@owlmeans/server-api 0.1.18-rc.49 → 0.1.18-rc.50
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/README.md +2 -2
- package/agent-meta/manifest.json +2 -2
- package/agent-meta/skills/server-api/SKILL.md +1 -1
- package/build/consts.local.d.ts +2 -0
- package/build/consts.local.d.ts.map +1 -0
- package/build/consts.local.js +2 -0
- package/build/consts.local.js.map +1 -0
- package/build/helper.d.ts +3 -6
- package/build/helper.d.ts.map +1 -1
- package/build/helper.js.map +1 -1
- package/build/hold.d.ts +1 -18
- package/build/hold.d.ts.map +1 -1
- package/build/hold.js.map +1 -1
- package/build/protocol.d.ts +3 -30
- package/build/protocol.d.ts.map +1 -1
- package/build/protocol.js.map +1 -1
- package/build/server.d.ts +2 -3
- package/build/server.d.ts.map +1 -1
- package/build/server.js +3 -4
- package/build/server.js.map +1 -1
- package/build/types.d.ts +21 -0
- package/build/types.d.ts.map +1 -1
- package/build/types.local.d.ts +38 -0
- package/build/types.local.d.ts.map +1 -0
- package/build/types.local.js +2 -0
- package/build/types.local.js.map +1 -0
- package/build/utils/consts.d.ts +2 -0
- package/build/utils/consts.d.ts.map +1 -0
- package/build/utils/consts.js +2 -0
- package/build/utils/consts.js.map +1 -0
- package/build/utils/consts.local.d.ts +5 -0
- package/build/utils/consts.local.d.ts.map +1 -0
- package/build/utils/consts.local.js +5 -0
- package/build/utils/consts.local.js.map +1 -0
- package/build/utils/error.d.ts +1 -18
- package/build/utils/error.d.ts.map +1 -1
- package/build/utils/error.js +2 -5
- package/build/utils/error.js.map +1 -1
- package/build/utils/guards.d.ts +1 -5
- package/build/utils/guards.d.ts.map +1 -1
- package/build/utils/guards.js.map +1 -1
- package/build/utils/index.d.ts +2 -0
- package/build/utils/index.d.ts.map +1 -1
- package/build/utils/index.js +1 -0
- package/build/utils/index.js.map +1 -1
- package/build/utils/log.d.ts +1 -1
- package/build/utils/log.d.ts.map +1 -1
- package/build/utils/log.js.map +1 -1
- package/build/utils/server.d.ts +3 -7
- package/build/utils/server.d.ts.map +1 -1
- package/build/utils/server.js +1 -2
- package/build/utils/server.js.map +1 -1
- package/build/utils/types.d.ts +18 -0
- package/build/utils/types.d.ts.map +1 -0
- package/build/utils/types.js +2 -0
- package/build/utils/types.js.map +1 -0
- package/build/utils/types.local.d.ts +9 -0
- package/build/utils/types.local.d.ts.map +1 -0
- package/build/utils/types.local.js +2 -0
- package/build/utils/types.local.js.map +1 -0
- package/package.json +20 -20
- package/src/consts.local.ts +1 -0
- package/src/helper.ts +3 -7
- package/src/hold.ts +1 -20
- package/src/protocol.ts +3 -40
- package/src/server.ts +5 -8
- package/src/types.local.ts +44 -0
- package/src/types.ts +23 -0
- package/src/utils/consts.local.ts +7 -0
- package/src/utils/consts.ts +1 -0
- package/src/utils/error.ts +3 -25
- package/src/utils/guards.ts +2 -5
- package/src/utils/index.ts +2 -0
- package/src/utils/log.ts +2 -4
- package/src/utils/server.ts +5 -11
- package/src/utils/types.local.ts +12 -0
- package/src/utils/types.ts +18 -0
- package/tests/error-status.spec.ts +2 -1
package/build/utils/log.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"log.js","sourceRoot":"","sources":["../../src/utils/log.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"log.js","sourceRoot":"","sources":["../../src/utils/log.ts"],"names":[],"mappings":"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"}
|
package/build/utils/server.d.ts
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
import type { FastifyReply, FastifyRequest } from 'fastify';
|
|
2
2
|
import type { ServerEntrypoint } from '@owlmeans/server-entrypoint';
|
|
3
|
-
import type
|
|
4
|
-
import type {
|
|
5
|
-
|
|
6
|
-
type Config = ApiConfig;
|
|
7
|
-
type Context = ServerContext<Config>;
|
|
8
|
-
export declare const canServeModule: (context: Context, module: CommonEntrypoint) => module is ServerEntrypoint<unknown>;
|
|
3
|
+
import { type CommonEntrypoint } from '@owlmeans/entrypoint';
|
|
4
|
+
import type { ServerContext2 } from './types.local.js';
|
|
5
|
+
export declare const canServeModule: (context: ServerContext2, module: CommonEntrypoint) => module is ServerEntrypoint<unknown>;
|
|
9
6
|
export declare const createServerHandler: (module: ServerEntrypoint<FastifyRequest>, location: string) => (req: FastifyRequest, reply: FastifyReply) => Promise<void>;
|
|
10
|
-
export {};
|
|
11
7
|
//# sourceMappingURL=server.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/utils/server.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/utils/server.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAC3D,OAAO,KAAK,EAAgB,gBAAgB,EAAE,MAAM,6BAA6B,CAAA;AACjF,OAAO,EAAE,KAAK,gBAAgB,EAAqC,MAAM,sBAAsB,CAAA;AAQ/F,OAAO,KAAK,EAAiB,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAGrE,eAAO,MAAM,cAAc,YAAa,cAAc,UAAU,gBAAgB,KAAG,MAAM,IAAI,gBAAgB,CAAC,OAAO,CAcpH,CAAA;AAED,eAAO,MAAM,mBAAmB,WAAY,gBAAgB,CAAC,cAAc,CAAC,YAAY,MAAM,WAChF,cAAc,SAAS,YAAY,kBAuC9C,CAAA"}
|
package/build/utils/server.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { AppType } from '@owlmeans/context';
|
|
2
|
-
import { assertContext } from '@owlmeans/context';
|
|
1
|
+
import { AppType, assertContext } from '@owlmeans/context';
|
|
3
2
|
import { provideResponse } from '@owlmeans/entrypoint';
|
|
4
3
|
import { ResilientError } from '@owlmeans/error';
|
|
5
4
|
import { OK } from '@owlmeans/api';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/utils/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/utils/server.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What an error class may declare about the HTTP status it is answered with.
|
|
3
|
+
*
|
|
4
|
+
* Structural on purpose: the classes that declare it live in packages that must not depend on an
|
|
5
|
+
* HTTP server (`@owlmeans/payment`, a product's contract package), so they write a plain
|
|
6
|
+
* `public static httpStatus = 409` and nothing imports this type.
|
|
7
|
+
*/
|
|
8
|
+
export interface HttpStatusDeclaration {
|
|
9
|
+
httpStatus?: unknown;
|
|
10
|
+
/** Explicit opt-in for a declared 5xx response. Client-error declarations need no opt-in. */
|
|
11
|
+
allowServerErrorStatus?: unknown;
|
|
12
|
+
}
|
|
13
|
+
export interface SerializedHttpError {
|
|
14
|
+
status: number;
|
|
15
|
+
body: string;
|
|
16
|
+
incidentId: string;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/utils/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,WAAW,qBAAqB;IACpC,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,6FAA6F;IAC7F,sBAAsB,CAAC,EAAE,OAAO,CAAA;CACjC;AAED,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,MAAM,CAAA;IACZ,UAAU,EAAE,MAAM,CAAA;CACnB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/utils/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ServerConfig, ServerContext } from '@owlmeans/server-context';
|
|
2
|
+
import type { Config as ApiConfig } from '../types.js';
|
|
3
|
+
export type Config = ServerConfig;
|
|
4
|
+
export interface Context<C extends Config = Config> extends ServerContext<C> {
|
|
5
|
+
}
|
|
6
|
+
export type Severity = 'debug' | 'info' | 'warn' | 'error';
|
|
7
|
+
export type ServerConfig2 = ApiConfig;
|
|
8
|
+
export type ServerContext2 = ServerContext<ServerConfig2>;
|
|
9
|
+
//# sourceMappingURL=types.local.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.local.d.ts","sourceRoot":"","sources":["../../src/utils/types.local.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAA;AAC3E,OAAO,KAAK,EAAE,MAAM,IAAI,SAAS,EAAE,MAAM,aAAa,CAAA;AAEtD,MAAM,MAAM,MAAM,GAAG,YAAY,CAAA;AAEjC,MAAM,WAAW,OAAO,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,CAAE,SAAQ,aAAa,CAAC,CAAC,CAAC;CAAI;AAEhF,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAA;AAE1D,MAAM,MAAM,aAAa,GAAG,SAAS,CAAA;AAErC,MAAM,MAAM,cAAc,GAAG,aAAa,CAAC,aAAa,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.local.js","sourceRoot":"","sources":["../../src/utils/types.local.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@owlmeans/server-api",
|
|
3
|
-
"version": "0.1.18-rc.
|
|
3
|
+
"version": "0.1.18-rc.50",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -30,23 +30,23 @@
|
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@fastify/cors": "^11.3.0",
|
|
33
|
-
"@fastify/helmet": "^13.1.
|
|
34
|
-
"@fastify/middie": "^9.
|
|
35
|
-
"@fastify/multipart": "^
|
|
36
|
-
"@owlmeans/api": "^0.1.18-rc.
|
|
37
|
-
"@owlmeans/auth": "^0.1.18-rc.
|
|
38
|
-
"@owlmeans/auth-common": "^0.1.18-rc.
|
|
39
|
-
"@owlmeans/context": "^0.1.18-rc.
|
|
40
|
-
"@owlmeans/entrypoint": "^0.1.18-rc.
|
|
41
|
-
"@owlmeans/error": "^0.1.18-rc.
|
|
42
|
-
"@owlmeans/log": "^0.1.18-rc.
|
|
43
|
-
"@owlmeans/route": "^0.1.18-rc.
|
|
44
|
-
"@owlmeans/server-context": "^0.1.18-rc.
|
|
45
|
-
"@owlmeans/server-entrypoint": "^0.1.18-rc.
|
|
33
|
+
"@fastify/helmet": "^13.1.1",
|
|
34
|
+
"@fastify/middie": "^9.3.4",
|
|
35
|
+
"@fastify/multipart": "^10.1.2",
|
|
36
|
+
"@owlmeans/api": "^0.1.18-rc.46",
|
|
37
|
+
"@owlmeans/auth": "^0.1.18-rc.39",
|
|
38
|
+
"@owlmeans/auth-common": "^0.1.18-rc.46",
|
|
39
|
+
"@owlmeans/context": "^0.1.18-rc.33",
|
|
40
|
+
"@owlmeans/entrypoint": "^0.1.18-rc.40",
|
|
41
|
+
"@owlmeans/error": "^0.1.18-rc.37",
|
|
42
|
+
"@owlmeans/log": "^0.1.18-rc.1",
|
|
43
|
+
"@owlmeans/route": "^0.1.18-rc.34",
|
|
44
|
+
"@owlmeans/server-context": "^0.1.18-rc.42",
|
|
45
|
+
"@owlmeans/server-entrypoint": "^0.1.18-rc.39",
|
|
46
46
|
"ajv-errors": "^3.0.0",
|
|
47
|
-
"fastify": "^5.
|
|
48
|
-
"fastify-raw-body": "^
|
|
49
|
-
"pino-pretty": "^13.
|
|
47
|
+
"fastify": "^5.12.5",
|
|
48
|
+
"fastify-raw-body": "^6.0.1",
|
|
49
|
+
"pino-pretty": "^13.2.0"
|
|
50
50
|
},
|
|
51
51
|
"peerDependencies": {
|
|
52
52
|
"ajv": "*",
|
|
@@ -54,9 +54,9 @@
|
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"@owlmeans/dep-config": "workspace:*",
|
|
57
|
-
"@owlmeans/resource": "^0.1.18-rc.
|
|
58
|
-
"@types/bun": "^1.4.
|
|
59
|
-
"@types/node": "^26.
|
|
57
|
+
"@owlmeans/resource": "^0.1.18-rc.39",
|
|
58
|
+
"@types/bun": "^1.4.2",
|
|
59
|
+
"@types/node": "^26.6.4",
|
|
60
60
|
"nodemon": "^3.1.14",
|
|
61
61
|
"typescript": "^7.0.2"
|
|
62
62
|
},
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const bodyLimit = 1024 * 1024 * 20
|
package/src/helper.ts
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
|
|
2
|
-
import type
|
|
3
|
-
import {
|
|
4
|
-
import { EntrypointOutcome } from '@owlmeans/entrypoint'
|
|
5
|
-
import type { AbstractRequest, AbstractResponse } from '@owlmeans/entrypoint'
|
|
2
|
+
import { type BasicConfig, type BasicContext, assertContext } from '@owlmeans/context'
|
|
3
|
+
import { EntrypointOutcome, type AbstractRequest, type AbstractResponse } from '@owlmeans/entrypoint'
|
|
6
4
|
import type { RefedEntrypointHandler } from '@owlmeans/server-entrypoint'
|
|
7
|
-
import type { Config, Context } from './types.js'
|
|
5
|
+
import type { Config, Context, UploadedFile } from './types.js'
|
|
8
6
|
import type { FastifyRequest } from 'fastify'
|
|
9
|
-
import type { MultipartFile } from '@fastify/multipart'
|
|
10
7
|
|
|
11
8
|
/**
|
|
12
9
|
* The context a handler runs against.
|
|
@@ -95,4 +92,3 @@ export const extractUploadedFile = async <T extends {} = {}>(req: AbstractReques
|
|
|
95
92
|
return request.file()
|
|
96
93
|
}
|
|
97
94
|
|
|
98
|
-
export interface UploadedFile extends MultipartFile { }
|
package/src/hold.ts
CHANGED
|
@@ -2,26 +2,7 @@ import Fastify from 'fastify'
|
|
|
2
2
|
import { logger } from '@owlmeans/log'
|
|
3
3
|
import type { ServerConfig } from '@owlmeans/server-context'
|
|
4
4
|
import { CLOSED_HOST, OPENED_HOST, PORT } from './consts.js'
|
|
5
|
-
|
|
6
|
-
export interface ApiPortHoldOptions {
|
|
7
|
-
/**
|
|
8
|
-
* The one path answered 200 while the hold is in place — the app's health endpoint, so
|
|
9
|
-
* whatever supervises the process keeps a conventional liveness answer through the boot.
|
|
10
|
-
* Everything else answers 503 with the same body. Absent, everything is 503.
|
|
11
|
-
*/
|
|
12
|
-
okPath?: string
|
|
13
|
-
/** Body of every answer, evaluated per request so a changing boot phase is reported live. */
|
|
14
|
-
payload?: () => unknown
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export interface ApiPortHold {
|
|
18
|
-
/**
|
|
19
|
-
* Free the port for the real server. Awaits the actual close — `listen()` follows immediately,
|
|
20
|
-
* and a predecessor still bound makes it throw — and force-closes keep-alive sockets, so a
|
|
21
|
-
* supervisor's own poller cannot hold the release open.
|
|
22
|
-
*/
|
|
23
|
-
release: () => Promise<void>
|
|
24
|
-
}
|
|
5
|
+
import type { ApiPortHold, ApiPortHoldOptions } from './types.js'
|
|
25
6
|
|
|
26
7
|
/**
|
|
27
8
|
* Own the app's port while the context initializes, and answer for the app until `listen()`
|
package/src/protocol.ts
CHANGED
|
@@ -1,44 +1,10 @@
|
|
|
1
|
-
import { assertContext } from '@owlmeans/context'
|
|
2
|
-
import type
|
|
3
|
-
import { EntrypointOutcome } from '@owlmeans/entrypoint'
|
|
4
|
-
import type {
|
|
5
|
-
BodyOf, EntrypointProtocolDeclaration, HandlerRequest, OpenRequest, OpenValue, ParamsOf, RequestOf, ResponseOf,
|
|
6
|
-
} from '@owlmeans/entrypoint'
|
|
7
|
-
import type { AbstractRequest } from '@owlmeans/entrypoint'
|
|
1
|
+
import { assertContext, type BasicConfig, type BasicContext } from '@owlmeans/context'
|
|
2
|
+
import { EntrypointOutcome, type BodyOf, type EntrypointProtocolDeclaration, type HandlerRequest, type OpenRequest, type ParamsOf, type RequestOf, type ResponseOf, type AbstractRequest } from '@owlmeans/entrypoint'
|
|
8
3
|
import type { BoundEntrypointHandler } from '@owlmeans/server-entrypoint'
|
|
9
4
|
import { HandlerMisconfiguredError } from './errors.js'
|
|
10
5
|
import { logger } from '@owlmeans/log'
|
|
6
|
+
import type { AnyBoundHandler, BodyProtocol, ContextCarrier, HandlerResponse, MaybePromise, ParamsProtocol } from './types.local.js'
|
|
11
7
|
|
|
12
|
-
/**
|
|
13
|
-
* True for a response the declaration left with no compile-time contract: `typed<any>()` (an
|
|
14
|
-
* `[any] extends [X]` conditional does not produce `any`'s usual both-branches union once the
|
|
15
|
-
* checked type is wrapped in a tuple, so it resolves to a single branch like any other type) and
|
|
16
|
-
* a response inferred as bare `typed()` with nothing to infer from, which resolves to `undefined`
|
|
17
|
-
* with no shape to validate a handler's return against — the same signal a zero-argument
|
|
18
|
-
* `contract()` produces for a genuinely response-less route. Neither means "this handler must
|
|
19
|
-
* return void": it means the declaration did not constrain the response, so the handler is free to
|
|
20
|
-
* return whatever its route actually sends.
|
|
21
|
-
*/
|
|
22
|
-
type IsUntypedResponse<T> = 0 extends (1 & T) ? true : [T] extends [undefined] ? true : false
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* The type a bound handler is allowed to return for a given protocol response.
|
|
26
|
-
*
|
|
27
|
-
* A concretely typed or schema-backed `Response` is returned unchanged — the handler must produce
|
|
28
|
-
* exactly that shape. An untyped one (see `IsUntypedResponse` above) relaxes to `any`: the
|
|
29
|
-
* declaration made no promise about the response, so nothing here should force a handler bound to
|
|
30
|
-
* it into returning `void`.
|
|
31
|
-
*/
|
|
32
|
-
type HandlerResponse<Response> = IsUntypedResponse<Response> extends true ? any : Response
|
|
33
|
-
type MaybePromise<Value> = Value | Promise<Value>
|
|
34
|
-
type BodyProtocol<Protocol extends EntrypointProtocolDeclaration> = RequestOf<Protocol> extends { body: OpenValue }
|
|
35
|
-
? Protocol : never
|
|
36
|
-
type ParamsProtocol<Protocol extends EntrypointProtocolDeclaration> = RequestOf<Protocol> extends { params: object }
|
|
37
|
-
? Protocol : never
|
|
38
|
-
|
|
39
|
-
interface ContextCarrier<Context> {
|
|
40
|
-
_ctx?: Context
|
|
41
|
-
}
|
|
42
8
|
|
|
43
9
|
const contextFor = <Context extends BasicContext<BasicConfig>>(
|
|
44
10
|
request: AbstractRequest,
|
|
@@ -75,9 +41,6 @@ const bind = <Protocol extends EntrypointProtocolDeclaration, Context extends Ba
|
|
|
75
41
|
},
|
|
76
42
|
})
|
|
77
43
|
|
|
78
|
-
/** Structural, not `instanceof`: a `BoundEntrypointHandler` crosses no class boundary a runtime check could use. */
|
|
79
|
-
type AnyBoundHandler = BoundEntrypointHandler<EntrypointProtocolDeclaration>
|
|
80
|
-
|
|
81
44
|
/**
|
|
82
45
|
* `value` is shaped like a `BoundEntrypointHandler` — never a plain function, which also carries
|
|
83
46
|
* its own `.bind` and would otherwise pass a `typeof value.bind === 'function'` check alone.
|
package/src/server.ts
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ServerContext } from '@owlmeans/server-context'
|
|
2
2
|
import type { ApiServer, ApiServerAppend } from './types.js'
|
|
3
3
|
import { assertContext, createService } from '@owlmeans/context'
|
|
4
|
-
import { canServeModule, executeResponse, provideRequest } from './utils/index.js'
|
|
4
|
+
import { canServeModule, executeResponse, provideRequest, createServerHandler, fixFormatDates } from './utils/index.js'
|
|
5
5
|
import { DEFAULT_ALIAS, CLOSED_HOST, PORT, OPENED_HOST } from './consts.js'
|
|
6
6
|
import type { ServerEntrypoint } from '@owlmeans/server-entrypoint'
|
|
7
7
|
import { RouteMethod } from '@owlmeans/route'
|
|
8
|
-
import { createServerHandler, fixFormatDates } from './utils/index.js'
|
|
9
8
|
import { provideResponse } from '@owlmeans/entrypoint'
|
|
10
9
|
import { TOKEN_UPDATE } from '@owlmeans/auth-common'
|
|
11
|
-
import { INCIDENT_ID_HEADER } from './utils/
|
|
10
|
+
import { INCIDENT_ID_HEADER } from './utils/consts.js'
|
|
12
11
|
import { DENIAL_KIND_HEADER } from '@owlmeans/api'
|
|
13
12
|
import { logger } from '@owlmeans/log'
|
|
14
13
|
import { fastifyLogger } from './utils/log.js'
|
|
@@ -24,6 +23,8 @@ import Multipart from '@fastify/multipart'
|
|
|
24
23
|
import formatsPlugin from 'ajv-formats'
|
|
25
24
|
import Ajv from 'ajv'
|
|
26
25
|
import ajvErrors from "ajv-errors"
|
|
26
|
+
import { bodyLimit } from './consts.local.js'
|
|
27
|
+
import type { Config, Context } from './types.local.js'
|
|
27
28
|
|
|
28
29
|
|
|
29
30
|
const ajv = new Ajv({
|
|
@@ -36,10 +37,6 @@ const ajv = new Ajv({
|
|
|
36
37
|
formatsPlugin(ajv)
|
|
37
38
|
ajvErrors(ajv, { singleError: true })
|
|
38
39
|
|
|
39
|
-
type Config = ServerConfig
|
|
40
|
-
type Context = ServerContext<Config>
|
|
41
|
-
|
|
42
|
-
const bodyLimit = 1024 * 1024 * 20
|
|
43
40
|
|
|
44
41
|
const http = logger('http')
|
|
45
42
|
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { EntrypointProtocolDeclaration, OpenValue, RequestOf } from '@owlmeans/entrypoint'
|
|
2
|
+
import type { BoundEntrypointHandler } from '@owlmeans/server-entrypoint'
|
|
3
|
+
import type { ServerConfig, ServerContext } from '@owlmeans/server-context'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* True for a response the declaration left with no compile-time contract: `typed<any>()` (an
|
|
7
|
+
* `[any] extends [X]` conditional does not produce `any`'s usual both-branches union once the
|
|
8
|
+
* checked type is wrapped in a tuple, so it resolves to a single branch like any other type) and
|
|
9
|
+
* a response inferred as bare `typed()` with nothing to infer from, which resolves to `undefined`
|
|
10
|
+
* with no shape to validate a handler's return against — the same signal a zero-argument
|
|
11
|
+
* `contract()` produces for a genuinely response-less route. Neither means "this handler must
|
|
12
|
+
* return void": it means the declaration did not constrain the response, so the handler is free to
|
|
13
|
+
* return whatever its route actually sends.
|
|
14
|
+
*/
|
|
15
|
+
export type IsUntypedResponse<T> = 0 extends (1 & T) ? true : [T] extends [undefined] ? true : false
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The type a bound handler is allowed to return for a given protocol response.
|
|
19
|
+
*
|
|
20
|
+
* A concretely typed or schema-backed `Response` is returned unchanged — the handler must produce
|
|
21
|
+
* exactly that shape. An untyped one (see `IsUntypedResponse` above) relaxes to `any`: the
|
|
22
|
+
* declaration made no promise about the response, so nothing here should force a handler bound to
|
|
23
|
+
* it into returning `void`.
|
|
24
|
+
*/
|
|
25
|
+
export type HandlerResponse<Response> = IsUntypedResponse<Response> extends true ? any : Response
|
|
26
|
+
|
|
27
|
+
export type MaybePromise<Value> = Value | Promise<Value>
|
|
28
|
+
|
|
29
|
+
export type BodyProtocol<Protocol extends EntrypointProtocolDeclaration> = RequestOf<Protocol> extends { body: OpenValue }
|
|
30
|
+
? Protocol : never
|
|
31
|
+
|
|
32
|
+
export type ParamsProtocol<Protocol extends EntrypointProtocolDeclaration> = RequestOf<Protocol> extends { params: object }
|
|
33
|
+
? Protocol : never
|
|
34
|
+
|
|
35
|
+
export type Config = ServerConfig
|
|
36
|
+
|
|
37
|
+
export type Context = ServerContext<Config>
|
|
38
|
+
|
|
39
|
+
export interface ContextCarrier<Context> {
|
|
40
|
+
_ctx?: Context
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Structural, not `instanceof`: a `BoundEntrypointHandler` crosses no class boundary a runtime check could use. */
|
|
44
|
+
export type AnyBoundHandler = BoundEntrypointHandler<EntrypointProtocolDeclaration>
|
package/src/types.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type { InitializedService } from '@owlmeans/context'
|
|
|
3
3
|
import type { ServerConfig, ServerContext } from '@owlmeans/server-context'
|
|
4
4
|
import type { FastifyInstance, FastifyReply, FastifyRequest } from 'fastify'
|
|
5
5
|
import '@fastify/middie/types/index.d.ts'
|
|
6
|
+
import type { MultipartFile } from '@fastify/multipart'
|
|
6
7
|
|
|
7
8
|
export interface ApiServer extends InitializedService {
|
|
8
9
|
server: FastifyInstance
|
|
@@ -35,3 +36,25 @@ export interface Config extends ServerConfig {
|
|
|
35
36
|
|
|
36
37
|
export interface Context<C extends Config = Config> extends ServerContext<C>,
|
|
37
38
|
ApiServerAppend { }
|
|
39
|
+
|
|
40
|
+
export interface UploadedFile extends MultipartFile { }
|
|
41
|
+
|
|
42
|
+
export interface ApiPortHoldOptions {
|
|
43
|
+
/**
|
|
44
|
+
* The one path answered 200 while the hold is in place — the app's health endpoint, so
|
|
45
|
+
* whatever supervises the process keeps a conventional liveness answer through the boot.
|
|
46
|
+
* Everything else answers 503 with the same body. Absent, everything is 503.
|
|
47
|
+
*/
|
|
48
|
+
okPath?: string
|
|
49
|
+
/** Body of every answer, evaluated per request so a changing boot phase is reported live. */
|
|
50
|
+
payload?: () => unknown
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface ApiPortHold {
|
|
54
|
+
/**
|
|
55
|
+
* Free the port for the real server. Awaits the actual close — `listen()` follows immediately,
|
|
56
|
+
* and a predecessor still bound makes it throw — and force-closes keep-alive sockets, so a
|
|
57
|
+
* supervisor's own poller cannot hold the release open.
|
|
58
|
+
*/
|
|
59
|
+
release: () => Promise<void>
|
|
60
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const INCIDENT_ID_HEADER = 'X-Incident-ID'
|
package/src/utils/error.ts
CHANGED
|
@@ -8,26 +8,10 @@ import { isResilientError, ResilientError, SEPARATOR } from '@owlmeans/error'
|
|
|
8
8
|
import { randomUUID } from 'node:crypto'
|
|
9
9
|
import { logger } from '@owlmeans/log'
|
|
10
10
|
import type { Config, HttpErrorExposure } from '../types.js'
|
|
11
|
+
import { CLIENT_ERROR_FIRST, CLIENT_ERROR_LAST, SERVER_ERROR_FIRST, SERVER_ERROR_LAST } from './consts.local.js'
|
|
12
|
+
import { INCIDENT_ID_HEADER } from './consts.js'
|
|
13
|
+
import type { HttpStatusDeclaration, SerializedHttpError } from './types.js'
|
|
11
14
|
|
|
12
|
-
export const INCIDENT_ID_HEADER = 'X-Incident-ID'
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* What an error class may declare about the HTTP status it is answered with.
|
|
16
|
-
*
|
|
17
|
-
* Structural on purpose: the classes that declare it live in packages that must not depend on an
|
|
18
|
-
* HTTP server (`@owlmeans/payment`, a product's contract package), so they write a plain
|
|
19
|
-
* `public static httpStatus = 409` and nothing imports this type.
|
|
20
|
-
*/
|
|
21
|
-
export interface HttpStatusDeclaration {
|
|
22
|
-
httpStatus?: unknown
|
|
23
|
-
/** Explicit opt-in for a declared 5xx response. Client-error declarations need no opt-in. */
|
|
24
|
-
allowServerErrorStatus?: unknown
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const CLIENT_ERROR_FIRST = 400
|
|
28
|
-
const CLIENT_ERROR_LAST = 499
|
|
29
|
-
const SERVER_ERROR_FIRST = 500
|
|
30
|
-
const SERVER_ERROR_LAST = 599
|
|
31
15
|
|
|
32
16
|
/**
|
|
33
17
|
* The HTTP status an error's class declares, or `null` when it declares none that may be honoured.
|
|
@@ -123,12 +107,6 @@ export const errorStatus = (error: unknown): number => {
|
|
|
123
107
|
return declaredErrorStatus(error) ?? SERVER_ERROR
|
|
124
108
|
}
|
|
125
109
|
|
|
126
|
-
export interface SerializedHttpError {
|
|
127
|
-
status: number
|
|
128
|
-
body: string
|
|
129
|
-
incidentId: string
|
|
130
|
-
}
|
|
131
|
-
|
|
132
110
|
/** Invalid or absent configuration always resolves to the production-safe policy. */
|
|
133
111
|
export const errorExposure = (config?: Pick<Config, 'http'>): HttpErrorExposure =>
|
|
134
112
|
config?.http?.errors?.exposure === 'development' ? 'development' : 'production'
|
package/src/utils/guards.ts
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
import type { FastifyReply, FastifyRequest } from 'fastify'
|
|
2
2
|
import type { ServerEntrypoint } from '@owlmeans/server-entrypoint'
|
|
3
|
-
import type
|
|
4
|
-
import { provideResponse } from '@owlmeans/entrypoint'
|
|
5
|
-
import type { ServerConfig, ServerContext } from '@owlmeans/server-context'
|
|
3
|
+
import { type GuardService, provideResponse } from '@owlmeans/entrypoint'
|
|
6
4
|
import { executeResponse, provideRequest } from './payload.js'
|
|
7
5
|
import { AuthFailedError } from '../errors.js'
|
|
8
6
|
import type { Auth } from '@owlmeans/auth'
|
|
9
7
|
import { attachEntity } from '@owlmeans/auth-common'
|
|
8
|
+
import type { Config, Context } from './types.local.js'
|
|
10
9
|
|
|
11
|
-
type Config = ServerConfig
|
|
12
|
-
interface Context<C extends Config = Config> extends ServerContext<C> { }
|
|
13
10
|
|
|
14
11
|
export const authorize = async <C extends Config, T extends Context<C>>(
|
|
15
12
|
context: T, module: ServerEntrypoint<FastifyRequest>,
|
package/src/utils/index.ts
CHANGED
package/src/utils/log.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import type { FastifyBaseLogger } from 'fastify'
|
|
2
|
-
import { logger } from '@owlmeans/log'
|
|
3
|
-
import type {
|
|
4
|
-
|
|
5
|
-
type Severity = 'debug' | 'info' | 'warn' | 'error'
|
|
2
|
+
import { logger, type LogLevel, type Logger } from '@owlmeans/log'
|
|
3
|
+
import type { Severity } from './types.local.js'
|
|
6
4
|
|
|
7
5
|
/**
|
|
8
6
|
* What Fastify says about itself, mapped to what an operator needs at each level.
|
package/src/utils/server.ts
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
import { AppType } from '@owlmeans/context'
|
|
1
|
+
import { AppType, assertContext } from '@owlmeans/context'
|
|
2
2
|
import type { FastifyReply, FastifyRequest } from 'fastify'
|
|
3
|
-
import { assertContext } from '@owlmeans/context'
|
|
4
3
|
import type { FixerService, ServerEntrypoint } from '@owlmeans/server-entrypoint'
|
|
5
|
-
import type
|
|
6
|
-
import type { GateService } from '@owlmeans/entrypoint'
|
|
7
|
-
import { provideResponse } from '@owlmeans/entrypoint'
|
|
8
|
-
import type { ServerContext } from '@owlmeans/server-context'
|
|
4
|
+
import { type CommonEntrypoint, type GateService, provideResponse } from '@owlmeans/entrypoint'
|
|
9
5
|
import { ResilientError } from '@owlmeans/error'
|
|
10
6
|
import { OK } from '@owlmeans/api'
|
|
11
7
|
import { logger } from '@owlmeans/log'
|
|
@@ -13,12 +9,10 @@ import { errorExposure, handleError } from './error.js'
|
|
|
13
9
|
import { executeResponse, provideRequest } from './payload.js'
|
|
14
10
|
import { authorize } from './guards.js'
|
|
15
11
|
import { RouteProtocols } from '@owlmeans/route'
|
|
16
|
-
import type {
|
|
12
|
+
import type { ServerConfig2, ServerContext2 } from './types.local.js'
|
|
17
13
|
|
|
18
|
-
type Config = ApiConfig
|
|
19
|
-
type Context = ServerContext<Config>
|
|
20
14
|
|
|
21
|
-
export const canServeModule = (context:
|
|
15
|
+
export const canServeModule = (context: ServerContext2, module: CommonEntrypoint): module is ServerEntrypoint<unknown> => {
|
|
22
16
|
if (module.route.route.type !== AppType.Backend) {
|
|
23
17
|
return false
|
|
24
18
|
}
|
|
@@ -37,7 +31,7 @@ export const canServeModule = (context: Context, module: CommonEntrypoint): modu
|
|
|
37
31
|
export const createServerHandler = (module: ServerEntrypoint<FastifyRequest>, location: string) =>
|
|
38
32
|
async (req: FastifyRequest, reply: FastifyReply) => {
|
|
39
33
|
// We passed context using fastify request object
|
|
40
|
-
let context = assertContext<
|
|
34
|
+
let context = assertContext<ServerConfig2, ServerContext2>((req as any)._ctx, location)
|
|
41
35
|
try {
|
|
42
36
|
const authorized = await authorize(context, module, req, reply)
|
|
43
37
|
context = authorized[0]
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ServerConfig, ServerContext } from '@owlmeans/server-context'
|
|
2
|
+
import type { Config as ApiConfig } from '../types.js'
|
|
3
|
+
|
|
4
|
+
export type Config = ServerConfig
|
|
5
|
+
|
|
6
|
+
export interface Context<C extends Config = Config> extends ServerContext<C> { }
|
|
7
|
+
|
|
8
|
+
export type Severity = 'debug' | 'info' | 'warn' | 'error'
|
|
9
|
+
|
|
10
|
+
export type ServerConfig2 = ApiConfig
|
|
11
|
+
|
|
12
|
+
export type ServerContext2 = ServerContext<ServerConfig2>
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What an error class may declare about the HTTP status it is answered with.
|
|
3
|
+
*
|
|
4
|
+
* Structural on purpose: the classes that declare it live in packages that must not depend on an
|
|
5
|
+
* HTTP server (`@owlmeans/payment`, a product's contract package), so they write a plain
|
|
6
|
+
* `public static httpStatus = 409` and nothing imports this type.
|
|
7
|
+
*/
|
|
8
|
+
export interface HttpStatusDeclaration {
|
|
9
|
+
httpStatus?: unknown
|
|
10
|
+
/** Explicit opt-in for a declared 5xx response. Client-error declarations need no opt-in. */
|
|
11
|
+
allowServerErrorStatus?: unknown
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface SerializedHttpError {
|
|
15
|
+
status: number
|
|
16
|
+
body: string
|
|
17
|
+
incidentId: string
|
|
18
|
+
}
|
|
@@ -4,7 +4,8 @@ import type { FastifyInstance } from 'fastify'
|
|
|
4
4
|
import { AuthForbidden, AuthorizationError, AuthUnknown } from '@owlmeans/auth'
|
|
5
5
|
import { ResilientError, SEPARATOR } from '@owlmeans/error'
|
|
6
6
|
import { provideResponse } from '@owlmeans/entrypoint'
|
|
7
|
-
import { errorExposure, errorStatus, handleError
|
|
7
|
+
import { errorExposure, errorStatus, handleError } from '../src/utils/error.js'
|
|
8
|
+
import { INCIDENT_ID_HEADER } from '../src/utils/consts.js'
|
|
8
9
|
import { executeResponse } from '../src/utils/payload.js'
|
|
9
10
|
import { AccessError, AuthFailedError } from '../src/errors.js'
|
|
10
11
|
import { DENIAL_KIND_HEADER, ACCESS_DENIED_KIND, httpStatusOf } from '@owlmeans/api'
|