@kedem/okdb 2.3.5 → 2.5.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/CHANGELOG.md +427 -0
- package/algorithm-worker-thread.js +1 -1
- package/bin/okdb.js +1 -1
- package/docs/auth-and-sync.md +30 -5
- package/docs/auth-permissions.md +19 -6
- package/docs/change-log.md +79 -59
- package/docs/data-model.md +20 -18
- package/docs/deployment.md +25 -0
- package/docs/diagnostics.md +59 -17
- package/docs/embeddings.md +57 -6
- package/docs/fts.md +50 -5
- package/docs/functions.md +21 -8
- package/docs/http-api.md +139 -98
- package/docs/http-cluster.md +30 -8
- package/docs/indexes.md +5 -4
- package/docs/licensing.md +6 -1
- package/docs/logging.md +18 -0
- package/docs/migration.md +153 -2
- package/docs/pipelines.md +6 -1
- package/docs/plugins.md +12 -18
- package/docs/process-registry.md +50 -39
- package/docs/processors.md +40 -22
- package/docs/querying.md +50 -36
- package/docs/queue.md +110 -14
- package/docs/subscriptions.md +37 -24
- package/docs/sync.md +96 -37
- package/docs/time-machine.md +23 -17
- package/docs/transactions.md +11 -19
- package/docs/ttl.md +118 -67
- package/docs/upgrade-2.0.md +2 -2
- package/docs/views.md +75 -52
- package/okdb-functions-sandbox-worker.js +1 -1
- package/okdb-http-worker-child.js +1 -1
- package/okdb-views-bootstrap-worker.js +1 -1
- package/okdb.js +1 -1
- package/package.json +1 -1
- package/public/sections/db/parts/type-viewer.ok.js +1 -1
- package/public/sections/embeddings/parts/engines-overview.ok.js +1 -1
- package/public/sections/queue/parts/queue-jobs.ok.js +1 -1
- package/public/sections/system/modals/data-ops-modal.ok.js +1 -1
- package/types/environment.d.ts +320 -52
- package/types/features/admin.d.ts +8 -2
- package/types/features/api.d.ts +10 -16
- package/types/features/auth.d.ts +135 -16
- package/types/features/embeddings.d.ts +639 -31
- package/types/features/engines.d.ts +368 -14
- package/types/features/files.d.ts +0 -3
- package/types/features/fts.d.ts +98 -26
- package/types/features/functions.d.ts +175 -15
- package/types/features/mcp.d.ts +23 -10
- package/types/features/pipelines.d.ts +268 -9
- package/types/features/queue.d.ts +230 -34
- package/types/features/sync.d.ts +177 -14
- package/types/features/time-machine.d.ts +117 -16
- package/types/features/views.d.ts +230 -39
- package/types/index.d.ts +357 -254
- package/types/okdb.d.ts +397 -0
- package/types/options.d.ts +309 -48
- package/public/test-cron-input.html +0 -60
- package/public/test-json-input.html +0 -280
package/types/features/auth.d.ts
CHANGED
|
@@ -1,31 +1,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A stored API token: a record of the `~tokens` type in the `~system` env (key = token id).
|
|
3
|
+
* Tokens are created/listed/revoked via `okdb token create`, the admin UI, or
|
|
4
|
+
* `POST|GET|DELETE /api/auth/tokens` — there is no JS method for it on `db.auth`.
|
|
5
|
+
* The raw bearer value is only returned once, at creation; only its SHA-256 is stored.
|
|
6
|
+
*/
|
|
1
7
|
export interface OKDBToken {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
8
|
+
/** SHA-256 hex of the raw bearer value. */
|
|
9
|
+
tokenHash: string;
|
|
10
|
+
/** Optional login username (case-insensitive). */
|
|
11
|
+
name: string | null;
|
|
12
|
+
/** scrypt `saltHex:hashHex`, present when the token has a login password. */
|
|
13
|
+
passwordHash: string | null;
|
|
14
|
+
label: string | null;
|
|
15
|
+
/** Base permissions, `"<namespace>:<operation>"` (`"*"` = everything). */
|
|
16
|
+
permissions: string[];
|
|
17
|
+
/** Per-env additive permissions: `{ [envName]: ["<ns>:<op>", ...] }`. */
|
|
18
|
+
grants: Record<string, string[]>;
|
|
5
19
|
createdAt: number;
|
|
20
|
+
lastUsedAt: number | null;
|
|
6
21
|
expiresAt: number | null;
|
|
7
|
-
[key: string]: unknown;
|
|
8
22
|
}
|
|
9
23
|
|
|
24
|
+
export interface OKDBAuthUser {
|
|
25
|
+
id: string | null;
|
|
26
|
+
username: string | null;
|
|
27
|
+
/** For token-backed identities these are the token's permissions. */
|
|
28
|
+
roles: string[];
|
|
29
|
+
isAuthenticated: boolean;
|
|
30
|
+
isSystem: boolean;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Result of `authenticateRequest()`; also found on HTTP handlers as `context.auth`. */
|
|
10
34
|
export interface OKDBAuthContext {
|
|
11
|
-
|
|
12
|
-
|
|
35
|
+
type: 'system' | 'token' | 'user' | 'anonymous' | 'bootstrap-blocked';
|
|
36
|
+
isAuthenticated: boolean;
|
|
37
|
+
isSystem: boolean;
|
|
38
|
+
user: OKDBAuthUser | null;
|
|
39
|
+
id?: string | null;
|
|
40
|
+
username?: string | null;
|
|
13
41
|
roles?: string[];
|
|
14
|
-
|
|
42
|
+
subject?: string | null;
|
|
43
|
+
/** On `system` identities: true when granted by open mode. */
|
|
44
|
+
open?: boolean;
|
|
45
|
+
/** Set on `bootstrap-blocked` (secure mode, no tokens yet, non-loopback client). */
|
|
46
|
+
bootstrapBlocked?: boolean;
|
|
47
|
+
/** Verified claims for HMAC session tokens and OIDC access tokens. */
|
|
48
|
+
claims?: Record<string, unknown>;
|
|
49
|
+
/** Effective permission set used by the permission checks. */
|
|
50
|
+
token?: { permissions: string[]; grants: Record<string, string[]> };
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Result of `login()` / `loginSelect()`. Invalid credentials resolve (never reject) with `ok: false`. */
|
|
54
|
+
export type OKDBLoginResult =
|
|
55
|
+
| { ok: false; code?: 'INVALID_CREDENTIALS'; error: string }
|
|
56
|
+
| {
|
|
57
|
+
ok: true;
|
|
58
|
+
/** Several tokens share this name + password: finish with `loginSelect(..., tokenId)`. */
|
|
59
|
+
ambiguous: true;
|
|
60
|
+
candidates: Array<{ tokenId: string; label: string | null; permissions: string[]; createdAt: number }>;
|
|
61
|
+
}
|
|
62
|
+
| {
|
|
63
|
+
ok: true;
|
|
64
|
+
ambiguous?: undefined;
|
|
65
|
+
user: { name: string; permissions: string[] };
|
|
66
|
+
/** Sealed session value; usable as the session cookie or as a Bearer token. */
|
|
67
|
+
cookie: string;
|
|
68
|
+
cookieName: string;
|
|
69
|
+
/** Seconds (from `auth.token.ttl`). */
|
|
70
|
+
expiresIn: number;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
/** Claims carried by an HMAC session token (`issueToken()` / `authenticateToken()`). */
|
|
74
|
+
export interface OKDBSessionClaims {
|
|
75
|
+
iat: number;
|
|
76
|
+
exp: number;
|
|
77
|
+
sub: string | null;
|
|
78
|
+
username: string | null;
|
|
79
|
+
roles: string[];
|
|
15
80
|
[key: string]: unknown;
|
|
16
81
|
}
|
|
17
82
|
|
|
18
|
-
export interface
|
|
19
|
-
|
|
20
|
-
|
|
83
|
+
export interface OKDBSecurityNotice {
|
|
84
|
+
level: 'warn' | 'error';
|
|
85
|
+
code: string;
|
|
86
|
+
title: string;
|
|
87
|
+
message: string;
|
|
88
|
+
hint?: string;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export interface OKDBLoginConfig {
|
|
92
|
+
mode: 'open' | 'secure';
|
|
93
|
+
openAccess: boolean;
|
|
94
|
+
bootstrap: boolean;
|
|
95
|
+
setupRequired: false;
|
|
96
|
+
login: { enabled: boolean };
|
|
97
|
+
oauth: { enabled: boolean; providers: string[] };
|
|
21
98
|
}
|
|
22
99
|
|
|
100
|
+
/**
|
|
101
|
+
* Request authentication for the HTTP layer, attached as `db.auth`. Configured by the `auth`
|
|
102
|
+
* constructor option; ready after `open()`. Token management is HTTP/CLI-only (see `OKDBToken`).
|
|
103
|
+
*
|
|
104
|
+
* Removed: `createToken`, `revokeToken`, `listTokens`, `getToken` (never on `db.auth` in 2.x; use
|
|
105
|
+
* `/api/auth/tokens` or `okdb token ...`).
|
|
106
|
+
*/
|
|
23
107
|
export declare class OKDBAuth {
|
|
24
|
-
|
|
25
|
-
|
|
108
|
+
/** `'open'` when `auth.open` trusts some client IPs, otherwise `'secure'`. */
|
|
109
|
+
readonly mode: 'open' | 'secure';
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Resolve the identity of an HTTP request: bootstrap window → open-mode IP → Bearer token
|
|
113
|
+
* (stored token, HMAC session token, sealed login session, OIDC access token) → session cookie
|
|
114
|
+
* → anonymous. Reads `req.socket.remoteAddress`, `req.headers.authorization`, `req.cookies`,
|
|
115
|
+
* `req.context.internal`.
|
|
116
|
+
*/
|
|
117
|
+
authenticateRequest(req: {
|
|
118
|
+
socket?: { remoteAddress?: string | null };
|
|
119
|
+
remoteAddress?: string | null;
|
|
120
|
+
headers?: Record<string, string | string[] | undefined>;
|
|
121
|
+
cookies?: Record<string, string>;
|
|
122
|
+
context?: Record<string, unknown>;
|
|
123
|
+
}): Promise<OKDBAuthContext>;
|
|
124
|
+
|
|
125
|
+
/** Password login against `~tokens` records by `name`. */
|
|
26
126
|
login(username: string, password: string): Promise<OKDBLoginResult>;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
127
|
+
/** Completes an ambiguous `login()` by choosing one candidate token. */
|
|
128
|
+
loginSelect(username: string, password: string, tokenId: string): Promise<OKDBLoginResult>;
|
|
129
|
+
|
|
130
|
+
/** Sign an HMAC session token (`base64url(payload).sig`) with the store's token secret. */
|
|
131
|
+
issueToken(user: {
|
|
132
|
+
id?: string | null;
|
|
133
|
+
sub?: string | null;
|
|
134
|
+
username?: string | null;
|
|
135
|
+
name?: string | null;
|
|
136
|
+
roles?: string[];
|
|
137
|
+
}): string;
|
|
138
|
+
/** Verify an HMAC session token; null if invalid or expired (30 s skew). */
|
|
139
|
+
authenticateToken(tokenString: string): OKDBSessionClaims | null;
|
|
140
|
+
/** Extract the value of an `Authorization: Bearer <token>` header, or null. */
|
|
141
|
+
parseBearer(header: string | null | undefined): string | null;
|
|
142
|
+
|
|
143
|
+
/** OAuth allowlist check (`auth.oauth.allowedEmails` / `allowedDomains`); false when neither is set. */
|
|
144
|
+
isOAuthEmailAllowed(email: string | null | undefined): boolean;
|
|
145
|
+
/** Open-mode warning text, or null in secure mode. */
|
|
146
|
+
getOpenWarning(): string | null;
|
|
147
|
+
getSecurityNotices(): OKDBSecurityNotice[];
|
|
148
|
+
/** Login-page configuration as served to the admin UI. */
|
|
149
|
+
getLoginConfig(): OKDBLoginConfig;
|
|
31
150
|
}
|