akanjs 3.2.0-rc.4 → 3.2.0-rc.5

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 CHANGED
@@ -171,6 +171,7 @@
171
171
 
172
172
  `akan lint`'s `akan.service.call-in-loop` fix and the agent guidelines name `create<Model>Many` as the way to write a set once.
173
173
 
174
+ - 73f8830: An error an endpoint declares in `errors` and throws with that status under 500 is now logged at debug, as a returned call is, rather than as an ERROR line. A public endpoint that answers a bad token with a declared 404 no longer sends every probe, token scan or mistyped webhook URL to real-error alerts. Undeclared errors, a declared key thrown with another status, and every 5xx still log as errors.
174
175
  - 958f175: A dev server now answers only the host names it can be reached under locally. Under `akan start`, or on a local dev runtime, with `AKAN_ALLOWED_HOSTS` unset, it answers `localhost` and `*.localhost`, IPv4 and IPv6 addresses (a phone on the LAN included), and the app's own hosts: its route domains and `<app>-<environment>.<serveDomain>`. A request under any other `Host`, the HMR socket and the `/_akan/*` dev routes included, gets a 403 that names `AKAN_ALLOWED_HOSTS`. To open a dev server under another name, such as a container's service name or a forwarded editor URL, list every `host:port` it should answer there; a set list replaces the default, as before. A deployed server with the variable unset still answers every `Host`.
175
176
 
176
177
  `akan tunnel` and `akan start --share` keep working: the tunnel agent now dials the local app under the app's own address and leaves the public host name in `x-forwarded-host`, which is where the app already reads it. A redirect a page raises during SSR now sends a same-origin target as a relative `Location`, so a tunnel or proxy caller lands on the host it used rather than the one the server was dialed as; a target on another origin stays absolute.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "akanjs",
3
- "version": "3.2.0-rc.4",
3
+ "version": "3.2.0-rc.5",
4
4
  "sourceType": "module",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -1,6 +1,7 @@
1
1
  import type { Adaptor } from "akanjs/service";
2
2
 
3
3
  import type { EndpointInfo } from "./endpointInfo";
4
+ import type { ExceptionLike } from "./exception";
4
5
  import type { EndpointErrors } from "./types";
5
6
 
6
7
  export class EndpointErrorContract {
@@ -34,4 +35,14 @@ export class EndpointErrorContract {
34
35
  `"${key}" threw ${thrownKey}, which its \`errors\` declaration leaves out: OpenAPI and the MCP catalogue do not publish it.`,
35
36
  );
36
37
  }
38
+
39
+ static promised(endpointInfo: EndpointInfo, error: ExceptionLike) {
40
+ const keys: readonly string[] | undefined = endpointInfo.signalOption.errors?.[error.statusCode];
41
+ return error.statusCode < 500 && keys?.includes(EndpointErrorContract.wireKey(error)) === true;
42
+ }
43
+
44
+ static wireKey(error: ExceptionLike): string {
45
+ const wire = (error.toJSON() as { error?: unknown }).error;
46
+ return typeof wire === "string" ? wire : (error as unknown as Error).message;
47
+ }
37
48
  }
@@ -1,5 +1,6 @@
1
1
  import type { BackendEnv, Cls, PromiseOrObject } from "akanjs/base";
2
2
  import { Logger } from "akanjs/common";
3
+ import { EndpointErrorContract } from "./endpointErrorContract";
3
4
  import { Exception, isExceptionLike } from "./exception";
4
5
  import type { SignalContext } from "./signalContext";
5
6
 
@@ -37,8 +38,11 @@ export class Logging extends middleware("logging") {
37
38
 
38
39
  if (context.isBodyReadFailure(error)) throw error;
39
40
  const line = `Error ${context.endpointInfo.type}-${context.key} / ${Date.now() - start}ms: ${String(error)}`;
40
-
41
- if (isExceptionLike(error) && error.statusCode === 429) {
41
+
42
+ if (
43
+ isExceptionLike(error) &&
44
+ (error.statusCode === 429 || EndpointErrorContract.promised(context.endpointInfo, error))
45
+ ) {
42
46
  if (debug) context.adaptor.logger.debug(line);
43
47
  } else context.adaptor.logger.error(line);
44
48
  throw error;
@@ -30,7 +30,7 @@ import { EndpointErrorContract } from "./endpointErrorContract";
30
30
  import { EndpointIdempotency } from "./endpointIdempotency";
31
31
  import type { ArgInfo, EndpointInfo, EndpointType } from "./endpointInfo";
32
32
  import { EndpointRateLimit } from "./endpointRateLimit";
33
- import { Exception, type ExceptionLike, isExceptionLike } from "./exception";
33
+ import { Exception, isExceptionLike } from "./exception";
34
34
  import { type GuardCls, type GuardScope, guardOf } from "./guard";
35
35
  import { MiddlewareChain } from "./middlewareChain";
36
36
  import { RoomKey } from "./roomKey";
@@ -429,7 +429,7 @@ export class SignalContext<
429
429
  return await fn();
430
430
  } catch (error) {
431
431
  if (isExceptionLike(error))
432
- EndpointErrorContract.checkThrown(endpoint, endpointInfo, key, SignalContext.#wireKey(error));
432
+ EndpointErrorContract.checkThrown(endpoint, endpointInfo, key, EndpointErrorContract.wireKey(error));
433
433
  else if (SignalFailure.generalized(error).statusCode >= 500) {
434
434
  const message = error instanceof Error ? error.message : String(error);
435
435
  const stack = error instanceof Error ? error.stack : undefined;
@@ -463,11 +463,6 @@ export class SignalContext<
463
463
  return SignalFailure.response(error, { path: endpointInfo.getPath(key) });
464
464
  }
465
465
  }
466
-
467
- static #wireKey(error: ExceptionLike): string {
468
- const wire = (error.toJSON() as { error?: unknown }).error;
469
- return typeof wire === "string" ? wire : (error as unknown as Error).message;
470
- }
471
466
  static #exceptionHeaders(error: { statusCode: number }): Record<string, string> {
472
467
  const seconds = (error as { data?: { seconds?: unknown } }).data?.seconds;
473
468
  if (error.statusCode !== 429 || typeof seconds !== "number") return { "Content-Type": "application/json" };
@@ -1,5 +1,6 @@
1
1
  import type { Adaptor } from "akanjs/service";
2
2
  import type { EndpointInfo } from "./endpointInfo.d.ts";
3
+ import type { ExceptionLike } from "./exception.d.ts";
3
4
  import type { EndpointErrors } from "./types.d.ts";
4
5
  export declare class EndpointErrorContract {
5
6
  #private;
@@ -7,4 +8,6 @@ export declare class EndpointErrorContract {
7
8
  static assertDeclared(errors: EndpointErrors | undefined): void;
8
9
  static keysOf(errors: EndpointErrors | undefined): string[];
9
10
  static checkThrown(endpoint: Adaptor, endpointInfo: EndpointInfo, key: string, thrownKey: string): void;
11
+ static promised(endpointInfo: EndpointInfo, error: ExceptionLike): boolean;
12
+ static wireKey(error: ExceptionLike): string;
10
13
  }