@nabasolution/runtime 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/dist/src/app.d.ts +60 -0
- package/dist/src/app.d.ts.map +1 -0
- package/dist/src/app.js +649 -0
- package/dist/src/app.js.map +1 -0
- package/dist/src/audit.d.ts +42 -0
- package/dist/src/audit.d.ts.map +1 -0
- package/dist/src/audit.js +53 -0
- package/dist/src/audit.js.map +1 -0
- package/dist/src/auth-guard.d.ts +27 -0
- package/dist/src/auth-guard.d.ts.map +1 -0
- package/dist/src/auth-guard.js +29 -0
- package/dist/src/auth-guard.js.map +1 -0
- package/dist/src/index.d.ts +14 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +9 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/metrics.d.ts +26 -0
- package/dist/src/metrics.d.ts.map +1 -0
- package/dist/src/metrics.js +54 -0
- package/dist/src/metrics.js.map +1 -0
- package/dist/src/rate-limit.d.ts +40 -0
- package/dist/src/rate-limit.d.ts.map +1 -0
- package/dist/src/rate-limit.js +71 -0
- package/dist/src/rate-limit.js.map +1 -0
- package/dist/src/router.d.ts +21 -0
- package/dist/src/router.d.ts.map +1 -0
- package/dist/src/router.js +55 -0
- package/dist/src/router.js.map +1 -0
- package/dist/src/security.d.ts +35 -0
- package/dist/src/security.d.ts.map +1 -0
- package/dist/src/security.js +106 -0
- package/dist/src/security.js.map +1 -0
- package/dist/src/services.d.ts +10 -0
- package/dist/src/services.d.ts.map +1 -0
- package/dist/src/services.js +23 -0
- package/dist/src/services.js.map +1 -0
- package/dist/test/hardening.test.d.ts +2 -0
- package/dist/test/hardening.test.d.ts.map +1 -0
- package/dist/test/hardening.test.js +795 -0
- package/dist/test/hardening.test.js.map +1 -0
- package/dist/test/runtime.test.d.ts +2 -0
- package/dist/test/runtime.test.d.ts.map +1 -0
- package/dist/test/runtime.test.js +143 -0
- package/dist/test/runtime.test.js.map +1 -0
- package/package.json +47 -3
- package/README.md +0 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 NABA Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { Logger, NabaConfig, NabaModule, NabaRequest, ServiceRegistry } from "@nabasolution/core";
|
|
2
|
+
import type { AuditSink } from "./audit.js";
|
|
3
|
+
import type { RateLimiter } from "./rate-limit.js";
|
|
4
|
+
export interface CreateAppOptions {
|
|
5
|
+
config: NabaConfig;
|
|
6
|
+
modules: NabaModule[];
|
|
7
|
+
logger?: Logger;
|
|
8
|
+
/**
|
|
9
|
+
* Optional authorization hook, called before rate limiting and route
|
|
10
|
+
* dispatch for every non-public request. Throw `NabaError` (401/403) to
|
|
11
|
+
* reject. Not enabled by default; public storefront routes stay open.
|
|
12
|
+
*/
|
|
13
|
+
authorize?: (request: Request) => void | Record<string, unknown> | Promise<void | Record<string, unknown>>;
|
|
14
|
+
/**
|
|
15
|
+
* Optional shared rate limiter (e.g. Postgres-backed). Replaces the in-memory
|
|
16
|
+
* fixed-window limiter; `runtime.rateLimit` still supplies exemptions and
|
|
17
|
+
* proxy trust. Sync and async consume() implementations are supported.
|
|
18
|
+
*/
|
|
19
|
+
rateLimiter?: RateLimiter;
|
|
20
|
+
/**
|
|
21
|
+
* Optional audit destination (e.g. Postgres-backed). Replaces the file sink;
|
|
22
|
+
* `runtime.auditLog` is ignored when this is set. The runtime flushes and
|
|
23
|
+
* closes it on app close.
|
|
24
|
+
*/
|
|
25
|
+
auditSink?: AuditSink;
|
|
26
|
+
}
|
|
27
|
+
export interface NabaApp {
|
|
28
|
+
handle(request: Request): Promise<Response>;
|
|
29
|
+
listen(port?: number, host?: string): Promise<{
|
|
30
|
+
url: string;
|
|
31
|
+
close(): Promise<void>;
|
|
32
|
+
}>;
|
|
33
|
+
close(): Promise<void>;
|
|
34
|
+
readonly services: ServiceRegistry;
|
|
35
|
+
readonly routes: Array<{
|
|
36
|
+
method: string;
|
|
37
|
+
path: string;
|
|
38
|
+
}>;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Runtime-local extension of `NabaRequest`.
|
|
42
|
+
*
|
|
43
|
+
* Core declares `requestId`, `tenantId` and `clientKey` as optional; the runtime
|
|
44
|
+
* always populates them. Handlers can use the exported `routeContext(ctx)`
|
|
45
|
+
* helper (or cast) to get the narrowed, required fields. Existing handlers
|
|
46
|
+
* typed as `NabaRequest` keep compiling unchanged.
|
|
47
|
+
*/
|
|
48
|
+
export interface NabaRouteContext extends NabaRequest {
|
|
49
|
+
requestId: string;
|
|
50
|
+
clientKey: string;
|
|
51
|
+
tenantId: string;
|
|
52
|
+
}
|
|
53
|
+
/** Alias matching the v0.2 closure document's suggested name. */
|
|
54
|
+
export type RuntimeRequestContext = NabaRouteContext;
|
|
55
|
+
/** Re-type a handler's `NabaRequest` so runtime fields are required. */
|
|
56
|
+
export declare function routeContext(context: NabaRequest): NabaRouteContext;
|
|
57
|
+
export declare function json(data: unknown, init?: ResponseInit): Response;
|
|
58
|
+
export declare function problem(status: number, code: string, message: string, details?: unknown): Response;
|
|
59
|
+
export declare function createApp(options: CreateAppOptions): NabaApp;
|
|
60
|
+
//# sourceMappingURL=app.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../../src/app.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EACV,MAAM,EAEN,UAAU,EACV,UAAU,EACV,WAAW,EAEX,eAAe,EAChB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,KAAK,EAAc,SAAS,EAAE,MAAM,YAAY,CAAC;AAGxD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAYnD,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,UAAU,CAAC;IACnB,OAAO,EAAE,UAAU,EAAE,CAAC;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;;OAIG;IACH,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KACzB,IAAI,GACJ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACvB,OAAO,CAAC,IAAI,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IAC5C;;;;OAIG;IACH,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B;;;;OAIG;IACH,SAAS,CAAC,EAAE,SAAS,CAAC;CACvB;AAED,MAAM,WAAW,OAAO;IACtB,MAAM,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,C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