@ultrst-armada/kloks 2.0.0 → 2.0.2
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/package.json +1 -1
- package/packages/backend/dist/api/index.js +1 -1
- package/packages/backend/dist/api/middleware.test.d.ts +1 -0
- package/packages/backend/dist/{chunk-WC6EPW3A.js → chunk-POLVHTHJ.js} +16 -6
- package/packages/backend/dist/index.js +1 -1
- package/packages/backend/dist/node.js +1 -1
- package/packages/client/dist/auth.d.ts +20 -1
- package/packages/client/dist/auth.js +13 -3
- package/packages/client/dist/chunk-ATLIA7AJ.js +143 -0
- package/packages/client/dist/index.d.ts +1 -1
- package/packages/client/dist/index.js +13 -3
- package/packages/client/package.json +1 -1
- package/packages/functions/dist/async.d.ts +36 -0
- package/packages/functions/dist/base.d.ts +31 -1
- package/packages/functions/dist/cache.d.ts +27 -0
- package/packages/functions/dist/env-node.d.ts +8 -0
- package/packages/functions/dist/env.d.ts +19 -0
- package/packages/functions/dist/events.d.ts +32 -0
- package/packages/functions/dist/fileCache.d.ts +9 -0
- package/packages/functions/dist/fs-lock.d.ts +9 -0
- package/packages/functions/dist/fs.d.ts +35 -0
- package/packages/functions/dist/http.d.ts +36 -0
- package/packages/functions/dist/index.d.ts +14 -16
- package/packages/functions/dist/node.d.ts +7 -110
- package/packages/functions/dist/object.d.ts +32 -0
- package/packages/functions/dist/portable.d.ts +12 -206
- package/packages/functions/dist/shell.d.ts +37 -0
- package/packages/functions/dist/string.d.ts +14 -0
- package/packages/functions/dist/types.d.ts +31 -0
- package/packages/functions/package.json +1 -1
- package/packages/state-graph/dist/browser.js +16 -16
- package/packages/state-graph/dist/index.js +16 -16
- package/packages/client/dist/chunk-B4WOPCRZ.js +0 -26
- package/packages/functions/dist/base-DDYO-DzM.d.ts +0 -64
- package/packages/state-graph/dist/{chunk-UKTICGGV.js → chunk-YUJC367F.js} +3 -3
package/package.json
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -23,22 +23,32 @@ var BaseApiRoute = class extends SkipoBase {
|
|
|
23
23
|
// src/api/middleware.ts
|
|
24
24
|
function withAuth(verifyToken) {
|
|
25
25
|
return async (req) => {
|
|
26
|
-
const authHeader = req.headers.get("Authorization");
|
|
27
|
-
if (!authHeader
|
|
26
|
+
const authHeader = req.headers.get("authorization") ?? req.headers.get("Authorization");
|
|
27
|
+
if (!authHeader) {
|
|
28
28
|
return new Response(JSON.stringify({ error: "Unauthorized", status: 401 }), { status: 401 });
|
|
29
29
|
}
|
|
30
|
-
const
|
|
31
|
-
const
|
|
32
|
-
if (!
|
|
30
|
+
const trimmed = authHeader.trim();
|
|
31
|
+
const parts = trimmed.split(/\s+/);
|
|
32
|
+
if (parts.length !== 2 || parts[0].toLowerCase() !== "bearer" || !parts[1]) {
|
|
33
33
|
return new Response(JSON.stringify({ error: "Unauthorized", status: 401 }), { status: 401 });
|
|
34
34
|
}
|
|
35
|
-
|
|
35
|
+
const token = parts[1];
|
|
36
|
+
try {
|
|
37
|
+
const isValid = await verifyToken(token);
|
|
38
|
+
if (!isValid) {
|
|
39
|
+
return new Response(JSON.stringify({ error: "Unauthorized", status: 401 }), { status: 401 });
|
|
40
|
+
}
|
|
41
|
+
return null;
|
|
42
|
+
} catch {
|
|
43
|
+
return new Response(JSON.stringify({ error: "Service Unavailable", status: 503 }), { status: 503 });
|
|
44
|
+
}
|
|
36
45
|
};
|
|
37
46
|
}
|
|
38
47
|
function withCors(allowedOrigin = "*") {
|
|
39
48
|
return async (req) => {
|
|
40
49
|
if (req.method === "OPTIONS") {
|
|
41
50
|
return new Response(null, {
|
|
51
|
+
status: 204,
|
|
42
52
|
headers: {
|
|
43
53
|
"Access-Control-Allow-Origin": allowedOrigin,
|
|
44
54
|
"Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, OPTIONS",
|
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
import { DeploymentEnvironment } from '@dinilmusick/gutts/auth';
|
|
2
2
|
export { LuthAuthClient as CanonicalAuthClient, DEFAULT_LUTH_URL, DeploymentEnvironment, EmailSignInCredentials, EmailSignUpData, GoogleSignInOptions, LuthAuthClient, LuthAuthClientConfig, LuthAuthError, LuthAuthTokenStore, LuthSession, LuthSessionResult, LuthUser, RegisterApplicationResult, createLuthAuthClient as createCanonicalAuthClient, createLuthAuthClient, hydrateLuthTokenFromUrl, resolveClientEnvironment, resolveClientOrigin } from '@dinilmusick/gutts/auth';
|
|
3
3
|
|
|
4
|
+
interface LuthPrincipal {
|
|
5
|
+
id: string;
|
|
6
|
+
email: string;
|
|
7
|
+
name: string;
|
|
8
|
+
role: string;
|
|
9
|
+
}
|
|
10
|
+
declare const CANONICAL_PUBLIC_ROUTES: (string | RegExp)[];
|
|
11
|
+
declare function extractLuthToken(request: Request): string;
|
|
12
|
+
declare function isPublicRoute(pathname: string, extraPublicRoutes?: (string | RegExp)[]): boolean;
|
|
13
|
+
declare function verifyLuthRequest(request: Request, options?: {
|
|
14
|
+
luthUrl?: string;
|
|
15
|
+
extraPublicRoutes?: (string | RegExp)[];
|
|
16
|
+
}): Promise<LuthPrincipal | Response | null>;
|
|
17
|
+
|
|
4
18
|
interface LuthDeploymentRecord {
|
|
5
19
|
id: string;
|
|
6
20
|
url: string;
|
|
@@ -11,4 +25,9 @@ interface LuthDeploymentRecord {
|
|
|
11
25
|
priority?: number;
|
|
12
26
|
}
|
|
13
27
|
|
|
14
|
-
|
|
28
|
+
/** Creates an authenticated fetch function that automatically injects Luth bearer headers and credentials: 'include'. */
|
|
29
|
+
declare function createUniversalAuthFetch(authClient: {
|
|
30
|
+
getAuthHeaders: () => HeadersInit;
|
|
31
|
+
}): (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
|
|
32
|
+
|
|
33
|
+
export { CANONICAL_PUBLIC_ROUTES, type LuthDeploymentRecord, type LuthPrincipal, createUniversalAuthFetch, extractLuthToken, isPublicRoute, verifyLuthRequest };
|
|
@@ -1,22 +1,32 @@
|
|
|
1
1
|
import {
|
|
2
|
+
CANONICAL_PUBLIC_ROUTES,
|
|
2
3
|
DEFAULT_LUTH_URL,
|
|
3
4
|
LuthAuthClient,
|
|
4
5
|
LuthAuthClient2,
|
|
5
6
|
LuthAuthError,
|
|
6
7
|
createLuthAuthClient,
|
|
7
8
|
createLuthAuthClient2,
|
|
9
|
+
createUniversalAuthFetch,
|
|
10
|
+
extractLuthToken,
|
|
8
11
|
hydrateLuthTokenFromUrl,
|
|
12
|
+
isPublicRoute,
|
|
9
13
|
resolveClientEnvironment,
|
|
10
|
-
resolveClientOrigin
|
|
11
|
-
|
|
14
|
+
resolveClientOrigin,
|
|
15
|
+
verifyLuthRequest
|
|
16
|
+
} from "./chunk-ATLIA7AJ.js";
|
|
12
17
|
export {
|
|
18
|
+
CANONICAL_PUBLIC_ROUTES,
|
|
13
19
|
LuthAuthClient2 as CanonicalAuthClient,
|
|
14
20
|
DEFAULT_LUTH_URL,
|
|
15
21
|
LuthAuthClient,
|
|
16
22
|
LuthAuthError,
|
|
17
23
|
createLuthAuthClient2 as createCanonicalAuthClient,
|
|
18
24
|
createLuthAuthClient,
|
|
25
|
+
createUniversalAuthFetch,
|
|
26
|
+
extractLuthToken,
|
|
19
27
|
hydrateLuthTokenFromUrl,
|
|
28
|
+
isPublicRoute,
|
|
20
29
|
resolveClientEnvironment,
|
|
21
|
-
resolveClientOrigin
|
|
30
|
+
resolveClientOrigin,
|
|
31
|
+
verifyLuthRequest
|
|
22
32
|
};
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
// src/auth.ts
|
|
2
|
+
import {
|
|
3
|
+
LuthAuthClient,
|
|
4
|
+
createLuthAuthClient,
|
|
5
|
+
hydrateLuthTokenFromUrl,
|
|
6
|
+
resolveClientOrigin,
|
|
7
|
+
resolveClientEnvironment,
|
|
8
|
+
LuthAuthError,
|
|
9
|
+
DEFAULT_LUTH_URL as DEFAULT_LUTH_URL2
|
|
10
|
+
} from "@dinilmusick/gutts/auth";
|
|
11
|
+
import {
|
|
12
|
+
LuthAuthClient as LuthAuthClient2,
|
|
13
|
+
createLuthAuthClient as createLuthAuthClient2
|
|
14
|
+
} from "@dinilmusick/gutts/auth";
|
|
15
|
+
|
|
16
|
+
// src/UniversalLuthGuard.ts
|
|
17
|
+
import { DEFAULT_LUTH_URL } from "@dinilmusick/gutts/auth";
|
|
18
|
+
var CANONICAL_PUBLIC_ROUTES = [
|
|
19
|
+
"/health",
|
|
20
|
+
"/api/health",
|
|
21
|
+
"/api/status",
|
|
22
|
+
"/api/auth",
|
|
23
|
+
/^\/api(\/v1)?\/auth(\/.*)?$/,
|
|
24
|
+
/^\/api(\/v1)?\/database\/status$/,
|
|
25
|
+
/^\/api(\/v1)?\/guest(\/.*)?$/,
|
|
26
|
+
/^\/api(\/v1)?\/discovery(\/.*)?$/,
|
|
27
|
+
/^\/api(\/v1)?\/spec(\/.*)?$/
|
|
28
|
+
];
|
|
29
|
+
var SESSION_CACHE_TTL_MS = 6e4;
|
|
30
|
+
var sessionCache = /* @__PURE__ */ new Map();
|
|
31
|
+
function extractLuthToken(request) {
|
|
32
|
+
const authorization = request.headers.get("authorization") || "";
|
|
33
|
+
const bearer = /^Bearer\s+([^\s]+)$/i.exec(authorization.trim());
|
|
34
|
+
if (bearer) return bearer[1];
|
|
35
|
+
const apiKey = request.headers.get("x-api-key")?.trim();
|
|
36
|
+
if (apiKey) return apiKey;
|
|
37
|
+
const cookieHeader = request.headers.get("cookie") || "";
|
|
38
|
+
const cookies = cookieHeader.split(";").map((c) => c.trim());
|
|
39
|
+
for (const prefix of ["better-auth.session_token=", "__Secure-better-auth.session_token=", "luth_session="]) {
|
|
40
|
+
const found = cookies.find((c) => c.startsWith(prefix));
|
|
41
|
+
if (found) {
|
|
42
|
+
try {
|
|
43
|
+
return decodeURIComponent(found.slice(prefix.length));
|
|
44
|
+
} catch {
|
|
45
|
+
return "";
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return "";
|
|
50
|
+
}
|
|
51
|
+
function isPublicRoute(pathname, extraPublicRoutes) {
|
|
52
|
+
const routes = extraPublicRoutes ? [...CANONICAL_PUBLIC_ROUTES, ...extraPublicRoutes] : CANONICAL_PUBLIC_ROUTES;
|
|
53
|
+
return routes.some((route) => typeof route === "string" ? pathname === route : route.test(pathname));
|
|
54
|
+
}
|
|
55
|
+
async function verifyLuthRequest(request, options) {
|
|
56
|
+
const url = new URL(request.url);
|
|
57
|
+
if (request.method === "OPTIONS") return null;
|
|
58
|
+
if (isPublicRoute(url.pathname, options?.extraPublicRoutes)) return null;
|
|
59
|
+
const isMcp = url.pathname.includes("/mcp");
|
|
60
|
+
const token = extractLuthToken(request);
|
|
61
|
+
if (!token) {
|
|
62
|
+
const payload = isMcp ? { jsonrpc: "2.0", id: null, error: { code: -32001, message: "A verified Luth session is required." } } : { success: false, error: "A verified Luth session is required." };
|
|
63
|
+
return new Response(JSON.stringify(payload), { status: 401, headers: { "Content-Type": "application/json" } });
|
|
64
|
+
}
|
|
65
|
+
const now = Date.now();
|
|
66
|
+
const cached = sessionCache.get(token);
|
|
67
|
+
if (cached && cached.expiresAt > now) {
|
|
68
|
+
return cached.principal;
|
|
69
|
+
}
|
|
70
|
+
try {
|
|
71
|
+
const luthUrl = options?.luthUrl || DEFAULT_LUTH_URL;
|
|
72
|
+
const res = await fetch(`${luthUrl}/api/session`, {
|
|
73
|
+
headers: {
|
|
74
|
+
authorization: `Bearer ${token}`,
|
|
75
|
+
cookie: request.headers.get("cookie") || "",
|
|
76
|
+
origin: url.origin
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
if (!res.ok) {
|
|
80
|
+
const payload = isMcp ? { jsonrpc: "2.0", id: null, error: { code: -32001, message: "The Luth session is invalid or expired." } } : { success: false, error: "The Luth session is invalid or expired." };
|
|
81
|
+
return new Response(JSON.stringify(payload), { status: 401, headers: { "Content-Type": "application/json" } });
|
|
82
|
+
}
|
|
83
|
+
const data = await res.json();
|
|
84
|
+
const user = data?.user || (data?.authenticated ? data?.session?.user : null);
|
|
85
|
+
if (!user || !user.id) {
|
|
86
|
+
const payload = isMcp ? { jsonrpc: "2.0", id: null, error: { code: -32001, message: "The Luth session is invalid or expired." } } : { success: false, error: "The Luth session is invalid or expired." };
|
|
87
|
+
return new Response(JSON.stringify(payload), { status: 401, headers: { "Content-Type": "application/json" } });
|
|
88
|
+
}
|
|
89
|
+
const principal = {
|
|
90
|
+
id: String(user.id),
|
|
91
|
+
email: String(user.email || ""),
|
|
92
|
+
name: String(user.name || user.email?.split("@")[0] || ""),
|
|
93
|
+
role: String(user.role || "user")
|
|
94
|
+
};
|
|
95
|
+
sessionCache.set(token, { principal, expiresAt: now + SESSION_CACHE_TTL_MS });
|
|
96
|
+
return principal;
|
|
97
|
+
} catch {
|
|
98
|
+
const payload = isMcp ? { jsonrpc: "2.0", id: null, error: { code: -32603, message: "Canonical Luth authentication service unavailable." } } : { success: false, error: "Canonical Luth authentication service unavailable." };
|
|
99
|
+
return new Response(JSON.stringify(payload), { status: 503, headers: { "Content-Type": "application/json" } });
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// src/auth.ts
|
|
104
|
+
function createUniversalAuthFetch(authClient) {
|
|
105
|
+
return async function universalAuthFetch(input, init = {}) {
|
|
106
|
+
const headers = new Headers();
|
|
107
|
+
if (typeof input === "object" && input !== null && "headers" in input && input.headers) {
|
|
108
|
+
new Headers(input.headers).forEach((value, key) => {
|
|
109
|
+
headers.set(key, value);
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
if (init.headers) {
|
|
113
|
+
new Headers(init.headers).forEach((value, key) => {
|
|
114
|
+
headers.set(key, value);
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
new Headers(authClient.getAuthHeaders()).forEach((value, key) => {
|
|
118
|
+
if (!headers.has(key)) headers.set(key, value);
|
|
119
|
+
});
|
|
120
|
+
return fetch(input, {
|
|
121
|
+
...init,
|
|
122
|
+
headers,
|
|
123
|
+
credentials: init.credentials ?? "include"
|
|
124
|
+
});
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export {
|
|
129
|
+
CANONICAL_PUBLIC_ROUTES,
|
|
130
|
+
extractLuthToken,
|
|
131
|
+
isPublicRoute,
|
|
132
|
+
verifyLuthRequest,
|
|
133
|
+
createUniversalAuthFetch,
|
|
134
|
+
LuthAuthClient,
|
|
135
|
+
createLuthAuthClient,
|
|
136
|
+
hydrateLuthTokenFromUrl,
|
|
137
|
+
resolveClientOrigin,
|
|
138
|
+
resolveClientEnvironment,
|
|
139
|
+
LuthAuthError,
|
|
140
|
+
DEFAULT_LUTH_URL2 as DEFAULT_LUTH_URL,
|
|
141
|
+
LuthAuthClient2,
|
|
142
|
+
createLuthAuthClient2
|
|
143
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { LuthDeploymentRecord } from './auth.js';
|
|
1
|
+
export { CANONICAL_PUBLIC_ROUTES, LuthDeploymentRecord, LuthPrincipal, createUniversalAuthFetch, extractLuthToken, isPublicRoute, verifyLuthRequest } from './auth.js';
|
|
2
2
|
export { LuthAuthClient as CanonicalAuthClient, DEFAULT_LUTH_URL, DeploymentEnvironment, EmailSignInCredentials, EmailSignUpData, GoogleSignInOptions, LuthAuthClient, LuthAuthClientConfig, LuthAuthError, LuthAuthTokenStore, LuthSession, LuthSessionResult, LuthUser, RegisterApplicationResult, createLuthAuthClient as createCanonicalAuthClient, createLuthAuthClient, hydrateLuthTokenFromUrl, resolveClientEnvironment, resolveClientOrigin } from '@dinilmusick/gutts/auth';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
import {
|
|
2
|
+
CANONICAL_PUBLIC_ROUTES,
|
|
2
3
|
DEFAULT_LUTH_URL,
|
|
3
4
|
LuthAuthClient,
|
|
4
5
|
LuthAuthClient2,
|
|
5
6
|
LuthAuthError,
|
|
6
7
|
createLuthAuthClient,
|
|
7
8
|
createLuthAuthClient2,
|
|
9
|
+
createUniversalAuthFetch,
|
|
10
|
+
extractLuthToken,
|
|
8
11
|
hydrateLuthTokenFromUrl,
|
|
12
|
+
isPublicRoute,
|
|
9
13
|
resolveClientEnvironment,
|
|
10
|
-
resolveClientOrigin
|
|
11
|
-
|
|
14
|
+
resolveClientOrigin,
|
|
15
|
+
verifyLuthRequest
|
|
16
|
+
} from "./chunk-ATLIA7AJ.js";
|
|
12
17
|
|
|
13
18
|
// src/browserExecutionClient.ts
|
|
14
19
|
var BrowserExecutionClient = class {
|
|
@@ -184,6 +189,7 @@ var OPFSWorkspaceStorage = class {
|
|
|
184
189
|
};
|
|
185
190
|
export {
|
|
186
191
|
BrowserExecutionClient,
|
|
192
|
+
CANONICAL_PUBLIC_ROUTES,
|
|
187
193
|
LuthAuthClient2 as CanonicalAuthClient,
|
|
188
194
|
DEFAULT_LUTH_URL,
|
|
189
195
|
LuthAuthClient,
|
|
@@ -193,7 +199,11 @@ export {
|
|
|
193
199
|
createBrowserExecutionClient,
|
|
194
200
|
createLuthAuthClient2 as createCanonicalAuthClient,
|
|
195
201
|
createLuthAuthClient,
|
|
202
|
+
createUniversalAuthFetch,
|
|
203
|
+
extractLuthToken,
|
|
196
204
|
hydrateLuthTokenFromUrl,
|
|
205
|
+
isPublicRoute,
|
|
197
206
|
resolveClientEnvironment,
|
|
198
|
-
resolveClientOrigin
|
|
207
|
+
resolveClientOrigin,
|
|
208
|
+
verifyLuthRequest
|
|
199
209
|
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file async.ts
|
|
3
|
+
* @description sleep, withTimeout, retry, pLimit, debounce, throttle, once, and memoize primitives.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Classic sleep/delay.
|
|
7
|
+
*/
|
|
8
|
+
export declare function sleep(ms: number): Promise<void>;
|
|
9
|
+
/**
|
|
10
|
+
* Rejects if the task does not finish within ms.
|
|
11
|
+
*/
|
|
12
|
+
export declare function withTimeout<T>(promise: Promise<T>, ms: number, label?: string): Promise<T>;
|
|
13
|
+
/**
|
|
14
|
+
* Retries an async execution up to maxAttempts times.
|
|
15
|
+
*/
|
|
16
|
+
export declare function retry<T>(fn: () => Promise<T>, maxAttempts: number, delayMs?: number): Promise<T>;
|
|
17
|
+
/**
|
|
18
|
+
* Limits concurrent async task execution.
|
|
19
|
+
*/
|
|
20
|
+
export declare function pLimit<T>(tasks: (() => Promise<T>)[], concurrency: number): Promise<T[]>;
|
|
21
|
+
/**
|
|
22
|
+
* Debounces a function.
|
|
23
|
+
*/
|
|
24
|
+
export declare function debounce<T extends (...args: any[]) => any>(fn: T, ms: number): (...args: Parameters<T>) => void;
|
|
25
|
+
/**
|
|
26
|
+
* Throttles a function.
|
|
27
|
+
*/
|
|
28
|
+
export declare function throttle<T extends (...args: any[]) => any>(fn: T, ms: number): (...args: Parameters<T>) => void;
|
|
29
|
+
/**
|
|
30
|
+
* Wraps a function to run only once and cache its outcome.
|
|
31
|
+
*/
|
|
32
|
+
export declare function once<T extends (...args: any[]) => any>(fn: T): (...args: Parameters<T>) => ReturnType<T>;
|
|
33
|
+
/**
|
|
34
|
+
* Computational memoization cache helper.
|
|
35
|
+
*/
|
|
36
|
+
export declare function memoize<T extends (...args: any[]) => any>(fn: T, keyFn?: (...args: Parameters<T>) => string): (...args: Parameters<T>) => ReturnType<T>;
|
|
@@ -1 +1,31 @@
|
|
|
1
|
-
|
|
1
|
+
import type { Disposable, Logger, SkipoConfig } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* SkipoBase — Abstract foundation class for all Skipo components.
|
|
4
|
+
* Provides lifecycle management, logging, and unique identification.
|
|
5
|
+
* All @skipo/* classes should extend this.
|
|
6
|
+
*/
|
|
7
|
+
export declare abstract class SkipoBase implements Disposable {
|
|
8
|
+
/** Unique instance identifier */
|
|
9
|
+
readonly instanceId: string;
|
|
10
|
+
/** Human-readable component name */
|
|
11
|
+
readonly name: string;
|
|
12
|
+
/** Logger instance */
|
|
13
|
+
protected readonly logger: Logger;
|
|
14
|
+
/** Whether this component has been initialized */
|
|
15
|
+
protected initialized: boolean;
|
|
16
|
+
/** Whether this component has been disposed */
|
|
17
|
+
protected disposed: boolean;
|
|
18
|
+
constructor(config?: SkipoConfig);
|
|
19
|
+
/** Initialize the component. Call before use. */
|
|
20
|
+
initialize(): Promise<void>;
|
|
21
|
+
/** Override to add custom initialization logic */
|
|
22
|
+
protected onInitialize(): Promise<void>;
|
|
23
|
+
/** Dispose the component and release resources */
|
|
24
|
+
dispose(): Promise<void>;
|
|
25
|
+
/** Override to add custom cleanup logic */
|
|
26
|
+
protected onDispose(): Promise<void>;
|
|
27
|
+
/** Guard: throws if not initialized */
|
|
28
|
+
protected ensureInitialized(): void;
|
|
29
|
+
/** Guard: throws if already disposed */
|
|
30
|
+
protected ensureNotDisposed(): void;
|
|
31
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file cache.ts
|
|
3
|
+
* @description Portable LRU cache, TTL cache, and Stale-While-Revalidate utilities.
|
|
4
|
+
*/
|
|
5
|
+
export declare class LRUCache<K, V> {
|
|
6
|
+
private maxSize;
|
|
7
|
+
private cache;
|
|
8
|
+
constructor(maxSize: number);
|
|
9
|
+
get(key: K): V | undefined;
|
|
10
|
+
set(key: K, value: V): void;
|
|
11
|
+
delete(key: K): boolean;
|
|
12
|
+
clear(): void;
|
|
13
|
+
size(): number;
|
|
14
|
+
}
|
|
15
|
+
export declare class TTLCache<K, V> {
|
|
16
|
+
private ttlMs;
|
|
17
|
+
private cache;
|
|
18
|
+
constructor(ttlMs: number);
|
|
19
|
+
get(key: K): V | null;
|
|
20
|
+
set(key: K, value: V): void;
|
|
21
|
+
delete(key: K): boolean;
|
|
22
|
+
clear(): void;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Stale-While-Revalidate utility.
|
|
26
|
+
*/
|
|
27
|
+
export declare function swr<K, V>(cache: TTLCache<K, V>, key: K, fetchFn: () => Promise<V>): Promise<V>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file env.ts
|
|
3
|
+
* @description Runtime-neutral environment value parsing and validation.
|
|
4
|
+
*/
|
|
5
|
+
import type { ZodTypeAny } from 'zod';
|
|
6
|
+
export type EnvironmentValues = Record<string, string | undefined>;
|
|
7
|
+
/**
|
|
8
|
+
* Reads an environment value with type coercion and defaults.
|
|
9
|
+
* Worker and browser callers should pass their environment bindings explicitly.
|
|
10
|
+
*/
|
|
11
|
+
export declare function getEnv<T>(key: string, defaultValue?: T, env?: EnvironmentValues): T;
|
|
12
|
+
/** Asserts an environment value is set and returns its string value. */
|
|
13
|
+
export declare function requireEnv(key: string, env?: EnvironmentValues): string;
|
|
14
|
+
/** Validates an environment object using a Zod schema. */
|
|
15
|
+
export declare function validateEnvSchema<T extends ZodTypeAny>(zodSchema: T, env?: EnvironmentValues): T['_output'];
|
|
16
|
+
/** Checks if a connection string is a placeholder or template value. */
|
|
17
|
+
export declare function isPlaceholderConnection(url?: string): boolean;
|
|
18
|
+
/** Sanitizes a database URL, returning undefined if it is empty or a placeholder. */
|
|
19
|
+
export declare function sanitizeDatabaseUrl(url?: string): string | undefined;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file events.ts
|
|
3
|
+
* @description Skipo Universal Real-Time Event Bus. Facilitates real-time event broadcasting and streaming.
|
|
4
|
+
*/
|
|
5
|
+
export interface RealtimeWorkspaceEvent {
|
|
6
|
+
id: string;
|
|
7
|
+
timestamp: number;
|
|
8
|
+
userId?: string;
|
|
9
|
+
workspaceId?: string;
|
|
10
|
+
source: 'api' | 'ui';
|
|
11
|
+
method?: string;
|
|
12
|
+
endpoint?: string;
|
|
13
|
+
action: 'DOCUMENT_CREATED' | 'DOCUMENT_UPDATED' | 'DOCUMENT_DELETED' | 'CATEGORY_CREATED' | 'CATEGORY_UPDATED' | 'CATEGORY_DELETED' | 'GRAPH_UPDATED' | 'BIOME_CHANGED' | 'WORKSPACE_UPDATED' | 'WORKSPACE_SWITCHED' | 'GENERIC_ACTION' | string;
|
|
14
|
+
details?: string;
|
|
15
|
+
payload?: any;
|
|
16
|
+
}
|
|
17
|
+
export type EventListener = (event: RealtimeWorkspaceEvent) => void;
|
|
18
|
+
/**
|
|
19
|
+
* Publish a new event to all active real-time subscribers and store in buffer.
|
|
20
|
+
*/
|
|
21
|
+
export declare function publishRealtimeEvent(eventInput: Omit<RealtimeWorkspaceEvent, 'id' | 'timestamp'> & {
|
|
22
|
+
id?: string;
|
|
23
|
+
timestamp?: number;
|
|
24
|
+
}): RealtimeWorkspaceEvent;
|
|
25
|
+
/**
|
|
26
|
+
* Subscribe to real-time events. Returns an unsubscribe function.
|
|
27
|
+
*/
|
|
28
|
+
export declare function subscribeRealtimeEvents(listener: EventListener): () => void;
|
|
29
|
+
/**
|
|
30
|
+
* Retrieve recent events since a specified timestamp, optionally filtered by workspaceId or userId.
|
|
31
|
+
*/
|
|
32
|
+
export declare function getRecentEvents(sinceTimestamp?: number, workspaceId?: string, userId?: string): RealtimeWorkspaceEvent[];
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file fs.ts
|
|
3
|
+
* @description Robust cross-platform filesystem abstraction layer.
|
|
4
|
+
*/
|
|
5
|
+
import fs from "fs";
|
|
6
|
+
export declare function readFile(filePath: string, encoding?: BufferEncoding): Promise<string>;
|
|
7
|
+
export declare function writeFile(filePath: string, content: string | Buffer): Promise<void>;
|
|
8
|
+
/**
|
|
9
|
+
* Atomic file writing via temp files.
|
|
10
|
+
*/
|
|
11
|
+
export declare function writeFileAtomic(filePath: string, content: string | Buffer): Promise<void>;
|
|
12
|
+
export declare function appendFile(filePath: string, content: string | Buffer): Promise<void>;
|
|
13
|
+
export declare function deleteFile(filePath: string): Promise<void>;
|
|
14
|
+
export declare function fileExists(filePath: string): Promise<boolean>;
|
|
15
|
+
export declare function getFileStat(filePath: string): Promise<{
|
|
16
|
+
size: number;
|
|
17
|
+
createdAt: Date;
|
|
18
|
+
modifiedAt: Date;
|
|
19
|
+
isDir: boolean;
|
|
20
|
+
}>;
|
|
21
|
+
export declare function readJSON<T>(filePath: string): Promise<T | null>;
|
|
22
|
+
export declare function writeJSON(filePath: string, data: unknown, indent?: number): Promise<void>;
|
|
23
|
+
export declare function updateJSON<T>(filePath: string, patch: Partial<T>): Promise<T>;
|
|
24
|
+
export declare function ensureDir(dirPath: string): Promise<void>;
|
|
25
|
+
export declare function deleteDir(dirPath: string, recursive?: boolean): Promise<void>;
|
|
26
|
+
export declare function listDir(dirPath: string): Promise<string[]>;
|
|
27
|
+
export declare function walkDir(dirPath: string, filter?: (file: string) => boolean): AsyncIterable<string>;
|
|
28
|
+
export declare function dirExists(dirPath: string): Promise<boolean>;
|
|
29
|
+
export declare function copyDir(src: string, dest: string): Promise<void>;
|
|
30
|
+
export declare function firstExisting(candidates: string[]): Promise<string | null>;
|
|
31
|
+
export declare function watchFile(filePath: string, handler: (event: string) => void, debounceMs?: number): fs.FSWatcher;
|
|
32
|
+
export declare function watchDir(dirPath: string, handler: (event: string, filename: string | null) => void, debounceMs?: number): fs.FSWatcher;
|
|
33
|
+
export declare function createTempFile(prefix?: string): string;
|
|
34
|
+
export declare function createTempDir(prefix?: string): string;
|
|
35
|
+
export declare function withTempDir<T>(fn: (tempDir: string) => Promise<T>, prefix?: string): Promise<T>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file http.ts
|
|
3
|
+
* @description Safe, type-safe HTTP client wrapper.
|
|
4
|
+
*/
|
|
5
|
+
export interface SkipoHTTPOptions extends RequestInit {
|
|
6
|
+
timeout?: number;
|
|
7
|
+
retries?: number;
|
|
8
|
+
}
|
|
9
|
+
export interface SkipoHTTPResult<T> {
|
|
10
|
+
status: "success" | "error";
|
|
11
|
+
data?: T;
|
|
12
|
+
message?: string;
|
|
13
|
+
code?: number;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Helper to perform fetch with timeout and retries.
|
|
17
|
+
*/
|
|
18
|
+
export declare function requestRaw(url: string, opts?: SkipoHTTPOptions): Promise<Response>;
|
|
19
|
+
export declare function request<T>(url: string, opts?: SkipoHTTPOptions): Promise<SkipoHTTPResult<T>>;
|
|
20
|
+
export declare function get<T>(url: string, opts?: SkipoHTTPOptions): Promise<SkipoHTTPResult<T>>;
|
|
21
|
+
export declare function post<T>(url: string, body: any, opts?: SkipoHTTPOptions): Promise<SkipoHTTPResult<T>>;
|
|
22
|
+
export declare function put<T>(url: string, body: any, opts?: SkipoHTTPOptions): Promise<SkipoHTTPResult<T>>;
|
|
23
|
+
export declare function del<T>(url: string, opts?: SkipoHTTPOptions): Promise<SkipoHTTPResult<T>>;
|
|
24
|
+
/**
|
|
25
|
+
* Creates a client instance.
|
|
26
|
+
*/
|
|
27
|
+
export declare function createClient(baseUrl: string, defaultHeaders?: Record<string, string>): {
|
|
28
|
+
get: <T>(path: string, opts?: SkipoHTTPOptions) => Promise<SkipoHTTPResult<T>>;
|
|
29
|
+
post: <T>(path: string, body: any, opts?: SkipoHTTPOptions) => Promise<SkipoHTTPResult<T>>;
|
|
30
|
+
put: <T>(path: string, body: any, opts?: SkipoHTTPOptions) => Promise<SkipoHTTPResult<T>>;
|
|
31
|
+
del: <T>(path: string, opts?: SkipoHTTPOptions) => Promise<SkipoHTTPResult<T>>;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Streaming SSE / Chunk response.
|
|
35
|
+
*/
|
|
36
|
+
export declare function streamResponse(url: string, opts?: SkipoHTTPOptions): AsyncIterable<string>;
|
|
@@ -1,32 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import '
|
|
6
|
-
|
|
7
|
-
declare const FunctionsServiceDefinition: ServiceDefinition;
|
|
8
|
-
declare const FunctionsServiceFacade: {
|
|
1
|
+
/**
|
|
2
|
+
* @file index.ts
|
|
3
|
+
* @description KrnlTS FunctionsServiceFacade plus the portable function library.
|
|
4
|
+
*/
|
|
5
|
+
import { type ServiceDefinition } from '@ultrst-armada/krnl';
|
|
6
|
+
export * from './portable.js';
|
|
7
|
+
export declare const FunctionsServiceDefinition: ServiceDefinition;
|
|
8
|
+
export declare const FunctionsServiceFacade: {
|
|
9
9
|
id: string;
|
|
10
10
|
name: string;
|
|
11
11
|
version: string;
|
|
12
12
|
runtime: "server";
|
|
13
13
|
deployment: "local";
|
|
14
14
|
definition: ServiceDefinition<Record<string, unknown>, Record<string, unknown>>;
|
|
15
|
-
readonly telemetry:
|
|
16
|
-
createInstance: () =>
|
|
15
|
+
readonly telemetry: import("@ultrst-armada/krnl").TelemetryController;
|
|
16
|
+
createInstance: () => import("@ultrst-armada/krnl").ServiceInstance<Record<string, unknown>, Record<string, unknown>>;
|
|
17
17
|
execute: <TIn = unknown, TOut = unknown>(op: string, input?: TIn) => Promise<TOut>;
|
|
18
18
|
};
|
|
19
|
-
declare const krnlFunctionsServiceDefinition: ServiceDefinition<Record<string, unknown>, Record<string, unknown>>;
|
|
20
|
-
declare const krnlFunctionsServiceFacade: {
|
|
19
|
+
export declare const krnlFunctionsServiceDefinition: ServiceDefinition<Record<string, unknown>, Record<string, unknown>>;
|
|
20
|
+
export declare const krnlFunctionsServiceFacade: {
|
|
21
21
|
id: string;
|
|
22
22
|
name: string;
|
|
23
23
|
version: string;
|
|
24
24
|
runtime: "server";
|
|
25
25
|
deployment: "local";
|
|
26
26
|
definition: ServiceDefinition<Record<string, unknown>, Record<string, unknown>>;
|
|
27
|
-
readonly telemetry:
|
|
28
|
-
createInstance: () =>
|
|
27
|
+
readonly telemetry: import("@ultrst-armada/krnl").TelemetryController;
|
|
28
|
+
createInstance: () => import("@ultrst-armada/krnl").ServiceInstance<Record<string, unknown>, Record<string, unknown>>;
|
|
29
29
|
execute: <TIn = unknown, TOut = unknown>(op: string, input?: TIn) => Promise<TOut>;
|
|
30
30
|
};
|
|
31
|
-
|
|
32
|
-
export { FunctionsServiceDefinition, FunctionsServiceFacade, krnlFunctionsServiceDefinition, krnlFunctionsServiceFacade };
|