lanka 2.2.2 → 2.3.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.
Files changed (41) hide show
  1. package/dist/{ALankaGateway-CzBISB0L.d.ts → ALankaGateway-CQrEPUHM.d.ts} +1 -0
  2. package/dist/{LankaError-D6RWNyLM.d.ts → LankaError-CfDmuGKc.d.ts} +17 -0
  3. package/dist/_extend/index.d.ts +2 -2
  4. package/dist/_extend/index.js +7 -7
  5. package/dist/_internal/index.d.ts +3 -3
  6. package/dist/_internal/index.js +2 -2
  7. package/dist/{activeRuntime-DxB62KN4.d.ts → activeRuntime-1Zj2m1Sx.d.ts} +1 -1
  8. package/dist/bootstrap/index.d.ts +5 -5
  9. package/dist/bootstrap/index.js +2 -2
  10. package/dist/{chunk-DKLOCKS4.js → chunk-3GQGNG7S.js} +2 -2
  11. package/dist/{chunk-HVSQOMRE.js → chunk-BIJTUWUD.js} +2 -2
  12. package/dist/{chunk-G32H73QY.js → chunk-INHAKVSO.js} +17 -1
  13. package/dist/chunk-INHAKVSO.js.map +1 -0
  14. package/dist/{chunk-YR4MZXMU.js → chunk-USZ7CFCU.js} +1 -1
  15. package/dist/chunk-USZ7CFCU.js.map +1 -0
  16. package/dist/{chunk-CRIRTOLB.js → chunk-VI4DY5PN.js} +2 -2
  17. package/dist/{chunk-JLBSXJRX.js → chunk-YEP54YU5.js} +4 -4
  18. package/dist/{createLanka-AuiMfPL9.d.ts → createLanka-XbyOz9ld.d.ts} +2 -2
  19. package/dist/errors/index.d.ts +2 -2
  20. package/dist/errors/index.js +2 -2
  21. package/dist/gateway/index.d.ts +3 -3
  22. package/dist/gateway/index.js +114 -45
  23. package/dist/gateway/index.js.map +1 -1
  24. package/dist/index.d.ts +5 -5
  25. package/dist/index.js +3 -3
  26. package/dist/{lankaRequestMiddleware-DAC5kCb7.d.ts → lankaRequestMiddleware-CbXc1PAV.d.ts} +3 -1
  27. package/dist/locator/gateway/lanka-gateway-locator/LankaGatewayLocator.d.ts +1 -1
  28. package/dist/locator/index.d.ts +1 -1
  29. package/dist/stream/index.d.ts +4 -4
  30. package/dist/validation/index.d.ts +1 -1
  31. package/dist/validation/index.js +3 -3
  32. package/package.json +1 -1
  33. package/skills/lanka-core/SKILL.md +14 -10
  34. package/skills/lanka-core/reference.md +20 -1
  35. package/skills/lanka-packages/SKILL.md +1 -1
  36. package/dist/chunk-G32H73QY.js.map +0 -1
  37. package/dist/chunk-YR4MZXMU.js.map +0 -1
  38. /package/dist/{chunk-DKLOCKS4.js.map → chunk-3GQGNG7S.js.map} +0 -0
  39. /package/dist/{chunk-HVSQOMRE.js.map → chunk-BIJTUWUD.js.map} +0 -0
  40. /package/dist/{chunk-CRIRTOLB.js.map → chunk-VI4DY5PN.js.map} +0 -0
  41. /package/dist/{chunk-JLBSXJRX.js.map → chunk-YEP54YU5.js.map} +0 -0
@@ -37,6 +37,7 @@ type TLankaRequestInit = Omit<RequestInit, "body"> & {
37
37
  */
38
38
  type TLankaExecuteOptions<TOptions> = TOptions & {
39
39
  signal?: AbortSignal;
40
+ /** The attempt's deadline. It stops while the page is seen hidden, and resumes when it shows. */
40
41
  timeoutMs?: number;
41
42
  };
42
43
 
@@ -60,6 +60,8 @@ interface ILankaErrorInit {
60
60
  * stream and get nothing. Core does not look into the body; it carries it.
61
61
  */
62
62
  body?: unknown;
63
+ /** The app went to the background during the attempt. See `LankaError.isFromBackground`. */
64
+ isFromBackground?: boolean;
63
65
  /** The original error, when this one wraps it. */
64
66
  cause?: unknown;
65
67
  }
@@ -92,6 +94,21 @@ declare class LankaError extends Error implements ILankaApiError {
92
94
  readonly fields?: readonly ILankaFieldError[];
93
95
  /** The parsed error response body; core carries it without reading it. */
94
96
  readonly body?: unknown;
97
+ /**
98
+ * The app went to the background while the attempt was on the wire: the page
99
+ * was seen to hide, or to unload. Set by the framework on the `network` and
100
+ * `aborted` failures it tags; `false` everywhere else.
101
+ *
102
+ * What it tells is WHEN, not why. On a mobile WebView it usually means the
103
+ * page was frozen and the platform cut the request; on a desktop tab that kept
104
+ * running, the server may just as well have failed. Segment telemetry by it —
105
+ * do not drop what it marks. Never on a `timeout`: the deadline stops while
106
+ * the page is hidden, so one that still ran out was slow in plain sight.
107
+ *
108
+ * Read it as truthy: a `LankaError` from an older copy of the framework in
109
+ * the same tree passes `LankaError.is` without it.
110
+ */
111
+ readonly isFromBackground: boolean;
95
112
  constructor(init: ILankaErrorInit);
96
113
  /** The `ILankaApiError` field. The details are the message list. */
97
114
  get errors(): string[] | undefined;
@@ -8,12 +8,12 @@ export { LankaGatewayLocator } from '../locator/gateway/lanka-gateway-locator/La
8
8
  export { LankaScenarioLocator } from '../locator/scenario/lanka-scenario-locator/LankaScenarioLocator.js';
9
9
  export { LankaSingletonLocator } from '../locator/singleton/lanka-singleton-locator/LankaSingletonLocator.js';
10
10
  export { LankaSharedStoreLocator } from '../locator/shared-store/lanka-shared-store-locator/LankaSharedStoreLocator.js';
11
- export { c as composeLankaRequestMiddleware } from '../lankaRequestMiddleware-DAC5kCb7.js';
11
+ export { c as composeLankaRequestMiddleware } from '../lankaRequestMiddleware-CbXc1PAV.js';
12
12
  import { I as ILankaReadableVM } from '../ILankaReadableVM-BoPzHEPV.js';
13
13
  import '../ILankaScenario-7J3MoKiY.js';
14
14
  import '../ILankaScenarioVM-DKwjbIRq.js';
15
15
  import '../ILankaScenarioMetadata-DgOxvpwx.js';
16
- import '../ALankaGateway-CzBISB0L.js';
16
+ import '../ALankaGateway-CQrEPUHM.js';
17
17
  import '../lankaStandardValidator-BUFnysK0.js';
18
18
  import '@standard-schema/spec';
19
19
  import '../ILankaFieldError-D5931-vT.js';
@@ -1,22 +1,22 @@
1
- import {
2
- createLankaLocatorProxy
3
- } from "../chunk-2ICKGQXS.js";
4
1
  import {
5
2
  lankaBlindSpotRegistry
6
3
  } from "../chunk-UDP6IXDS.js";
4
+ import {
5
+ createLankaLocatorProxy
6
+ } from "../chunk-2ICKGQXS.js";
7
7
  import {
8
8
  createLankaScope,
9
9
  lankaVMRecipes
10
10
  } from "../chunk-M4BK6GBV.js";
11
+ import {
12
+ LankaSingletonLocator
13
+ } from "../chunk-24MUFFHF.js";
11
14
  import {
12
15
  LankaSharedStoreLocator
13
16
  } from "../chunk-3R2NO47A.js";
14
17
  import {
15
18
  LankaGatewayLocator
16
19
  } from "../chunk-BMF4TM2Z.js";
17
- import {
18
- LankaSingletonLocator
19
- } from "../chunk-24MUFFHF.js";
20
20
  import "../chunk-JZJ6GXX3.js";
21
21
  import {
22
22
  LankaScenarioLocator
@@ -33,7 +33,7 @@ import {
33
33
  } from "../chunk-L27FF2IH.js";
34
34
  import {
35
35
  composeLankaRequestMiddleware
36
- } from "../chunk-YR4MZXMU.js";
36
+ } from "../chunk-USZ7CFCU.js";
37
37
  import "../chunk-AMLUKB6A.js";
38
38
  import "../chunk-SP5OUTWF.js";
39
39
  import {
@@ -1,4 +1,4 @@
1
- export { I as ILankaRuntime, T as TLankaRuntimeResolver, a as TLankaScopeResolver, g as getLankaProcessRuntime, h as hasLankaScopeResolver, s as setActiveLankaRuntime, b as setLankaRuntimeResolver, c as setLankaScopeResolver } from '../activeRuntime-DxB62KN4.js';
1
+ export { I as ILankaRuntime, T as TLankaRuntimeResolver, a as TLankaScopeResolver, g as getLankaProcessRuntime, h as hasLankaScopeResolver, s as setActiveLankaRuntime, b as setLankaRuntimeResolver, c as setLankaScopeResolver } from '../activeRuntime-1Zj2m1Sx.js';
2
2
  import { a as TLankaValidationResult } from '../lankaStandardValidator-BUFnysK0.js';
3
3
  import '../ILankaScenario-7J3MoKiY.js';
4
4
  import '../LankaScenariosRegistry-DiLN9xwy.js';
@@ -7,9 +7,9 @@ import '../ILankaScenarioMetadata-DgOxvpwx.js';
7
7
  import '../LankaScenarioVMRegistry-CFzCpIFd.js';
8
8
  import '../ILankaRuntimeConfig-Vl436GWK.js';
9
9
  import '../lankaHttpInFlight-Bk1eIuSx.js';
10
- import '../lankaRequestMiddleware-DAC5kCb7.js';
10
+ import '../lankaRequestMiddleware-CbXc1PAV.js';
11
11
  import '../locator/gateway/lanka-gateway-locator/LankaGatewayLocator.js';
12
- import '../ALankaGateway-CzBISB0L.js';
12
+ import '../ALankaGateway-CQrEPUHM.js';
13
13
  import '../ALankaLocator-BUCCz0Q5.js';
14
14
  import '@standard-schema/spec';
15
15
  import '../ILankaFieldError-D5931-vT.js';
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  LankaValidationError
3
- } from "../chunk-CRIRTOLB.js";
3
+ } from "../chunk-VI4DY5PN.js";
4
4
  import {
5
5
  getStringField,
6
6
  isRecord
7
7
  } from "../chunk-J5LA3Q6D.js";
8
- import "../chunk-G32H73QY.js";
8
+ import "../chunk-INHAKVSO.js";
9
9
  import {
10
10
  getLankaProcessRuntime,
11
11
  hasLankaScopeResolver,
@@ -4,7 +4,7 @@ import { L as LankaScenarioVMRegistry } from './LankaScenarioVMRegistry-CFzCpIFd
4
4
  import { b as ILankaRuntimeConfig } from './ILankaRuntimeConfig-Vl436GWK.js';
5
5
  import { I as ILankaInFlightCounter } from './lankaHttpInFlight-Bk1eIuSx.js';
6
6
  import { I as ILankaScenarioVM } from './ILankaScenarioVM-DKwjbIRq.js';
7
- import { T as TLankaRequestMiddleware } from './lankaRequestMiddleware-DAC5kCb7.js';
7
+ import { T as TLankaRequestMiddleware } from './lankaRequestMiddleware-CbXc1PAV.js';
8
8
  import { LankaGatewayLocator } from './locator/gateway/lanka-gateway-locator/LankaGatewayLocator.js';
9
9
  import { LankaScenarioLocator } from './locator/scenario/lanka-scenario-locator/LankaScenarioLocator.js';
10
10
  import { LankaSingletonLocator } from './locator/singleton/lanka-singleton-locator/LankaSingletonLocator.js';
@@ -1,17 +1,17 @@
1
- import { c as ILankaPlugin, e as ILankaServiceConfig, I as ILankaBootstrapConfig, a as ILankaInstance } from '../createLanka-AuiMfPL9.js';
2
- export { b as ILankaInstanceConfig, d as ILankaScenarioBootstrapConfig, f as createLanka } from '../createLanka-AuiMfPL9.js';
1
+ import { c as ILankaPlugin, e as ILankaServiceConfig, I as ILankaBootstrapConfig, a as ILankaInstance } from '../createLanka-XbyOz9ld.js';
2
+ export { b as ILankaInstanceConfig, d as ILankaScenarioBootstrapConfig, f as createLanka } from '../createLanka-XbyOz9ld.js';
3
3
  import { I as ILankaFlags, a as ILankaHost } from '../ILankaRuntimeConfig-Vl436GWK.js';
4
4
  export { I as ILankaScope } from '../createLankaScope-DeElRH-E.js';
5
- import '../activeRuntime-DxB62KN4.js';
5
+ import '../activeRuntime-1Zj2m1Sx.js';
6
6
  import '../ILankaScenario-7J3MoKiY.js';
7
7
  import '../LankaScenariosRegistry-DiLN9xwy.js';
8
8
  import '../ILankaScenarioVM-DKwjbIRq.js';
9
9
  import '../ILankaScenarioMetadata-DgOxvpwx.js';
10
10
  import '../LankaScenarioVMRegistry-CFzCpIFd.js';
11
11
  import '../lankaHttpInFlight-Bk1eIuSx.js';
12
- import '../lankaRequestMiddleware-DAC5kCb7.js';
12
+ import '../lankaRequestMiddleware-CbXc1PAV.js';
13
13
  import '../locator/gateway/lanka-gateway-locator/LankaGatewayLocator.js';
14
- import '../ALankaGateway-CzBISB0L.js';
14
+ import '../ALankaGateway-CQrEPUHM.js';
15
15
  import '../lankaStandardValidator-BUFnysK0.js';
16
16
  import '@standard-schema/spec';
17
17
  import '../ILankaFieldError-D5931-vT.js';
@@ -3,11 +3,11 @@ import {
3
3
  createLanka,
4
4
  resetActiveLanka,
5
5
  startLanka
6
- } from "../chunk-JLBSXJRX.js";
6
+ } from "../chunk-YEP54YU5.js";
7
7
  import "../chunk-M4BK6GBV.js";
8
+ import "../chunk-24MUFFHF.js";
8
9
  import "../chunk-3R2NO47A.js";
9
10
  import "../chunk-BMF4TM2Z.js";
10
- import "../chunk-24MUFFHF.js";
11
11
  import "../chunk-JZJ6GXX3.js";
12
12
  import "../chunk-EH5WZSRJ.js";
13
13
  import "../chunk-N3275IPH.js";
@@ -4,7 +4,7 @@ import {
4
4
  } from "./chunk-J5LA3Q6D.js";
5
5
  import {
6
6
  LankaError
7
- } from "./chunk-G32H73QY.js";
7
+ } from "./chunk-INHAKVSO.js";
8
8
  import {
9
9
  getLankaHost
10
10
  } from "./chunk-JGJBFELR.js";
@@ -49,4 +49,4 @@ export {
49
49
  createLankaApiError,
50
50
  handleLankaApiError
51
51
  };
52
- //# sourceMappingURL=chunk-DKLOCKS4.js.map
52
+ //# sourceMappingURL=chunk-3GQGNG7S.js.map
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  LankaValidationError
3
- } from "./chunk-CRIRTOLB.js";
3
+ } from "./chunk-VI4DY5PN.js";
4
4
 
5
5
  // src/validation/lanka-standard-validator/lankaStandardValidator.ts
6
6
  function readIssuePath(issue) {
@@ -66,4 +66,4 @@ var lankaStandardValidator = Object.freeze({
66
66
  export {
67
67
  lankaStandardValidator
68
68
  };
69
- //# sourceMappingURL=chunk-HVSQOMRE.js.map
69
+ //# sourceMappingURL=chunk-BIJTUWUD.js.map
@@ -14,6 +14,21 @@ var LankaError = class _LankaError extends Error {
14
14
  fields;
15
15
  /** The parsed error response body; core carries it without reading it. */
16
16
  body;
17
+ /**
18
+ * The app went to the background while the attempt was on the wire: the page
19
+ * was seen to hide, or to unload. Set by the framework on the `network` and
20
+ * `aborted` failures it tags; `false` everywhere else.
21
+ *
22
+ * What it tells is WHEN, not why. On a mobile WebView it usually means the
23
+ * page was frozen and the platform cut the request; on a desktop tab that kept
24
+ * running, the server may just as well have failed. Segment telemetry by it —
25
+ * do not drop what it marks. Never on a `timeout`: the deadline stops while
26
+ * the page is hidden, so one that still ran out was slow in plain sight.
27
+ *
28
+ * Read it as truthy: a `LankaError` from an older copy of the framework in
29
+ * the same tree passes `LankaError.is` without it.
30
+ */
31
+ isFromBackground;
17
32
  constructor(init) {
18
33
  super(init.message, init.cause === void 0 ? void 0 : { cause: init.cause });
19
34
  this.name = "LankaError";
@@ -23,6 +38,7 @@ var LankaError = class _LankaError extends Error {
23
38
  this.issues = init.issues;
24
39
  this.fields = init.fields;
25
40
  this.body = init.body;
41
+ this.isFromBackground = init.isFromBackground ?? false;
26
42
  Object.setPrototypeOf(this, _LankaError.prototype);
27
43
  }
28
44
  /** The `ILankaApiError` field. The details are the message list. */
@@ -55,4 +71,4 @@ var LankaError = class _LankaError extends Error {
55
71
  export {
56
72
  LankaError
57
73
  };
58
- //# sourceMappingURL=chunk-G32H73QY.js.map
74
+ //# sourceMappingURL=chunk-INHAKVSO.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/errors/lanka-error/LankaError.ts"],"sourcesContent":["import type { ILankaApiError } from \"../_interfaces/ILankaApiError\";\nimport type { ILankaFieldError } from \"../_interfaces/ILankaFieldError\";\n\n/**\n * How a request ended.\n *\n * Six kinds rather than one, for one reason: each demands something DIFFERENT of\n * the interface. A distinction that implies no different behaviour is\n * superfluous, which is why there is no seventh.\n */\nexport type TLankaErrorKind =\n\t/** Never reached the server: dropped link, DNS failure, no network. Offer a retry. */\n\t| \"network\"\n\t/** Reached it; the response never came. Also a retry, but a different message. */\n\t| \"timeout\"\n\t/** Cancelled by the caller. Nothing to show: the user left. */\n\t| \"aborted\"\n\t/** The server answered with an error status; what to show depends on it. */\n\t| \"http\"\n\t/** A response arrived in the wrong shape. A break, not the user's fault. */\n\t| \"schema\"\n\t/** The server refused deliberately and named the reason. Show what it said. */\n\t| \"domain\";\n\nexport interface ILankaErrorInit {\n\tkind: TLankaErrorKind;\n\tmessage: string;\n\t/** HTTP status, when there was one. */\n\tstatus?: number;\n\t/** The domain failure code — what the application branches on. */\n\tcode?: string;\n\t/** Details: server messages, or paths to the fields that failed validation. */\n\tissues?: readonly string[];\n\t/**\n\t * The failures that have an input to be shown at, with the path in segments.\n\t *\n\t * Beside `issues` rather than instead of it: `issues` is the banner's list and\n\t * is promised; this is the form's, and a failure may have either, both or\n\t * neither. Absent means \"nothing here has an address\", not \"unknown\".\n\t */\n\tfields?: readonly ILankaFieldError[];\n\t/**\n\t * The parsed ERROR response body, when there was one and it was JSON.\n\t *\n\t * Travels with the error because a `Response` is read once: without this field\n\t * a plugin extracting the domain failure code would read an already-drained\n\t * stream and get nothing. Core does not look into the body; it carries it.\n\t */\n\tbody?: unknown;\n\t/** The app went to the background during the attempt. See `LankaError.isFromBackground`. */\n\tisFromBackground?: boolean;\n\t/** The original error, when this one wraps it. */\n\tcause?: unknown;\n}\n\n/**\n * One failure type for every layer of the framework.\n *\n * Without a tagged kind, an app cannot tell a network failure from a timeout,\n * from a broken schema, from a deliberate domain refusal — so it builds its own\n * error contract ON TOP of the framework, and builds it once per application.\n *\n * Implements `ILankaApiError`: `status` and `errors` are present, so code reading\n * them the old way keeps working.\n *\n * What is NOT here: parsing a particular response body format. Which JSON a\n * backend sends is policy, and policy lives in `@lankajs/plugin-http`. Core knows\n * only that it has a failure and must name its kind.\n */\nexport class LankaError extends Error implements ILankaApiError {\n\treadonly kind: TLankaErrorKind;\n\treadonly status?: number;\n\treadonly code?: string;\n\treadonly issues?: readonly string[];\n\t/**\n\t * The failures with an input to be shown at. See `ILankaErrorInit.fields`.\n\t *\n\t * The array given is the array kept — unlike `errors`, which copies `issues`\n\t * on every read. `readonly` carries the promise, and this is read on the way\n\t * to a form, once, where a copy would buy nothing.\n\t */\n\treadonly fields?: readonly ILankaFieldError[];\n\t/** The parsed error response body; core carries it without reading it. */\n\treadonly body?: unknown;\n\t/**\n\t * The app went to the background while the attempt was on the wire: the page\n\t * was seen to hide, or to unload. Set by the framework on the `network` and\n\t * `aborted` failures it tags; `false` everywhere else.\n\t *\n\t * What it tells is WHEN, not why. On a mobile WebView it usually means the\n\t * page was frozen and the platform cut the request; on a desktop tab that kept\n\t * running, the server may just as well have failed. Segment telemetry by it —\n\t * do not drop what it marks. Never on a `timeout`: the deadline stops while\n\t * the page is hidden, so one that still ran out was slow in plain sight.\n\t *\n\t * Read it as truthy: a `LankaError` from an older copy of the framework in\n\t * the same tree passes `LankaError.is` without it.\n\t */\n\treadonly isFromBackground: boolean;\n\n\tconstructor(init: ILankaErrorInit) {\n\t\tsuper(init.message, init.cause === undefined ? undefined : { cause: init.cause });\n\t\tthis.name = \"LankaError\";\n\t\tthis.kind = init.kind;\n\t\tthis.status = init.status;\n\t\tthis.code = init.code;\n\t\tthis.issues = init.issues;\n\t\tthis.fields = init.fields;\n\t\tthis.body = init.body;\n\t\tthis.isFromBackground = init.isFromBackground ?? false;\n\n\t\t// The prototype chain is pinned explicitly: without it `instanceof` breaks\n\t\t// for a consumer whose bundler downlevels to ES5, and breaks silently —\n\t\t// `catch` simply fails to recognise its own error.\n\t\tObject.setPrototypeOf(this, LankaError.prototype);\n\t}\n\n\t/** The `ILankaApiError` field. The details are the message list. */\n\tget errors(): string[] | undefined {\n\t\treturn this.issues ? [...this.issues] : undefined;\n\t}\n\n\t/**\n\t * Whether to show this to the user.\n\t *\n\t * A cancelled request is the one failure that must NOT be reported: its cause\n\t * is that the user left before the response, and a toast would catch them on\n\t * another screen.\n\t */\n\tget isSilent(): boolean {\n\t\treturn this.kind === \"aborted\";\n\t}\n\n\t/**\n\t * Recognises our error among others.\n\t *\n\t * Checks the name rather than `instanceof` alone: a consumer may end up with\n\t * two copies of the package — adjacent majors in the dependency tree — and\n\t * then `instanceof` answers `false` for an error that is ours by every other\n\t * sign.\n\t */\n\tstatic is(value: unknown): value is LankaError {\n\t\treturn (\n\t\t\tvalue instanceof LankaError || (value instanceof Error && value.name === \"LankaError\")\n\t\t);\n\t}\n}\n"],"mappings":";AAqEO,IAAM,aAAN,MAAM,oBAAmB,MAAgC;AAAA,EACtD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA;AAAA;AAAA,EAEA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAeA;AAAA,EAET,YAAY,MAAuB;AAClC,UAAM,KAAK,SAAS,KAAK,UAAU,SAAY,SAAY,EAAE,OAAO,KAAK,MAAM,CAAC;AAChF,SAAK,OAAO;AACZ,SAAK,OAAO,KAAK;AACjB,SAAK,SAAS,KAAK;AACnB,SAAK,OAAO,KAAK;AACjB,SAAK,SAAS,KAAK;AACnB,SAAK,SAAS,KAAK;AACnB,SAAK,OAAO,KAAK;AACjB,SAAK,mBAAmB,KAAK,oBAAoB;AAKjD,WAAO,eAAe,MAAM,YAAW,SAAS;AAAA,EACjD;AAAA;AAAA,EAGA,IAAI,SAA+B;AAClC,WAAO,KAAK,SAAS,CAAC,GAAG,KAAK,MAAM,IAAI;AAAA,EACzC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,IAAI,WAAoB;AACvB,WAAO,KAAK,SAAS;AAAA,EACtB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,OAAO,GAAG,OAAqC;AAC9C,WACC,iBAAiB,eAAe,iBAAiB,SAAS,MAAM,SAAS;AAAA,EAE3E;AACD;","names":[]}
@@ -10,4 +10,4 @@ function composeLankaRequestMiddleware(middleware, perform) {
10
10
  export {
11
11
  composeLankaRequestMiddleware
12
12
  };
13
- //# sourceMappingURL=chunk-YR4MZXMU.js.map
13
+ //# sourceMappingURL=chunk-USZ7CFCU.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/gateway/request/lankaRequestMiddleware.ts"],"sourcesContent":["/**\n * What middleware knows about the request it wraps.\n *\n * `options` is deliberately `unknown`: every transport has its own —\n * `RequestInit` for fetch, something else for the next one. Core does not read\n * them, it passes them along.\n */\nexport interface ILankaRequestContext {\n\treadonly endpoint: string;\n\treadonly options: unknown;\n\t/**\n\t * Which attempt this is, counting from one.\n\t *\n\t * In the context rather than in the middleware itself, because a retry may be\n\t * started by someone other than the one counting: an auth refresh restarts the\n\t * request, and the retrying middleware must not mistake that for its own\n\t * second attempt.\n\t */\n\treadonly attempt: number;\n\t/**\n\t * This attempt's deadline, when middleware assigned one. It stops while the\n\t * page is seen hidden — a frozen WebView runs no timers — and resumes when it\n\t * shows.\n\t *\n\t * Read by CORE before every call into the transport, which is what allows a\n\t * deadline per request class: a file upload and a list read cannot share one\n\t * value, and the policy knows that difference while the framework does not.\n\t */\n\treadonly timeoutMs?: number;\n}\n\n/**\n * A wrapper around a request.\n *\n * ## A wrapper rather than `onRequest` / `onResponse` / `onError`\n *\n * Three hooks cannot express RETRY. `onError` can replace an error but cannot\n * run the request again — and retry plus auth refresh are the two main abilities\n * a request-policy plugin exists for. A wrapper expresses those and everything\n * the hooks expressed.\n *\n * ## Why the objection to `next()` does not carry over\n *\n * On the event bus, middleware that skips `next` SILENCES the event: subscribers\n * do not run and nothing records it. Here, skipping `next` means returning a\n * value instead of a request — and the caller receives that value, so the\n * decision is visible.\n *\n * ## Order\n *\n * Registered first wraps all the rest: it sees the request before everyone and\n * the response after everyone — ordinary layer semantics, where \"outer\" means\n * outer.\n */\nexport type TLankaRequestMiddleware = (\n\tctx: ILankaRequestContext,\n\tnext: (ctx: ILankaRequestContext) => Promise<unknown>,\n) => Promise<unknown>;\n\n/**\n * Folds the chain into one function.\n *\n * An empty chain returns `perform` as-is, with no wrappers and no cost: an app\n * without a request-policy plugin has no middleware at all and must not pay for\n * their absence.\n */\nexport function composeLankaRequestMiddleware(\n\tmiddleware: readonly TLankaRequestMiddleware[],\n\tperform: (ctx: ILankaRequestContext) => Promise<unknown>,\n): (ctx: ILankaRequestContext) => Promise<unknown> {\n\tif (middleware.length === 0) return perform;\n\n\treturn middleware.reduceRight<(ctx: ILankaRequestContext) => Promise<unknown>>(\n\t\t(next, current) => (ctx) => current(ctx, next),\n\t\tperform,\n\t);\n}\n"],"mappings":";AAkEO,SAAS,8BACf,YACA,SACkD;AAClD,MAAI,WAAW,WAAW,EAAG,QAAO;AAEpC,SAAO,WAAW;AAAA,IACjB,CAAC,MAAM,YAAY,CAAC,QAAQ,QAAQ,KAAK,IAAI;AAAA,IAC7C;AAAA,EACD;AACD;","names":[]}
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  LankaError
3
- } from "./chunk-G32H73QY.js";
3
+ } from "./chunk-INHAKVSO.js";
4
4
 
5
5
  // src/validation/lanka-validation-error/LankaValidationError.ts
6
6
  var LankaValidationError = class _LankaValidationError extends LankaError {
@@ -24,4 +24,4 @@ var LankaValidationError = class _LankaValidationError extends LankaError {
24
24
  export {
25
25
  LankaValidationError
26
26
  };
27
- //# sourceMappingURL=chunk-CRIRTOLB.js.map
27
+ //# sourceMappingURL=chunk-VI4DY5PN.js.map
@@ -1,15 +1,15 @@
1
1
  import {
2
2
  createLankaScope
3
3
  } from "./chunk-M4BK6GBV.js";
4
+ import {
5
+ LankaSingletonLocator
6
+ } from "./chunk-24MUFFHF.js";
4
7
  import {
5
8
  LankaSharedStoreLocator
6
9
  } from "./chunk-3R2NO47A.js";
7
10
  import {
8
11
  LankaGatewayLocator
9
12
  } from "./chunk-BMF4TM2Z.js";
10
- import {
11
- LankaSingletonLocator
12
- } from "./chunk-24MUFFHF.js";
13
13
  import {
14
14
  LankaScenarioLocator
15
15
  } from "./chunk-EH5WZSRJ.js";
@@ -735,4 +735,4 @@ export {
735
735
  resetActiveLanka,
736
736
  ALankaPlugin
737
737
  };
738
- //# sourceMappingURL=chunk-JLBSXJRX.js.map
738
+ //# sourceMappingURL=chunk-YEP54YU5.js.map
@@ -1,7 +1,7 @@
1
1
  import { I as ILankaScope } from './createLankaScope-DeElRH-E.js';
2
- import { I as ILankaRuntime } from './activeRuntime-DxB62KN4.js';
2
+ import { I as ILankaRuntime } from './activeRuntime-1Zj2m1Sx.js';
3
3
  import { a as ILankaHost, I as ILankaFlags } from './ILankaRuntimeConfig-Vl436GWK.js';
4
- import { T as TLankaRequestMiddleware } from './lankaRequestMiddleware-DAC5kCb7.js';
4
+ import { T as TLankaRequestMiddleware } from './lankaRequestMiddleware-CbXc1PAV.js';
5
5
 
6
6
  /**
7
7
  * A plugin is an extension core knows by SHAPE rather than by name.
@@ -1,5 +1,5 @@
1
- import { L as LankaError } from '../LankaError-D6RWNyLM.js';
2
- export { a as ILankaApiError, I as ILankaErrorInit, T as TLankaErrorKind } from '../LankaError-D6RWNyLM.js';
1
+ import { L as LankaError } from '../LankaError-CfDmuGKc.js';
2
+ export { a as ILankaApiError, I as ILankaErrorInit, T as TLankaErrorKind } from '../LankaError-CfDmuGKc.js';
3
3
  import { I as ILankaFieldError } from '../ILankaFieldError-D5931-vT.js';
4
4
  export { T as TLankaErrorHandler } from '../TLankaErrorHandler-Yfqtdh1M.js';
5
5
 
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  createLankaApiError,
3
3
  handleLankaApiError
4
- } from "../chunk-DKLOCKS4.js";
4
+ } from "../chunk-3GQGNG7S.js";
5
5
  import "../chunk-J5LA3Q6D.js";
6
6
  import {
7
7
  LankaError
8
- } from "../chunk-G32H73QY.js";
8
+ } from "../chunk-INHAKVSO.js";
9
9
  import "../chunk-JGJBFELR.js";
10
10
  import "../chunk-XTVEHYIZ.js";
11
11
 
@@ -1,9 +1,9 @@
1
- import { T as TLankaExecuteOptions, I as IALankaGatewayConfig, a as TLankaRequestInit, b as ILankaRequest, c as TLankaQueryBuilder } from '../ALankaGateway-CzBISB0L.js';
2
- export { A as ALankaGateway, d as TLankaQueryParams } from '../ALankaGateway-CzBISB0L.js';
1
+ import { T as TLankaExecuteOptions, I as IALankaGatewayConfig, a as TLankaRequestInit, b as ILankaRequest, c as TLankaQueryBuilder } from '../ALankaGateway-CQrEPUHM.js';
2
+ export { A as ALankaGateway, d as TLankaQueryParams } from '../ALankaGateway-CQrEPUHM.js';
3
3
  import { I as ILankaValidator } from '../lankaStandardValidator-BUFnysK0.js';
4
4
  import { T as TLankaErrorHandler } from '../TLankaErrorHandler-Yfqtdh1M.js';
5
5
  export { I as ILankaInFlightCounter, l as lankaHttpInFlight } from '../lankaHttpInFlight-Bk1eIuSx.js';
6
- export { I as ILankaRequestContext, T as TLankaRequestMiddleware } from '../lankaRequestMiddleware-DAC5kCb7.js';
6
+ export { I as ILankaRequestContext, T as TLankaRequestMiddleware } from '../lankaRequestMiddleware-CbXc1PAV.js';
7
7
  import '@standard-schema/spec';
8
8
  import '../ILankaFieldError-D5931-vT.js';
9
9
 
@@ -1,20 +1,20 @@
1
1
  import {
2
2
  lankaStandardValidator
3
- } from "../chunk-HVSQOMRE.js";
4
- import "../chunk-CRIRTOLB.js";
3
+ } from "../chunk-BIJTUWUD.js";
5
4
  import {
6
5
  composeLankaRequestMiddleware
7
- } from "../chunk-YR4MZXMU.js";
6
+ } from "../chunk-USZ7CFCU.js";
7
+ import "../chunk-VI4DY5PN.js";
8
8
  import {
9
9
  lankaHttpInFlight
10
10
  } from "../chunk-NMFNEVNE.js";
11
11
  import {
12
12
  handleLankaApiError
13
- } from "../chunk-DKLOCKS4.js";
13
+ } from "../chunk-3GQGNG7S.js";
14
14
  import "../chunk-J5LA3Q6D.js";
15
15
  import {
16
16
  LankaError
17
- } from "../chunk-G32H73QY.js";
17
+ } from "../chunk-INHAKVSO.js";
18
18
  import {
19
19
  getLankaHost
20
20
  } from "../chunk-JGJBFELR.js";
@@ -28,24 +28,119 @@ import {
28
28
  getActiveRuntime
29
29
  } from "../chunk-XTVEHYIZ.js";
30
30
 
31
+ // src/gateway/request/_internal/create-request-lifetime/createRequestLifetime.ts
32
+ var NO_LIFETIME = Object.freeze({
33
+ signal: void 0,
34
+ timedOut: () => false,
35
+ wasHidden: () => false,
36
+ dispose: () => void 0
37
+ });
38
+ var isPageHidden = () => typeof document !== "undefined" && document.visibilityState === "hidden";
39
+ function createVisibleDeadline(timeoutMs, onExpire) {
40
+ let remainingMs = timeoutMs;
41
+ let startedAt = 0;
42
+ let timer;
43
+ let cleared = false;
44
+ const pause = () => {
45
+ if (timer === void 0) return;
46
+ clearTimeout(timer);
47
+ timer = void 0;
48
+ remainingMs = Math.max(0, remainingMs - (Date.now() - startedAt));
49
+ };
50
+ const resume = () => {
51
+ if (timer !== void 0 || cleared) return;
52
+ startedAt = Date.now();
53
+ timer = setTimeout(() => {
54
+ cleared = true;
55
+ onExpire();
56
+ }, remainingMs);
57
+ };
58
+ const clear = () => {
59
+ cleared = true;
60
+ if (timer !== void 0) clearTimeout(timer);
61
+ timer = void 0;
62
+ };
63
+ resume();
64
+ return { pause, resume, clear };
65
+ }
66
+ function watchPage(deadline, onHide) {
67
+ if (typeof document === "undefined" || typeof window === "undefined") return () => void 0;
68
+ const onVisibility = () => {
69
+ if (isPageHidden()) {
70
+ onHide();
71
+ deadline?.pause();
72
+ } else deadline?.resume();
73
+ };
74
+ const onPageHide = () => {
75
+ onHide();
76
+ deadline?.pause();
77
+ };
78
+ const onPageShow = () => {
79
+ if (!isPageHidden()) deadline?.resume();
80
+ };
81
+ document.addEventListener("visibilitychange", onVisibility);
82
+ window.addEventListener("pagehide", onPageHide);
83
+ window.addEventListener("pageshow", onPageShow);
84
+ return () => {
85
+ document.removeEventListener("visibilitychange", onVisibility);
86
+ window.removeEventListener("pagehide", onPageHide);
87
+ window.removeEventListener("pageshow", onPageShow);
88
+ };
89
+ }
90
+ function createRequestLifetime(external, timeoutMs) {
91
+ const followsPage = typeof document !== "undefined";
92
+ if (!external && !timeoutMs && !followsPage) return NO_LIFETIME;
93
+ const controller = external || timeoutMs ? new AbortController() : void 0;
94
+ let expired = false;
95
+ let hidden = false;
96
+ const deadline = controller && timeoutMs !== void 0 ? createVisibleDeadline(timeoutMs, () => {
97
+ expired = true;
98
+ controller.abort(new DOMException("Request timed out", "TimeoutError"));
99
+ }) : void 0;
100
+ const unwatch = watchPage(deadline, () => {
101
+ hidden = true;
102
+ });
103
+ const onExternalAbort = () => {
104
+ controller?.abort(external?.reason);
105
+ };
106
+ if (external) {
107
+ if (external.aborted) onExternalAbort();
108
+ else external.addEventListener("abort", onExternalAbort, { once: true });
109
+ }
110
+ return {
111
+ signal: controller?.signal,
112
+ timedOut: () => expired,
113
+ wasHidden: () => hidden,
114
+ dispose: () => {
115
+ deadline?.clear();
116
+ unwatch();
117
+ external?.removeEventListener("abort", onExternalAbort);
118
+ }
119
+ };
120
+ }
121
+
31
122
  // src/gateway/request/_abstractions/lanka-request/ALankaRequest.ts
32
- function classifyTransportError(error, timedOut) {
123
+ var NO_OUTCOME = Object.freeze({ timedOut: false, hidden: false });
124
+ function tagInterruption(error, name, attempt) {
125
+ const timedOutHere = attempt.timedOut || name === "TimeoutError";
126
+ return new LankaError({
127
+ kind: timedOutHere ? "timeout" : "aborted",
128
+ message: timedOutHere ? getLankaHost().timeoutErrorMessage() : readErrorMessage(error),
129
+ isFromBackground: !timedOutHere && attempt.hidden,
130
+ cause: error
131
+ });
132
+ }
133
+ function classifyTransportError(error, attempt) {
33
134
  if (LankaError.is(error)) return error;
34
135
  const name = readErrorName(error);
35
- const isAbort = name === "AbortError" || name === "TimeoutError";
36
- if (isAbort) {
37
- const timedOutHere = timedOut || name === "TimeoutError";
38
- return new LankaError({
39
- kind: timedOutHere ? "timeout" : "aborted",
40
- message: timedOutHere ? getLankaHost().timeoutErrorMessage() : readErrorMessage(error),
41
- cause: error
42
- });
43
- }
136
+ if (name === "AbortError" || name === "TimeoutError")
137
+ return tagInterruption(error, name, attempt);
44
138
  if (error instanceof TypeError) {
45
139
  return new LankaError({
46
140
  kind: "network",
47
141
  message: getLankaHost().networkErrorMessage(),
48
142
  issues: [error.message],
143
+ isFromBackground: attempt.hidden,
49
144
  cause: error
50
145
  });
51
146
  }
@@ -83,7 +178,7 @@ var ALankaRequest = class {
83
178
  const { signal, timeoutMs, ...rest } = options ?? {};
84
179
  const fallbackDeadline = runtime?.requestTimeoutMs;
85
180
  const passedOptions = options === void 0 ? void 0 : rest;
86
- let lastTimedOut = false;
181
+ let lastAttempt = NO_OUTCOME;
87
182
  const perform = async (ctx) => {
88
183
  const lifetime = createRequestLifetime(signal, ctx.timeoutMs ?? fallbackDeadline);
89
184
  try {
@@ -93,8 +188,8 @@ var ALankaRequest = class {
93
188
  mockHandler
94
189
  );
95
190
  } catch (error) {
96
- lastTimedOut = lifetime.timedOut();
97
- throw classifyTransportError(error, lastTimedOut);
191
+ lastAttempt = { timedOut: lifetime.timedOut(), hidden: lifetime.wasHidden() };
192
+ throw classifyTransportError(error, lastAttempt);
98
193
  } finally {
99
194
  lifetime.dispose();
100
195
  }
@@ -109,38 +204,12 @@ var ALankaRequest = class {
109
204
  timeoutMs
110
205
  });
111
206
  } catch (error) {
112
- throw classifyTransportError(error, lastTimedOut);
207
+ throw classifyTransportError(error, lastAttempt);
113
208
  } finally {
114
209
  lankaHttpInFlight.end();
115
210
  }
116
211
  }
117
212
  };
118
- function createRequestLifetime(external, timeoutMs) {
119
- if (!external && !timeoutMs) {
120
- return { signal: void 0, timedOut: () => false, dispose: () => void 0 };
121
- }
122
- const controller = new AbortController();
123
- let expired = false;
124
- const timer = timeoutMs === void 0 ? void 0 : setTimeout(() => {
125
- expired = true;
126
- controller.abort(new DOMException("Request timed out", "TimeoutError"));
127
- }, timeoutMs);
128
- const onExternalAbort = () => {
129
- controller.abort(external?.reason);
130
- };
131
- if (external) {
132
- if (external.aborted) onExternalAbort();
133
- else external.addEventListener("abort", onExternalAbort, { once: true });
134
- }
135
- return {
136
- signal: controller.signal,
137
- timedOut: () => expired,
138
- dispose: () => {
139
- if (timer !== void 0) clearTimeout(timer);
140
- external?.removeEventListener("abort", onExternalAbort);
141
- }
142
- };
143
- }
144
213
  function withSignal(options, signal) {
145
214
  if (signal === void 0) return options;
146
215
  return { ...options ?? {}, signal };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/gateway/request/_abstractions/lanka-request/ALankaRequest.ts","../../src/gateway/request/_abstractions/lanka-transport-request/ALankaTransportRequest.ts","../../src/gateway/lanka-fetch-transport/LankaFetchTransport.ts","../../src/gateway/request/lanka-fetch-json-request/LankaFetchJsonRequest.ts","../../src/gateway/_utils/build-lanka-query-params/buildLankaQueryParams.ts","../../src/gateway/_abstractions/lanka-gateway/ALankaGateway.ts","../../src/gateway/_factories/create-lanka-gateway/createLankaGateway.ts","../../src/gateway/request/lanka-fetch-request/LankaFetchRequest.ts","../../src/gateway/request/_factories/create-lanka-fetch-request/createLankaFetchRequest.ts","../../src/gateway/request/_factories/create-lanka-fetch-json-request/createLankaFetchJsonRequest.ts"],"sourcesContent":["import type { TLankaRequestInit } from \"../../../_types/TLankaRequestInit\";\nimport type { TLankaErrorHandler } from \"../../../../errors/_types/TLankaErrorHandler\";\nimport type { ILankaRequest } from \"../../../_interfaces/ILankaRequest\";\nimport type { TLankaExecuteOptions } from \"../../../_types/TLankaExecuteOptions\";\nimport { handleLankaApiError } from \"../../../../errors/handle-lanka-api-error/handleLankaApiError\";\nimport { getLankaFlags } from \"../../../../config/get-lanka-flags/getLankaFlags\";\nimport { getLankaHost } from \"../../../../config/get-lanka-host/getLankaHost\";\nimport { lankaHttpInFlight } from \"../../../inflight/lankaHttpInFlight\";\nimport { LankaError } from \"../../../../errors/lanka-error/LankaError\";\nimport { getActiveRuntime } from \"../../../../_internal/active-runtime/activeRuntime\";\nimport { composeLankaRequestMiddleware } from \"../../lankaRequestMiddleware\";\nimport type { ILankaRequestContext } from \"../../lankaRequestMiddleware\";\n\n/**\n * Tags whatever the transport threw with a kind.\n *\n * Here rather than in the transports: `execute` is the single point EVERY\n * request passes through, and tagging in each of the four transports would be\n * four places to forget it.\n *\n * A real `fetch` throws `TypeError` on a broken connection and a `DOMException`\n * named `AbortError` on cancellation; it does not throw on a status code at all.\n *\n * An already-tagged error is NOT re-tagged: a request-policy plugin may report\n * `domain`, and rewriting that to `network` would lose the one thing the kind\n * exists for.\n */\nfunction classifyTransportError(error: unknown, timedOut: boolean): LankaError {\n\tif (LankaError.is(error)) return error;\n\n\t// The name is read off ANYTHING, not only off `Error`.\n\t//\n\t// `DOMException` — how `fetch` reports cancellation — does not extend `Error`\n\t// everywhere: in a browser yes, in jsdom no. An `instanceof Error` check lets\n\t// cancellation past the tagging, and a raw `AbortError` reaches the app with\n\t// neither `kind` nor `status`: retry policy reads it as non-retryable and the\n\t// app as an unknown error, so a cancelled request is shown to the user as a\n\t// failure.\n\tconst name = readErrorName(error);\n\tconst isAbort = name === \"AbortError\" || name === \"TimeoutError\";\n\tif (isAbort) {\n\t\t// Only whoever assembled the lifetime knows who aborted: `AbortSignal` has\n\t\t// one `abort` for everyone. The distinction carries a decision — a timeout\n\t\t// is shown, a cancellation is not.\n\t\tconst timedOutHere = timedOut || name === \"TimeoutError\";\n\t\treturn new LankaError({\n\t\t\tkind: timedOutHere ? \"timeout\" : \"aborted\",\n\t\t\tmessage: timedOutHere ? getLankaHost().timeoutErrorMessage() : readErrorMessage(error),\n\t\t\tcause: error,\n\t\t});\n\t}\n\n\t// `network` ONLY for what looks like a transport failure. A real `fetch`\n\t// throws `TypeError`; everything else comes from code we did not write — the\n\t// app's error handler, a response transformer, a broken plugin — and calling\n\t// that a network failure would invite the user to retry a request that\n\t// arrived and was processed.\n\t//\n\t// Unknown stays unknown and passes through. The framework asserts only what\n\t// it knows.\n\tif (error instanceof TypeError) {\n\t\treturn new LankaError({\n\t\t\tkind: \"network\",\n\t\t\tmessage: getLankaHost().networkErrorMessage(),\n\t\t\tissues: [error.message],\n\t\t\tcause: error,\n\t\t});\n\t}\n\n\treturn error as LankaError;\n}\n\n/** The error name, off `Error`, `DOMException` or anything else carrying one. */\nfunction readErrorName(error: unknown): string | undefined {\n\tif (typeof error !== \"object\" || error === null) return undefined;\n\tconst name: unknown = (error as { name?: unknown }).name;\n\treturn typeof name === \"string\" ? name : undefined;\n}\n\n/**\n * The error text, when there is one.\n *\n * An object without `message` is not stringified: `String({})` yields\n * `[object Object]`, which occupies the message slot and says nothing. Empty is\n * more honest.\n */\nfunction readErrorMessage(error: unknown): string {\n\tif (typeof error === \"string\") return error;\n\tif (typeof error !== \"object\" || error === null) return \"\";\n\tconst message: unknown = (error as { message?: unknown }).message;\n\treturn typeof message === \"string\" ? message : \"\";\n}\n\n/**\n * How a gateway request goes on the wire.\n *\n * A subclass declares one method, `request()`, and does only its own work there:\n * `LankaFetchJsonRequest` returns parsed JSON, `LankaFetchRequest` returns the\n * whole response, a custom kind returns whatever it likes.\n *\n * Overriding `request()` customises the request flow, failure handling, mock\n * substitution, response transformation and log interception.\n */\nexport abstract class ALankaRequest<\n\tTOptions = TLankaRequestInit,\n> implements ILankaRequest<TOptions> {\n\tprotected readonly errorHandler?: TLankaErrorHandler;\n\tprotected readonly useMock: boolean;\n\n\tprotected constructor(config: { errorHandler?: TLankaErrorHandler; useMock?: boolean }) {\n\t\tconst flags = getLankaFlags();\n\n\t\t// The default error-body handler lives HERE because the request is the only\n\t\t// thing that sees the `Response`. Put on the gateway it would sit in a field\n\t\t// nobody reads — the request takes the handler from ITS OWN config — and a\n\t\t// consumer passing `errorHandler` to the gateway would get silence.\n\t\t//\n\t\t// The parse is cheap: core reads the body once and takes `message` from it;\n\t\t// backend-specific shapes are parsed by `@lankajs/plugin-http`.\n\t\tthis.errorHandler = config.errorHandler ?? handleLankaApiError;\n\n\t\tthis.useMock = config.useMock ?? flags.isMockMode ?? false;\n\t}\n\n\t/**\n\t * Performs the request and returns its result — a response, JSON or a custom\n\t * type.\n\t *\n\t * @param endpoint Full URL\n\t * @param options Transport-specific options\n\t * @param mockHandler Mock, when there is one\n\t */\n\tprotected abstract request<TReturn = Response>(\n\t\tendpoint: string,\n\t\toptions?: TOptions,\n\t\tmockHandler?: () => Promise<TReturn>,\n\t): Promise<TReturn>;\n\n\t/**\n\t * The single point EVERY gateway request passes through.\n\t *\n\t * Hence the in-flight accounting here: intent prefetch stands down while\n\t * anything else is on the wire. The `finally` matters more than the increment —\n\t * a rejected request that never decremented would disable prefetching for the\n\t * rest of the session.\n\t */\n\tpublic async execute<TReturn = Response>(\n\t\tendpoint: string,\n\t\toptions?: TLankaExecuteOptions<TOptions>,\n\t\tmockHandler?: () => Promise<TReturn>,\n\t): Promise<TReturn> {\n\t\tconst runtime = getActiveRuntime();\n\t\tconst { signal, timeoutMs, ...rest } = (options ?? {}) as TLankaExecuteOptions<TOptions>;\n\t\t// The caller's deadline travels IN THE CONTEXT, not only in the closure:\n\t\t// otherwise a policy assigning deadlines per request class could not tell\n\t\t// \"no deadline given\" from \"given by the caller\" and would override an\n\t\t// explicit request with a blanket default.\n\t\tconst fallbackDeadline = runtime?.requestTimeoutMs;\n\n\t\t// No options passed means none are produced. Destructuring yields `{}` even\n\t\t// from `undefined`, and handing that empty object to the transport would\n\t\t// change the request: \"no options\" and \"empty options\" are different\n\t\t// statements, and the transport is entitled to tell them apart.\n\t\tconst passedOptions: unknown = options === undefined ? undefined : rest;\n\n\t\t/*\n\t\t * The lifetime is assembled PER ATTEMPT, not per call, and that does two\n\t\t * things at once.\n\t\t *\n\t\t * Under retry a shared deadline would start the third attempt with whatever\n\t\t * the first two left, so the retry aborts before reaching the server.\n\t\t *\n\t\t * And it is the only way to let middleware set the deadline: `ctx.timeoutMs`\n\t\t * is read on every attempt, which is how a request-policy plugin assigns a\n\t\t * deadline per request CLASS — a file upload and a list read cannot share\n\t\t * one value.\n\t\t *\n\t\t * Caller cancellation stays end-to-end: one `signal` for all attempts.\n\t\t */\n\t\tlet lastTimedOut = false;\n\n\t\t// Tagging happens INSIDE, around the request itself, not in the outer\n\t\t// catch: middleware must receive an already-tagged error, or a retrying\n\t\t// middleware cannot tell a network failure from a domain rejection and\n\t\t// retries what must not be retried. The outer catch stays as a backstop.\n\t\tconst perform = async (ctx: ILankaRequestContext): Promise<unknown> => {\n\t\t\tconst lifetime = createRequestLifetime(signal, ctx.timeoutMs ?? fallbackDeadline);\n\t\t\ttry {\n\t\t\t\treturn await this.request<TReturn>(\n\t\t\t\t\tctx.endpoint,\n\t\t\t\t\twithSignal(ctx.options, lifetime.signal) as TOptions,\n\t\t\t\t\tmockHandler,\n\t\t\t\t);\n\t\t\t} catch (error) {\n\t\t\t\tlastTimedOut = lifetime.timedOut();\n\t\t\t\tthrow classifyTransportError(error, lastTimedOut);\n\t\t\t} finally {\n\t\t\t\tlifetime.dispose();\n\t\t\t}\n\t\t};\n\n\t\tconst run = composeLankaRequestMiddleware(runtime?.requestMiddleware ?? [], perform);\n\n\t\tlankaHttpInFlight.begin();\n\t\ttry {\n\t\t\t// The chain runs INSIDE the same guard as the request. A catch placed\n\t\t\t// outside would leave a permanent +1 when a plugin throws, disabling\n\t\t\t// prefetch for the rest of the session — the very defect this `finally`\n\t\t\t// exists to prevent.\n\t\t\treturn (await run({\n\t\t\t\tendpoint,\n\t\t\t\toptions: passedOptions,\n\t\t\t\tattempt: 1,\n\t\t\t\ttimeoutMs,\n\t\t\t})) as TReturn;\n\t\t} catch (error) {\n\t\t\tthrow classifyTransportError(error, lastTimedOut);\n\t\t} finally {\n\t\t\tlankaHttpInFlight.end();\n\t\t}\n\t}\n}\n\ninterface IRequestLifetime {\n\treadonly signal: AbortSignal | undefined;\n\t/** Whether OUR timer aborted the request rather than the caller. */\n\ttimedOut(): boolean;\n\tdispose(): void;\n}\n\n/**\n * Combines the caller's signal and our own timeout into one request lifetime.\n *\n * The outcome looks the same — an interrupted request — but the decisions\n * differ: a timeout is shown and offered for retry, a user cancellation is not\n * shown at all. `AbortSignal` does not distinguish them: one `abort`, whose\n * reason belongs to whoever got there first. Hence the private flag.\n *\n * Not `AbortSignal.timeout` alone: it cannot combine with a foreign signal\n * without `AbortSignal.any`, which older engines lack. Assembling by hand works\n * everywhere and costs one listener.\n */\nfunction createRequestLifetime(\n\texternal: AbortSignal | undefined,\n\ttimeoutMs: number | undefined,\n): IRequestLifetime {\n\tif (!external && !timeoutMs) {\n\t\treturn { signal: undefined, timedOut: () => false, dispose: () => undefined };\n\t}\n\n\tconst controller = new AbortController();\n\tlet expired = false;\n\n\tconst timer =\n\t\ttimeoutMs === undefined\n\t\t\t? undefined\n\t\t\t: setTimeout(() => {\n\t\t\t\t\texpired = true;\n\t\t\t\t\tcontroller.abort(new DOMException(\"Request timed out\", \"TimeoutError\"));\n\t\t\t\t}, timeoutMs);\n\n\tconst onExternalAbort = (): void => {\n\t\tcontroller.abort(external?.reason);\n\t};\n\n\tif (external) {\n\t\tif (external.aborted) onExternalAbort();\n\t\telse external.addEventListener(\"abort\", onExternalAbort, { once: true });\n\t}\n\n\treturn {\n\t\tsignal: controller.signal,\n\t\ttimedOut: () => expired,\n\t\tdispose: () => {\n\t\t\tif (timer !== undefined) clearTimeout(timer);\n\t\t\texternal?.removeEventListener(\"abort\", onExternalAbort);\n\t\t},\n\t};\n}\n\n/**\n * Attaches the signal to the options, inventing nothing.\n *\n * With no options and no signal the transport receives `undefined` — exactly\n * what the caller passed. An empty object instead looks harmless but is a\n * different statement, and the transport is entitled to tell them apart.\n */\nfunction withSignal(options: unknown, signal: AbortSignal | undefined): unknown {\n\tif (signal === undefined) return options;\n\treturn { ...(options ?? {}), signal };\n}\n","import { ALankaRequest } from \"../lanka-request/ALankaRequest\";\nimport { LankaError } from \"../../../../errors/lanka-error/LankaError\";\nimport { getLankaFlags } from \"../../../../config/get-lanka-flags/getLankaFlags\";\nimport { getLankaHost } from \"../../../../config/get-lanka-host/getLankaHost\";\nimport type { ILankaTransport } from \"../../../_interfaces/ILankaTransport\";\nimport type { TLankaRequestInit } from \"../../../_types/TLankaRequestInit\";\nimport type { TLankaErrorHandler } from \"../../../../errors/_types/TLankaErrorHandler\";\n\nexport interface ILankaTransportRequestConfig<TOptions> {\n\ttransport?: ILankaTransport<TOptions>;\n\terrorHandler?: TLankaErrorHandler;\n\tuseMock?: boolean;\n}\n\n/**\n * The shape every fetch-backed request has: mock, send, check, parse.\n *\n * The concrete requests differ in ONE place — how they turn a successful\n * `Response` into a value — so a third kind is a subclass with one method rather\n * than a third copy of the sequence.\n *\n * The default transport stays a constructor PARAMETER even though both shipped\n * kinds pass the same one. It is the seam a request kind that is not fetch-backed\n * comes through: this template is the mock/send/check/parse sequence, and nothing\n * in it is about HTTP. Defaulting the parameter here would fix `TOptions` to\n * fetch options for everyone who reuses the sequence.\n */\nexport abstract class ALankaTransportRequest<\n\tTOptions = TLankaRequestInit,\n> extends ALankaRequest<TOptions> {\n\tprotected readonly transport: ILankaTransport<TOptions>;\n\n\tprotected constructor(\n\t\tconfig: ILankaTransportRequestConfig<TOptions>,\n\t\tcreateDefaultTransport: () => ILankaTransport<TOptions>,\n\t) {\n\t\tconst flags = getLankaFlags();\n\n\t\tsuper({\n\t\t\terrorHandler: config.errorHandler,\n\t\t\tuseMock: config.useMock ?? flags.isMockMode ?? false,\n\t\t});\n\n\t\tthis.transport = config.transport ?? createDefaultTransport();\n\t}\n\n\tprotected async request<TReturn>(\n\t\tendpoint: string,\n\t\toptions?: TOptions,\n\t\tmockHandler?: () => Promise<TReturn>,\n\t): Promise<TReturn> {\n\t\tif (this.useMock && mockHandler) {\n\t\t\treturn await mockHandler();\n\t\t}\n\n\t\tconst response = await this.transport.request(endpoint, options);\n\t\tif (!response.ok) return await this.refuse(response);\n\n\t\treturn await this.parse<TReturn>(response);\n\t}\n\n\t/**\n\t * Turns a successful response into the value the caller asked for.\n\t *\n\t * The one step that genuinely differs between request kinds.\n\t */\n\tprotected abstract parse<TReturn>(response: Response): Promise<TReturn>;\n\n\t/**\n\t * Refuses an unsuccessful response, and never returns.\n\t *\n\t * `TLankaErrorHandler` is typed `Promise<never>` — a handler must throw. It is\n\t * still CALLED and then followed by a throw, because a handler that breaks its\n\t * contract and returns would otherwise hand `undefined` back as if the request\n\t * had succeeded, and a non-value must never become a value.\n\t */\n\tprotected async refuse(response: Response): Promise<never> {\n\t\tif (this.errorHandler) {\n\t\t\tawait this.errorHandler(response);\n\t\t}\n\n\t\t// Kind `http`, not a bare Error: the server answered, and answered with a\n\t\t// code. Without the kind this reads as a network failure, and the user is\n\t\t// offered a retry of a request that already got a meaningful answer.\n\t\tthrow new LankaError({\n\t\t\tkind: \"http\",\n\t\t\tmessage: getLankaHost().httpErrorMessage(response.status),\n\t\t\tstatus: response.status,\n\t\t});\n\t}\n}\n","import type { ILankaTransport } from \"../_interfaces/ILankaTransport\";\nimport type { TLankaRequestInit } from \"../_types/TLankaRequestInit\";\n\n/** What an unencoded body is sent as, and the header that says so. */\nconst CONTENT_TYPE = \"content-type\";\nconst JSON_CONTENT_TYPE = \"application/json\";\n\n/**\n * The network seam: `fetch`, plus the two things `fetch` cannot be told.\n *\n * ## Why there is ONE of these\n *\n * There were three — a plain one, a JSON one and a multipart one — and the split\n * was wrong at birth. `ILankaTransport` exists so a consumer can change the\n * PROTOCOL: a native bridge, a socket, a double that never leaves the process.\n * The three differed in a `content-type` header. That is not a protocol, it is an\n * encoding, and an encoding is a property of the CALL: a gateway with fourteen\n * JSON endpoints and one upload had no way to say so, because its request kind —\n * and with it its transport — was fixed in its constructor. The application that\n * hit this added a `useFormData` flag to its own options and wrote its own\n * transport to read it.\n *\n * So the encoding is decided here, per call, by looking at the body. A gateway\n * posts `FormData` to one endpoint and an object to the next, and neither it nor\n * the request kind has to know.\n *\n * ## What does NOT belong here\n *\n * The base URL (`ALankaGateway` prefixes `apiBaseUrl`), credentials, static\n * headers, CSRF, retry, auth refresh, idempotency keys and deadlines. Every one\n * of those is policy around a request rather than a way of sending one, and every\n * one is a middleware — `useRequestMiddleware`, which `@lankajs/plugin-http`\n * occupies. A transport that grew them would be a second composition mechanism\n * beside the one core already publishes, and \"where does a header get added\"\n * would have two answers.\n */\nexport class LankaFetchTransport implements ILankaTransport<TLankaRequestInit> {\n\tasync request(resource: RequestInfo, options?: TLankaRequestInit): Promise<Response> {\n\t\t// Nothing to encode: the object the caller assembled reaches `fetch`\n\t\t// unchanged, `undefined` included. \"No options\" and \"empty options\" are\n\t\t// different statements and `fetch` is entitled to tell them apart.\n\t\tif (options === undefined || options.body === undefined || options.body === null) {\n\t\t\treturn await fetch(resource, options as RequestInit | undefined);\n\t\t}\n\n\t\tconst { body, headers } = options;\n\n\t\t// Multipart: the header is REMOVED, not set. The boundary is generated with\n\t\t// the body, and a hand-written `content-type` carries none — the server then\n\t\t// reads zero fields out of a request that looks correct.\n\t\tif (isFormData(body)) {\n\t\t\tif (headers === undefined) return await fetch(resource, options as RequestInit);\n\n\t\t\tconst stripped = new Headers(headers);\n\t\t\tstripped.delete(CONTENT_TYPE);\n\t\t\treturn await fetch(resource, { ...options, headers: stripped } as RequestInit);\n\t\t}\n\n\t\t// Already something `fetch` understands: untouched.\n\t\tif (isEncodedBody(body)) return await fetch(resource, options as RequestInit);\n\n\t\treturn await fetch(resource, {\n\t\t\t...options,\n\t\t\theaders: withJsonContentType(headers),\n\t\t\tbody: JSON.stringify(body),\n\t\t});\n\t}\n}\n\n/**\n * The header set, with `content-type` filled in only if the caller left it out.\n *\n * Not overwritten: `application/merge-patch+json` and `application/ld+json` are\n * JSON that a server distinguishes, and a transport that flattened them to\n * `application/json` would turn a PATCH into a request the server refuses — for\n * a header the caller had already written correctly.\n */\nfunction withJsonContentType(headers: HeadersInit | undefined): Headers {\n\tconst result = new Headers(headers);\n\tif (!result.has(CONTENT_TYPE)) result.set(CONTENT_TYPE, JSON_CONTENT_TYPE);\n\treturn result;\n}\n\n/**\n * Whether `fetch` can already send this body.\n *\n * Every global here is guarded by `typeof`: core runs in node and React Native\n * as well as a browser, and `ReadableStream` in particular is absent on engines\n * this framework supports. An unguarded `instanceof` against a missing global is\n * a `ReferenceError` on the first request, from a transport, in production.\n *\n * Cheapest and most common first. A string — an already-serialised body — stops\n * on line one.\n */\nfunction isEncodedBody(body: unknown): body is BodyInit {\n\tif (typeof body === \"string\") return true;\n\tif (typeof URLSearchParams !== \"undefined\" && body instanceof URLSearchParams) return true;\n\tif (typeof Blob !== \"undefined\" && body instanceof Blob) return true;\n\tif (body instanceof ArrayBuffer || ArrayBuffer.isView(body)) return true;\n\treturn typeof ReadableStream !== \"undefined\" && body instanceof ReadableStream;\n}\n\n/**\n * Multipart, checked separately because it is the one body whose header is\n * removed rather than added.\n */\nfunction isFormData(body: unknown): body is FormData {\n\treturn typeof FormData !== \"undefined\" && body instanceof FormData;\n}\n","import { ALankaTransportRequest } from \"../_abstractions/lanka-transport-request/ALankaTransportRequest\";\nimport type { ILankaTransportRequestConfig } from \"../_abstractions/lanka-transport-request/ALankaTransportRequest\";\nimport type { TLankaRequestInit } from \"../../_types/TLankaRequestInit\";\nimport { LankaFetchTransport } from \"../../lanka-fetch-transport/LankaFetchTransport\";\nimport { LankaError } from \"../../../errors/lanka-error/LankaError\";\n\n/** The JSON request: parses the body, and refuses a body that is not JSON. */\n/**\n * A request kind that answers a parsed JSON body — what most endpoints return.\n *\n * A gateway holds one, and is handed it rather than constructing it, which is\n * what lets a test give the same gateway a transport that never leaves the\n * process. `createLankaFetchJsonRequest()` builds the same class.\n */\nexport class LankaFetchJsonRequest<\n\tTOptions extends TLankaRequestInit = TLankaRequestInit,\n> extends ALankaTransportRequest<TOptions> {\n\tconstructor(config: ILankaTransportRequestConfig<TOptions> = {}) {\n\t\tsuper(config, () => new LankaFetchTransport());\n\t}\n\n\t/**\n\t * Parses the body, or names the failure.\n\t *\n\t * The content type is read for the ERROR MESSAGE only. Using it to choose\n\t * between two parse paths, where the second answers `{}` for any non-empty\n\t * body it cannot parse, fails silently: the caller's schema is the first thing\n\t * to notice, and the caller's SCREEN is where it shows up.\n\t *\n\t * A measured case: a dev server whose `/api` fell through to the SPA fallback\n\t * answered `200 text/html` with `index.html`. Turned into `{}`, the schema\n\t * refused it and a person read a validator's issue list on the sign-in card. A\n\t * body a JSON transport cannot parse is never a value — it is a misrouted\n\t * request, and saying so names the actual failure.\n\t */\n\tprotected async parse<TReturn>(response: Response): Promise<TReturn> {\n\t\tconst contentType = response.headers.get(\"content-type\");\n\n\t\tconst text = await response.text();\n\t\tif (!text) {\n\t\t\treturn undefined as TReturn;\n\t\t}\n\n\t\ttry {\n\t\t\treturn JSON.parse(text) as TReturn;\n\t\t} catch (error) {\n\t\t\t// `schema`, not `network`: the request arrived, the server answered, and\n\t\t\t// the answer was the wrong shape. Not cosmetic — a network failure\n\t\t\t// invites a retry, while retrying a broken contract is pointless and\n\t\t\t// blaming the user for it more so.\n\t\t\tthrow new LankaError({\n\t\t\t\tkind: \"schema\",\n\t\t\t\tmessage:\n\t\t\t\t\t`Failed to parse JSON response (content-type: ${contentType ?? \"none\"}): ` +\n\t\t\t\t\t`${error instanceof Error ? error.message : String(error)}`,\n\t\t\t\tcause: error,\n\t\t\t});\n\t\t}\n\t}\n}\n","import { TLankaQueryParams } from \"../../_types/TLankaQueryParams\";\nimport { TLankaQueryBuilder } from \"../../_types/TLankaQueryBuilder\";\n\n/**\n * The query string a gateway sends, from the object a method was called with.\n *\n * Arrays become `key[]` repeated, nested objects become `key[inner]`: the shape\n * most JSON APIs read back without being told about it.\n *\n * Plain loops over `Object.keys` rather than `Object.entries` and `forEach`: this\n * runs on every request that carries a filter, and the pair array `entries`\n * builds — two allocations per key, thrown away immediately — is a cost with\n * nothing to show for it.\n */\nexport const buildLankaQueryParams: TLankaQueryBuilder = <T extends Record<string, unknown>>(\n\tinput: T,\n): URLSearchParams => {\n\tconst params = new URLSearchParams();\n\n\tconst append = (key: string, value: TLankaQueryParams): void => {\n\t\tif (value == null) return;\n\n\t\tif (Array.isArray(value)) {\n\t\t\t// The bracketed key once for the whole array, not once per element.\n\t\t\tconst itemKey = `${key}[]`;\n\t\t\tfor (let index = 0; index < value.length; index += 1) append(itemKey, value[index]);\n\n\t\t\treturn;\n\t\t}\n\n\t\tif (typeof value === \"object\") {\n\t\t\tconst inner = value as Record<string, TLankaQueryParams>;\n\t\t\tconst innerKeys = Object.keys(inner);\n\n\t\t\tfor (let index = 0; index < innerKeys.length; index += 1) {\n\t\t\t\tconst innerKey = innerKeys[index];\n\t\t\t\tappend(`${key}[${innerKey}]`, inner[innerKey]);\n\t\t\t}\n\n\t\t\treturn;\n\t\t}\n\n\t\tparams.append(key, String(value));\n\t};\n\n\tconst source = input as Record<string, TLankaQueryParams>;\n\tconst keys = Object.keys(source);\n\n\tfor (let index = 0; index < keys.length; index += 1) append(keys[index], source[keys[index]]);\n\n\treturn params;\n};\n","import type { TLankaRequestInit } from \"../../_types/TLankaRequestInit\";\nimport type { IALankaGatewayConfig } from \"../../_interfaces/IALankaGatewayConfig\";\nimport { lankaLogger } from \"../../../logger/lanka-logger/LankaLogger\";\nimport { LankaFetchJsonRequest } from \"../../request/lanka-fetch-json-request/LankaFetchJsonRequest\";\nimport type { ILankaRequest } from \"../../_interfaces/ILankaRequest\";\nimport type { TLankaExecuteOptions } from \"../../_types/TLankaExecuteOptions\";\nimport { buildLankaQueryParams } from \"../../_utils/build-lanka-query-params/buildLankaQueryParams\";\nimport { TLankaQueryParams } from \"../../_types/TLankaQueryParams\";\nimport { TLankaQueryBuilder } from \"../../_types/TLankaQueryBuilder\";\nimport { getLankaFlags } from \"../../../config/get-lanka-flags/getLankaFlags\";\nimport { getLankaHost } from \"../../../config/get-lanka-host/getLankaHost\";\nimport { lankaStandardValidator } from \"../../../validation/lanka-standard-validator/lankaStandardValidator\";\nimport type { ILankaValidator } from \"../../../validation/lanka-standard-validator/lankaStandardValidator\";\n\nexport abstract class ALankaGateway<TOptions = TLankaRequestInit> {\n\tprotected requestExecutor: ILankaRequest<TOptions>;\n\tprotected queryParamsHandler: TLankaQueryBuilder;\n\n\t/**\n\t * The validator a method checks a response body with.\n\t *\n\t * `config.validationService` when one was given, the Standard Schema port\n\t * otherwise. It used to be accepted by the config and read by nothing: a\n\t * consumer handing a test double to the gateway got the real validator and no\n\t * error, which is the worst kind of ignored option — it looks honoured.\n\t */\n\tprotected readonly validationService: ILankaValidator;\n\n\tprotected readonly useMock: boolean;\n\tprotected readonly basePath: string;\n\n\tprotected constructor(config: IALankaGatewayConfig<TOptions>) {\n\t\tlankaLogger.printGatewayLog(\"Create gateway\", this);\n\t\tconst flags = getLankaFlags();\n\t\tthis.useMock = config.useMock ?? flags.isMockMode ?? false;\n\t\tthis.validationService = config.validationService ?? lankaStandardValidator;\n\n\t\t// A gateway with nothing said about transport talks JSON over `fetch`, which\n\t\t// is what almost every one of them does. Supplying a request is how a gateway\n\t\t// stops being ordinary — a raw `Response`, a multipart upload, a transport\n\t\t// that never leaves the process — and that stays a decision rather than a\n\t\t// line every gateway has to carry to be born.\n\t\t// The cast covers the FRAMEWORK picking its own fallback, and nothing a\n\t\t// consumer does. `TOptions` is unconstrained here on purpose — a gateway may\n\t\t// front a request that never speaks HTTP, and the port promises exactly that\n\t\t// — so the JSON default cannot be proven to fit a `TOptions` nobody has\n\t\t// named yet. A consumer whose options are not fetch-shaped supplies\n\t\t// `request`, and this line never runs for them.\n\t\tthis.requestExecutor = config.request ?? new LankaFetchJsonRequest();\n\n\t\tthis.basePath = config.basePath ?? \"\";\n\t\tthis.queryParamsHandler = config.queryParamsHandler ?? buildLankaQueryParams;\n\t}\n\n\t/**\n\t * Resolves endpoint for request.\n\t * - Absolute paths (starting with \"/\") are returned as-is\n\t * - Relative paths are joined with basePath\n\t * - Query-only strings like \"?a=1\" are attached to basePath\n\t */\n\tprotected endpoint(path: string = \"\"): string {\n\t\t// An absolute URL is detected BEFORE joining with `basePath`, not after:\n\t\t// otherwise `https://other.host/health` first becomes\n\t\t// `/things/https://other.host/health` and there is nothing left to detect.\n\t\tif (isAbsoluteUrl(path)) return path;\n\n\t\t// A path already under the base is one this method produced, and it is\n\t\t// returned as it is: `endpoint()` is idempotent. `request()` resolves\n\t\t// through `endpoint()`, and every gateway in the guide hands it\n\t\t// `this.endpoint(…)`, so each call resolves twice. An absolute base hides\n\t\t// that — the first pass makes an absolute URL — and a RELATIVE one (`/api`)\n\t\t// sent every request to `/api/api/…` (issue #7).\n\t\t//\n\t\t// Decided on the INPUT, before `basePath` is joined, and not on the joined\n\t\t// result: a gateway whose `basePath` happens to start with the base's\n\t\t// segment then resolves exactly as it always did, and only an argument that\n\t\t// already carries the base is left alone. The one reading given up: a path\n\t\t// written as `/api/x` under a base of `/api` means `/api/x`.\n\t\tconst base = withoutTrailingSlashes(getLankaHost().apiBaseUrl);\n\t\tif (base && isUnder(path, base)) return path;\n\n\t\treturn withApiBase(base, this.resolvePath(path));\n\t}\n\n\t/**\n\t * Joins `basePath` and the method path.\n\t */\n\tprivate resolvePath(path: string): string {\n\t\tif (!path) return this.basePath;\n\n\t\tif (path.startsWith(\"/\")) return path;\n\n\t\tif (path.startsWith(\"?\")) return `${this.basePath}${path}`;\n\n\t\t// No leading-slash case here: the check above already returned for one, so\n\t\t// stripping it again was a branch no input could take — uncoverable by\n\t\t// construction, and it counted against the coverage floor that gates this\n\t\t// package.\n\t\tconst left = this.basePath.endsWith(\"/\") ? this.basePath.slice(0, -1) : this.basePath;\n\t\treturn `${left}/${path}`;\n\t}\n\n\tprotected buildQueryParams<T extends object>(params: T): URLSearchParams {\n\t\treturn this.queryParamsHandler(params as Record<string, TLankaQueryParams>);\n\t}\n\n\tprotected async request<TReturn = unknown>(\n\t\tpath: string,\n\t\toptions?: TLankaExecuteOptions<TOptions>,\n\t\tmockHandler?: () => Promise<TReturn>,\n\t): Promise<TReturn> {\n\t\treturn this.requestExecutor.execute<TReturn>(this.endpoint(path), options, mockHandler);\n\t}\n\n\t/**\n\t * Allows to replace request implementation at runtime (e.g. feature flags / tests).\n\t * If you prefer static customization - override `request()` in a subclass.\n\t */\n\tprotected setRequest(request: ILankaRequest<TOptions>): void {\n\t\tthis.requestExecutor = request;\n\t}\n\n\tprotected setQueryParamsHandler(handler: TLankaQueryBuilder): void {\n\t\tthis.queryParamsHandler = handler;\n\t}\n}\n\n/**\n * A scheme plus `//` — a URL that already knows where it is going.\n *\n * A standalone function rather than a method: it is not about a particular\n * gateway, and `endpoint()` needs it before any joining.\n */\nfunction isAbsoluteUrl(path: string): boolean {\n\t// The cheap half first: a scheme needs `://`, and `includes` answers without\n\t// starting the regex engine. Every relative path an application writes — which\n\t// is nearly all of them — stops on this line.\n\tif (!path.includes(\"://\")) return false;\n\n\treturn /^[a-z][a-z\\d+\\-.]*:\\/\\//i.test(path);\n}\n\n/**\n * Prefixes the API base URL from the host contract.\n *\n * Here rather than in every consumer: otherwise each consumer knows the URL\n * and the framework does not, and a realtime plugin would have to know a\n * specific application's build.\n *\n * Declaring the field and not using it would be worse than not declaring it: a\n * declaration nothing is built from is a second truth, free to diverge from\n * the first.\n *\n * An absolute URL never reaches here — `endpoint()` filters it out before the\n * join. The base is passed in rather than read: `endpoint()` has already read\n * it, and the host is not asked twice per request.\n */\nfunction withApiBase(base: string, path: string): string {\n\tif (!base) return path;\n\tif (!path) return base;\n\n\treturn path.startsWith(\"/\") ? `${base}${path}` : `${base}/${path}`;\n}\n\n/**\n * The base itself, or a path below it — compared as a whole segment.\n *\n * `/api-keys` starts with `/api` and is not under it; a bare `startsWith` would\n * take it for already-prefixed and drop the base from a real request.\n */\nfunction isUnder(path: string, base: string): boolean {\n\tif (!path.startsWith(base)) return false;\n\n\tconst next = path.charAt(base.length);\n\treturn next === \"\" || next === \"/\" || next === \"?\";\n}\n\n/**\n * The API base without its trailing slashes, remembered between calls.\n *\n * The host answers the same string for the life of an application, and trimming\n * it is a regex replace otherwise run on every endpoint of every request. One\n * entry is enough: there is one active host, and a second framework in the same\n * process simply replaces what is remembered here.\n */\nlet lastRawBase: string | null = null;\nlet lastTrimmedBase = \"\";\n\nfunction withoutTrailingSlashes(base: string): string {\n\tif (base !== lastRawBase) {\n\t\tlastRawBase = base;\n\t\tlastTrimmedBase = base.replace(/\\/+$/, \"\");\n\t}\n\n\treturn lastTrimmedBase;\n}\n","import { ALankaGateway } from \"../../_abstractions/lanka-gateway/ALankaGateway\";\nimport type { IALankaGatewayConfig } from \"../../_interfaces/IALankaGatewayConfig\";\nimport type { ILankaGatewayContext } from \"../../_interfaces/ILankaGatewayContext\";\n\n/** What a gateway is built from, whichever style builds it. */\nexport interface ILankaGatewayConfig<\n\tTOptions,\n\tTMethods extends object,\n> extends IALankaGatewayConfig<TOptions> {\n\t/** The endpoints this gateway offers, written over its own surface. */\n\tmethods: (context: ILankaGatewayContext<TOptions>) => TMethods;\n}\n\n/**\n * A gateway, without writing a class.\n *\n * The bridge below is the whole mechanism, and it lives here rather than on the\n * base for two reasons. The language reads `protected` from inside a deriving\n * class body and nowhere else, so a factory outside the hierarchy could only\n * reach the public half — the wrong one. And a `toStyleContext` ON the base\n * would put `TOptions` in a method's parameter position, making the class\n * invariant in it: every `ALankaGateway<unknown>` the locator holds would stop\n * accepting a gateway typed for `RequestInit`.\n *\n * One implementation: what comes back is an instance of `ALankaGateway`, so a\n * behaviour fix reaches both styles at once.\n */\nexport const createLankaGateway = <TOptions, TMethods extends object>(\n\tconfig: ILankaGatewayConfig<TOptions, TMethods>,\n): TMethods => {\n\tclass FunctionalGateway extends ALankaGateway<TOptions> {\n\t\t// The base keeps a protected constructor — it is abstract, and a consumer\n\t\t// reaching for `new ALankaGateway()` would get an object with no endpoints.\n\t\t// A subclass may widen it, and this one is the subclass.\n\t\tpublic constructor(gatewayConfig: IALankaGatewayConfig<TOptions>) {\n\t\t\tsuper(gatewayConfig);\n\t\t}\n\n\t\tpublic build(): TMethods {\n\t\t\treturn config.methods({\n\t\t\t\tendpoint: (path) => this.endpoint(path),\n\t\t\t\trequest: (path, options, mockHandler) => this.request(path, options, mockHandler),\n\t\t\t\tbuildQueryParams: (params) => this.buildQueryParams(params),\n\t\t\t\tvalidationService: this.validationService,\n\t\t\t});\n\t\t}\n\t}\n\n\treturn new FunctionalGateway(config).build();\n};\n","import { ALankaTransportRequest } from \"../_abstractions/lanka-transport-request/ALankaTransportRequest\";\nimport type { ILankaTransportRequestConfig } from \"../_abstractions/lanka-transport-request/ALankaTransportRequest\";\nimport type { TLankaRequestInit } from \"../../_types/TLankaRequestInit\";\nimport { LankaFetchTransport } from \"../../lanka-fetch-transport/LankaFetchTransport\";\n\n/**\n * The raw request: hands the `Response` back untouched.\n *\n * The minimal, extensible case — a caller wanting headers, a stream, a blob or a\n * `204` reads them off the response itself. Multipart uploads come through here\n * too: the transport encodes by looking at the body, so posting a `FormData` and\n * posting an object are the same call.\n *\n * `TOptions` is CONSTRAINED to fetch options rather than merely defaulted to\n * them. A consumer widening it — their own `interface IRequestOptions extends\n * TLankaRequestInit` — still gets the shipped transport, because the constraint\n * is what lets the framework hand one over without a cast. Unconstrained, the\n * assignment did not typecheck and core cast its way past it; the cast worked\n * here and was unavailable to the consumer, who wrote a transport instead.\n */\nexport class LankaFetchRequest<\n\tTOptions extends TLankaRequestInit = TLankaRequestInit,\n> extends ALankaTransportRequest<TOptions> {\n\tconstructor(config: ILankaTransportRequestConfig<TOptions> = {}) {\n\t\tsuper(config, () => new LankaFetchTransport());\n\t}\n\n\tprotected parse<TReturn>(response: Response): Promise<TReturn> {\n\t\treturn Promise.resolve(response as unknown as TReturn);\n\t}\n}\n","import { LankaFetchRequest } from \"../../lanka-fetch-request/LankaFetchRequest\";\nimport type { ILankaTransportRequestConfig } from \"../../_abstractions/lanka-transport-request/ALankaTransportRequest\";\nimport type { TLankaRequestInit } from \"../../../_types/TLankaRequestInit\";\n\n/**\n * The functional style of `LankaFetchRequest`: the raw `Response`, for a download or a stream.\n *\n * One line, and that is the point — the factory IS the class, so a behaviour\n * cannot exist in one style and not the other.\n */\nexport const createLankaFetchRequest = <TOptions extends TLankaRequestInit = TLankaRequestInit>(\n\tconfig: ILankaTransportRequestConfig<TOptions> = {},\n): LankaFetchRequest<TOptions> => new LankaFetchRequest<TOptions>(config);\n","import { LankaFetchJsonRequest } from \"../../lanka-fetch-json-request/LankaFetchJsonRequest\";\nimport type { ILankaTransportRequestConfig } from \"../../_abstractions/lanka-transport-request/ALankaTransportRequest\";\nimport type { TLankaRequestInit } from \"../../../_types/TLankaRequestInit\";\n\n/**\n * The functional style of `LankaFetchJsonRequest`: a JSON body, which is what most endpoints answer.\n *\n * One line, and that is the point — the factory IS the class, so a behaviour\n * cannot exist in one style and not the other.\n */\nexport const createLankaFetchJsonRequest = <TOptions extends TLankaRequestInit = TLankaRequestInit>(\n\tconfig: ILankaTransportRequestConfig<TOptions> = {},\n): LankaFetchJsonRequest<TOptions> => new LankaFetchJsonRequest<TOptions>(config);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,SAAS,uBAAuB,OAAgB,UAA+B;AAC9E,MAAI,WAAW,GAAG,KAAK,EAAG,QAAO;AAUjC,QAAM,OA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,CAAC;AAAA,IACF;AAAA,EACD;AAEA,SAAO,IAAI,kBAAkB,MAAM,EAAE,MAAM;AAC5C;;;AC7BO,IAAM,oBAAN,cAEG,uBAAiC;AAAA,EAC1C,YAAY,SAAiD,CAAC,GAAG;AAChE,UAAM,QAAQ,MAAM,IAAI,oBAAoB,CAAC;AAAA,EAC9C;AAAA,EAEU,MAAe,UAAsC;AAC9D,WAAO,QAAQ,QAAQ,QAA8B;AAAA,EACtD;AACD;;;ACpBO,IAAM,0BAA0B,CACtC,SAAiD,CAAC,MACjB,IAAI,kBAA4B,MAAM;;;ACFjE,IAAM,8BAA8B,CAC1C,SAAiD,CAAC,MACb,IAAI,sBAAgC,MAAM;","names":[]}
1
+ {"version":3,"sources":["../../src/gateway/request/_internal/create-request-lifetime/createRequestLifetime.ts","../../src/gateway/request/_abstractions/lanka-request/ALankaRequest.ts","../../src/gateway/request/_abstractions/lanka-transport-request/ALankaTransportRequest.ts","../../src/gateway/lanka-fetch-transport/LankaFetchTransport.ts","../../src/gateway/request/lanka-fetch-json-request/LankaFetchJsonRequest.ts","../../src/gateway/_utils/build-lanka-query-params/buildLankaQueryParams.ts","../../src/gateway/_abstractions/lanka-gateway/ALankaGateway.ts","../../src/gateway/_factories/create-lanka-gateway/createLankaGateway.ts","../../src/gateway/request/lanka-fetch-request/LankaFetchRequest.ts","../../src/gateway/request/_factories/create-lanka-fetch-request/createLankaFetchRequest.ts","../../src/gateway/request/_factories/create-lanka-fetch-json-request/createLankaFetchJsonRequest.ts"],"sourcesContent":["export interface IRequestLifetime {\n\treadonly signal: AbortSignal | undefined;\n\t/** Whether OUR timer aborted the request rather than the caller. */\n\ttimedOut(): boolean;\n\t/** Whether the page was SEEN to hide, or to unload, while the attempt lived. */\n\twasHidden(): boolean;\n\tdispose(): void;\n}\n\ninterface IVisibleDeadline {\n\tpause(): void;\n\tresume(): void;\n\tclear(): void;\n}\n\nconst NO_LIFETIME: IRequestLifetime = Object.freeze({\n\tsignal: undefined,\n\ttimedOut: () => false,\n\twasHidden: () => false,\n\tdispose: () => undefined,\n});\n\n/**\n * `\"hidden\"` exactly. A test runner's DOM may answer `\"prerender\"`, and a\n * deadline paused there would never fire in anybody's suite.\n */\nconst isPageHidden = (): boolean =>\n\ttypeof document !== \"undefined\" && document.visibilityState === \"hidden\";\n\n/**\n * A timer that stops counting while the page is seen hidden.\n *\n * A mobile WebView is FROZEN when the user leaves it — an external link, an app\n * switch, a locked screen — and timers do not run while it is. An overdue timer\n * fires at once on resume, so a plain `setTimeout` reported a timeout for a\n * request that was never slow: the minute the page spent frozen was counted as\n * the server's. The remainder is computed when the page HIDES, which is the last\n * moment the clock is still honest.\n *\n * It always STARTS. A page already hidden when the attempt begins is not trusted\n * to say `visible` again — some WebViews report `hidden` from load and never\n * change it, an Electron window may never be shown — and a clock that waited for\n * it would make the caller's deadline mean nothing there. Only a hide seen while\n * the attempt lives pauses it.\n */\nfunction createVisibleDeadline(timeoutMs: number, onExpire: () => void): IVisibleDeadline {\n\tlet remainingMs = timeoutMs;\n\tlet startedAt = 0;\n\tlet timer: ReturnType<typeof setTimeout> | undefined;\n\tlet cleared = false;\n\n\tconst pause = (): void => {\n\t\tif (timer === undefined) return;\n\t\tclearTimeout(timer);\n\t\ttimer = undefined;\n\t\tremainingMs = Math.max(0, remainingMs - (Date.now() - startedAt));\n\t};\n\tconst resume = (): void => {\n\t\tif (timer !== undefined || cleared) return;\n\t\tstartedAt = Date.now();\n\t\ttimer = setTimeout(() => {\n\t\t\tcleared = true;\n\t\t\tonExpire();\n\t\t}, remainingMs);\n\t};\n\tconst clear = (): void => {\n\t\tcleared = true;\n\t\tif (timer !== undefined) clearTimeout(timer);\n\t\ttimer = undefined;\n\t};\n\n\tresume();\n\treturn { pause, resume, clear };\n}\n\n/**\n * Follows the page for one attempt: whether it hid, and the deadline with it.\n *\n * `pagehide` beside `visibilitychange`: a page unloaded under its own requests\n * — the host relaunching the web app — cuts their fetches, and they come back as\n * `network` with nothing to tell them from a dropped connection. And `pageshow`\n * to resume: a page restored from the back/forward cache by an engine that\n * sends no `visibilitychange` would otherwise stay paused.\n */\nfunction watchPage(deadline: IVisibleDeadline | undefined, onHide: () => void): () => void {\n\tif (typeof document === \"undefined\" || typeof window === \"undefined\") return () => undefined;\n\n\tconst onVisibility = (): void => {\n\t\tif (isPageHidden()) {\n\t\t\tonHide();\n\t\t\tdeadline?.pause();\n\t\t} else deadline?.resume();\n\t};\n\tconst onPageHide = (): void => {\n\t\tonHide();\n\t\tdeadline?.pause();\n\t};\n\tconst onPageShow = (): void => {\n\t\tif (!isPageHidden()) deadline?.resume();\n\t};\n\n\tdocument.addEventListener(\"visibilitychange\", onVisibility);\n\twindow.addEventListener(\"pagehide\", onPageHide);\n\twindow.addEventListener(\"pageshow\", onPageShow);\n\treturn () => {\n\t\tdocument.removeEventListener(\"visibilitychange\", onVisibility);\n\t\twindow.removeEventListener(\"pagehide\", onPageHide);\n\t\twindow.removeEventListener(\"pageshow\", onPageShow);\n\t};\n}\n\n/**\n * Combines the caller's signal, our own deadline and the page's visibility into\n * one request lifetime.\n *\n * The outcome looks the same — an interrupted request — but the decisions\n * differ: a timeout is shown and offered for retry, a user cancellation is not\n * shown at all. `AbortSignal` does not distinguish them: one `abort`, whose\n * reason belongs to whoever got there first. Hence the private flag.\n *\n * Not `AbortSignal.timeout` alone: it cannot combine with a foreign signal\n * without `AbortSignal.any`, which older engines lack, and it cannot pause.\n */\nexport function createRequestLifetime(\n\texternal: AbortSignal | undefined,\n\ttimeoutMs: number | undefined,\n): IRequestLifetime {\n\tconst followsPage = typeof document !== \"undefined\";\n\tif (!external && !timeoutMs && !followsPage) return NO_LIFETIME;\n\n\t// No signal is produced when the caller gave none and set no deadline: \"no\n\t// options\" and \"empty options\" are different statements to a transport.\n\tconst controller = external || timeoutMs ? new AbortController() : undefined;\n\tlet expired = false;\n\tlet hidden = false;\n\n\tconst deadline =\n\t\tcontroller && timeoutMs !== undefined\n\t\t\t? createVisibleDeadline(timeoutMs, () => {\n\t\t\t\t\texpired = true;\n\t\t\t\t\tcontroller.abort(new DOMException(\"Request timed out\", \"TimeoutError\"));\n\t\t\t\t})\n\t\t\t: undefined;\n\tconst unwatch = watchPage(deadline, () => {\n\t\thidden = true;\n\t});\n\n\tconst onExternalAbort = (): void => {\n\t\tcontroller?.abort(external?.reason);\n\t};\n\tif (external) {\n\t\tif (external.aborted) onExternalAbort();\n\t\telse external.addEventListener(\"abort\", onExternalAbort, { once: true });\n\t}\n\n\treturn {\n\t\tsignal: controller?.signal,\n\t\ttimedOut: () => expired,\n\t\twasHidden: () => hidden,\n\t\tdispose: () => {\n\t\t\tdeadline?.clear();\n\t\t\tunwatch();\n\t\t\texternal?.removeEventListener(\"abort\", onExternalAbort);\n\t\t},\n\t};\n}\n","import type { TLankaRequestInit } from \"../../../_types/TLankaRequestInit\";\nimport type { TLankaErrorHandler } from \"../../../../errors/_types/TLankaErrorHandler\";\nimport type { ILankaRequest } from \"../../../_interfaces/ILankaRequest\";\nimport type { TLankaExecuteOptions } from \"../../../_types/TLankaExecuteOptions\";\nimport { handleLankaApiError } from \"../../../../errors/handle-lanka-api-error/handleLankaApiError\";\nimport { getLankaFlags } from \"../../../../config/get-lanka-flags/getLankaFlags\";\nimport { getLankaHost } from \"../../../../config/get-lanka-host/getLankaHost\";\nimport { lankaHttpInFlight } from \"../../../inflight/lankaHttpInFlight\";\nimport { LankaError } from \"../../../../errors/lanka-error/LankaError\";\nimport { getActiveRuntime } from \"../../../../_internal/active-runtime/activeRuntime\";\nimport { composeLankaRequestMiddleware } from \"../../lankaRequestMiddleware\";\nimport type { ILankaRequestContext } from \"../../lankaRequestMiddleware\";\nimport { createRequestLifetime } from \"../../_internal/create-request-lifetime/createRequestLifetime\";\n\n/** What the attempt that failed knew about itself. */\ninterface IAttemptOutcome {\n\treadonly timedOut: boolean;\n\treadonly hidden: boolean;\n}\n\nconst NO_OUTCOME: IAttemptOutcome = Object.freeze({ timedOut: false, hidden: false });\n\n/**\n * Tags an interrupted request: a timeout or a cancellation.\n *\n * Only whoever assembled the lifetime knows who aborted: `AbortSignal` has one\n * `abort` for everyone. The distinction carries a decision — a timeout is shown,\n * a cancellation is not. And only a cancellation can be \"from the background\": the\n * deadline no longer counts hidden time, so a timeout that still ran out is the\n * server being slow while somebody looked.\n */\nfunction tagInterruption(error: unknown, name: string, attempt: IAttemptOutcome): LankaError {\n\tconst timedOutHere = attempt.timedOut || name === \"TimeoutError\";\n\treturn new LankaError({\n\t\tkind: timedOutHere ? \"timeout\" : \"aborted\",\n\t\tmessage: timedOutHere ? getLankaHost().timeoutErrorMessage() : readErrorMessage(error),\n\t\tisFromBackground: !timedOutHere && attempt.hidden,\n\t\tcause: error,\n\t});\n}\n\n/**\n * Tags whatever the transport threw with a kind.\n *\n * Here rather than in the transports: `execute` is the single point EVERY\n * request passes through, and tagging in each of the four transports would be\n * four places to forget it.\n *\n * A real `fetch` throws `TypeError` on a broken connection and a `DOMException`\n * named `AbortError` on cancellation; it does not throw on a status code at all.\n *\n * An already-tagged error is NOT re-tagged: a request-policy plugin may report\n * `domain`, and rewriting that to `network` would lose the one thing the kind\n * exists for.\n */\nfunction classifyTransportError(error: unknown, attempt: IAttemptOutcome): LankaError {\n\tif (LankaError.is(error)) return error;\n\n\t// The name is read off ANYTHING, not only off `Error`.\n\t//\n\t// `DOMException` — how `fetch` reports cancellation — does not extend `Error`\n\t// everywhere: in a browser yes, in jsdom no. An `instanceof Error` check lets\n\t// cancellation past the tagging, and a raw `AbortError` reaches the app with\n\t// neither `kind` nor `status`: retry policy reads it as non-retryable and the\n\t// app as an unknown error, so a cancelled request is shown to the user as a\n\t// failure.\n\tconst name = readErrorName(error);\n\tif (name === \"AbortError\" || name === \"TimeoutError\")\n\t\treturn tagInterruption(error, name, attempt);\n\n\t// `network` ONLY for what looks like a transport failure. A real `fetch`\n\t// throws `TypeError`; everything else comes from code we did not write — the\n\t// app's error handler, a response transformer, a broken plugin — and calling\n\t// that a network failure would invite the user to retry a request that\n\t// arrived and was processed.\n\t//\n\t// Unknown stays unknown and passes through. The framework asserts only what\n\t// it knows.\n\tif (error instanceof TypeError) {\n\t\treturn new LankaError({\n\t\t\tkind: \"network\",\n\t\t\tmessage: getLankaHost().networkErrorMessage(),\n\t\t\tissues: [error.message],\n\t\t\tisFromBackground: attempt.hidden,\n\t\t\tcause: error,\n\t\t});\n\t}\n\n\treturn error as LankaError;\n}\n\n/** The error name, off `Error`, `DOMException` or anything else carrying one. */\nfunction readErrorName(error: unknown): string | undefined {\n\tif (typeof error !== \"object\" || error === null) return undefined;\n\tconst name: unknown = (error as { name?: unknown }).name;\n\treturn typeof name === \"string\" ? name : undefined;\n}\n\n/**\n * The error text, when there is one.\n *\n * An object without `message` is not stringified: `String({})` yields\n * `[object Object]`, which occupies the message slot and says nothing. Empty is\n * more honest.\n */\nfunction readErrorMessage(error: unknown): string {\n\tif (typeof error === \"string\") return error;\n\tif (typeof error !== \"object\" || error === null) return \"\";\n\tconst message: unknown = (error as { message?: unknown }).message;\n\treturn typeof message === \"string\" ? message : \"\";\n}\n\n/**\n * How a gateway request goes on the wire.\n *\n * A subclass declares one method, `request()`, and does only its own work there:\n * `LankaFetchJsonRequest` returns parsed JSON, `LankaFetchRequest` returns the\n * whole response, a custom kind returns whatever it likes.\n *\n * Overriding `request()` customises the request flow, failure handling, mock\n * substitution, response transformation and log interception.\n */\nexport abstract class ALankaRequest<\n\tTOptions = TLankaRequestInit,\n> implements ILankaRequest<TOptions> {\n\tprotected readonly errorHandler?: TLankaErrorHandler;\n\tprotected readonly useMock: boolean;\n\n\tprotected constructor(config: { errorHandler?: TLankaErrorHandler; useMock?: boolean }) {\n\t\tconst flags = getLankaFlags();\n\n\t\t// The default error-body handler lives HERE because the request is the only\n\t\t// thing that sees the `Response`. Put on the gateway it would sit in a field\n\t\t// nobody reads — the request takes the handler from ITS OWN config — and a\n\t\t// consumer passing `errorHandler` to the gateway would get silence.\n\t\t//\n\t\t// The parse is cheap: core reads the body once and takes `message` from it;\n\t\t// backend-specific shapes are parsed by `@lankajs/plugin-http`.\n\t\tthis.errorHandler = config.errorHandler ?? handleLankaApiError;\n\n\t\tthis.useMock = config.useMock ?? flags.isMockMode ?? false;\n\t}\n\n\t/**\n\t * Performs the request and returns its result — a response, JSON or a custom\n\t * type.\n\t *\n\t * @param endpoint Full URL\n\t * @param options Transport-specific options\n\t * @param mockHandler Mock, when there is one\n\t */\n\tprotected abstract request<TReturn = Response>(\n\t\tendpoint: string,\n\t\toptions?: TOptions,\n\t\tmockHandler?: () => Promise<TReturn>,\n\t): Promise<TReturn>;\n\n\t/**\n\t * The single point EVERY gateway request passes through.\n\t *\n\t * Hence the in-flight accounting here: intent prefetch stands down while\n\t * anything else is on the wire. The `finally` matters more than the increment —\n\t * a rejected request that never decremented would disable prefetching for the\n\t * rest of the session.\n\t */\n\tpublic async execute<TReturn = Response>(\n\t\tendpoint: string,\n\t\toptions?: TLankaExecuteOptions<TOptions>,\n\t\tmockHandler?: () => Promise<TReturn>,\n\t): Promise<TReturn> {\n\t\tconst runtime = getActiveRuntime();\n\t\tconst { signal, timeoutMs, ...rest } = (options ?? {}) as TLankaExecuteOptions<TOptions>;\n\t\t// The caller's deadline travels IN THE CONTEXT, not only in the closure:\n\t\t// otherwise a policy assigning deadlines per request class could not tell\n\t\t// \"no deadline given\" from \"given by the caller\" and would override an\n\t\t// explicit request with a blanket default.\n\t\tconst fallbackDeadline = runtime?.requestTimeoutMs;\n\n\t\t// No options passed means none are produced. Destructuring yields `{}` even\n\t\t// from `undefined`, and handing that empty object to the transport would\n\t\t// change the request: \"no options\" and \"empty options\" are different\n\t\t// statements, and the transport is entitled to tell them apart.\n\t\tconst passedOptions: unknown = options === undefined ? undefined : rest;\n\n\t\t/*\n\t\t * The lifetime is assembled PER ATTEMPT, not per call, and that does two\n\t\t * things at once.\n\t\t *\n\t\t * Under retry a shared deadline would start the third attempt with whatever\n\t\t * the first two left, so the retry aborts before reaching the server.\n\t\t *\n\t\t * And it is the only way to let middleware set the deadline: `ctx.timeoutMs`\n\t\t * is read on every attempt, which is how a request-policy plugin assigns a\n\t\t * deadline per request CLASS — a file upload and a list read cannot share\n\t\t * one value.\n\t\t *\n\t\t * Caller cancellation stays end-to-end: one `signal` for all attempts.\n\t\t */\n\t\tlet lastAttempt = NO_OUTCOME;\n\n\t\t// Tagging happens INSIDE, around the request itself, not in the outer\n\t\t// catch: middleware must receive an already-tagged error, or a retrying\n\t\t// middleware cannot tell a network failure from a domain rejection and\n\t\t// retries what must not be retried. The outer catch stays as a backstop.\n\t\tconst perform = async (ctx: ILankaRequestContext): Promise<unknown> => {\n\t\t\tconst lifetime = createRequestLifetime(signal, ctx.timeoutMs ?? fallbackDeadline);\n\t\t\ttry {\n\t\t\t\treturn await this.request<TReturn>(\n\t\t\t\t\tctx.endpoint,\n\t\t\t\t\twithSignal(ctx.options, lifetime.signal) as TOptions,\n\t\t\t\t\tmockHandler,\n\t\t\t\t);\n\t\t\t} catch (error) {\n\t\t\t\tlastAttempt = { timedOut: lifetime.timedOut(), hidden: lifetime.wasHidden() };\n\t\t\t\tthrow classifyTransportError(error, lastAttempt);\n\t\t\t} finally {\n\t\t\t\tlifetime.dispose();\n\t\t\t}\n\t\t};\n\n\t\tconst run = composeLankaRequestMiddleware(runtime?.requestMiddleware ?? [], perform);\n\n\t\tlankaHttpInFlight.begin();\n\t\ttry {\n\t\t\t// The chain runs INSIDE the same guard as the request. A catch placed\n\t\t\t// outside would leave a permanent +1 when a plugin throws, disabling\n\t\t\t// prefetch for the rest of the session — the very defect this `finally`\n\t\t\t// exists to prevent.\n\t\t\treturn (await run({\n\t\t\t\tendpoint,\n\t\t\t\toptions: passedOptions,\n\t\t\t\tattempt: 1,\n\t\t\t\ttimeoutMs,\n\t\t\t})) as TReturn;\n\t\t} catch (error) {\n\t\t\tthrow classifyTransportError(error, lastAttempt);\n\t\t} finally {\n\t\t\tlankaHttpInFlight.end();\n\t\t}\n\t}\n}\n\n/**\n * Attaches the signal to the options, inventing nothing.\n *\n * With no options and no signal the transport receives `undefined` — exactly\n * what the caller passed. An empty object instead looks harmless but is a\n * different statement, and the transport is entitled to tell them apart.\n */\nfunction withSignal(options: unknown, signal: AbortSignal | undefined): unknown {\n\tif (signal === undefined) return options;\n\treturn { ...(options ?? {}), signal };\n}\n","import { ALankaRequest } from \"../lanka-request/ALankaRequest\";\nimport { LankaError } from \"../../../../errors/lanka-error/LankaError\";\nimport { getLankaFlags } from \"../../../../config/get-lanka-flags/getLankaFlags\";\nimport { getLankaHost } from \"../../../../config/get-lanka-host/getLankaHost\";\nimport type { ILankaTransport } from \"../../../_interfaces/ILankaTransport\";\nimport type { TLankaRequestInit } from \"../../../_types/TLankaRequestInit\";\nimport type { TLankaErrorHandler } from \"../../../../errors/_types/TLankaErrorHandler\";\n\nexport interface ILankaTransportRequestConfig<TOptions> {\n\ttransport?: ILankaTransport<TOptions>;\n\terrorHandler?: TLankaErrorHandler;\n\tuseMock?: boolean;\n}\n\n/**\n * The shape every fetch-backed request has: mock, send, check, parse.\n *\n * The concrete requests differ in ONE place — how they turn a successful\n * `Response` into a value — so a third kind is a subclass with one method rather\n * than a third copy of the sequence.\n *\n * The default transport stays a constructor PARAMETER even though both shipped\n * kinds pass the same one. It is the seam a request kind that is not fetch-backed\n * comes through: this template is the mock/send/check/parse sequence, and nothing\n * in it is about HTTP. Defaulting the parameter here would fix `TOptions` to\n * fetch options for everyone who reuses the sequence.\n */\nexport abstract class ALankaTransportRequest<\n\tTOptions = TLankaRequestInit,\n> extends ALankaRequest<TOptions> {\n\tprotected readonly transport: ILankaTransport<TOptions>;\n\n\tprotected constructor(\n\t\tconfig: ILankaTransportRequestConfig<TOptions>,\n\t\tcreateDefaultTransport: () => ILankaTransport<TOptions>,\n\t) {\n\t\tconst flags = getLankaFlags();\n\n\t\tsuper({\n\t\t\terrorHandler: config.errorHandler,\n\t\t\tuseMock: config.useMock ?? flags.isMockMode ?? false,\n\t\t});\n\n\t\tthis.transport = config.transport ?? createDefaultTransport();\n\t}\n\n\tprotected async request<TReturn>(\n\t\tendpoint: string,\n\t\toptions?: TOptions,\n\t\tmockHandler?: () => Promise<TReturn>,\n\t): Promise<TReturn> {\n\t\tif (this.useMock && mockHandler) {\n\t\t\treturn await mockHandler();\n\t\t}\n\n\t\tconst response = await this.transport.request(endpoint, options);\n\t\tif (!response.ok) return await this.refuse(response);\n\n\t\treturn await this.parse<TReturn>(response);\n\t}\n\n\t/**\n\t * Turns a successful response into the value the caller asked for.\n\t *\n\t * The one step that genuinely differs between request kinds.\n\t */\n\tprotected abstract parse<TReturn>(response: Response): Promise<TReturn>;\n\n\t/**\n\t * Refuses an unsuccessful response, and never returns.\n\t *\n\t * `TLankaErrorHandler` is typed `Promise<never>` — a handler must throw. It is\n\t * still CALLED and then followed by a throw, because a handler that breaks its\n\t * contract and returns would otherwise hand `undefined` back as if the request\n\t * had succeeded, and a non-value must never become a value.\n\t */\n\tprotected async refuse(response: Response): Promise<never> {\n\t\tif (this.errorHandler) {\n\t\t\tawait this.errorHandler(response);\n\t\t}\n\n\t\t// Kind `http`, not a bare Error: the server answered, and answered with a\n\t\t// code. Without the kind this reads as a network failure, and the user is\n\t\t// offered a retry of a request that already got a meaningful answer.\n\t\tthrow new LankaError({\n\t\t\tkind: \"http\",\n\t\t\tmessage: getLankaHost().httpErrorMessage(response.status),\n\t\t\tstatus: response.status,\n\t\t});\n\t}\n}\n","import type { ILankaTransport } from \"../_interfaces/ILankaTransport\";\nimport type { TLankaRequestInit } from \"../_types/TLankaRequestInit\";\n\n/** What an unencoded body is sent as, and the header that says so. */\nconst CONTENT_TYPE = \"content-type\";\nconst JSON_CONTENT_TYPE = \"application/json\";\n\n/**\n * The network seam: `fetch`, plus the two things `fetch` cannot be told.\n *\n * ## Why there is ONE of these\n *\n * There were three — a plain one, a JSON one and a multipart one — and the split\n * was wrong at birth. `ILankaTransport` exists so a consumer can change the\n * PROTOCOL: a native bridge, a socket, a double that never leaves the process.\n * The three differed in a `content-type` header. That is not a protocol, it is an\n * encoding, and an encoding is a property of the CALL: a gateway with fourteen\n * JSON endpoints and one upload had no way to say so, because its request kind —\n * and with it its transport — was fixed in its constructor. The application that\n * hit this added a `useFormData` flag to its own options and wrote its own\n * transport to read it.\n *\n * So the encoding is decided here, per call, by looking at the body. A gateway\n * posts `FormData` to one endpoint and an object to the next, and neither it nor\n * the request kind has to know.\n *\n * ## What does NOT belong here\n *\n * The base URL (`ALankaGateway` prefixes `apiBaseUrl`), credentials, static\n * headers, CSRF, retry, auth refresh, idempotency keys and deadlines. Every one\n * of those is policy around a request rather than a way of sending one, and every\n * one is a middleware — `useRequestMiddleware`, which `@lankajs/plugin-http`\n * occupies. A transport that grew them would be a second composition mechanism\n * beside the one core already publishes, and \"where does a header get added\"\n * would have two answers.\n */\nexport class LankaFetchTransport implements ILankaTransport<TLankaRequestInit> {\n\tasync request(resource: RequestInfo, options?: TLankaRequestInit): Promise<Response> {\n\t\t// Nothing to encode: the object the caller assembled reaches `fetch`\n\t\t// unchanged, `undefined` included. \"No options\" and \"empty options\" are\n\t\t// different statements and `fetch` is entitled to tell them apart.\n\t\tif (options === undefined || options.body === undefined || options.body === null) {\n\t\t\treturn await fetch(resource, options as RequestInit | undefined);\n\t\t}\n\n\t\tconst { body, headers } = options;\n\n\t\t// Multipart: the header is REMOVED, not set. The boundary is generated with\n\t\t// the body, and a hand-written `content-type` carries none — the server then\n\t\t// reads zero fields out of a request that looks correct.\n\t\tif (isFormData(body)) {\n\t\t\tif (headers === undefined) return await fetch(resource, options as RequestInit);\n\n\t\t\tconst stripped = new Headers(headers);\n\t\t\tstripped.delete(CONTENT_TYPE);\n\t\t\treturn await fetch(resource, { ...options, headers: stripped } as RequestInit);\n\t\t}\n\n\t\t// Already something `fetch` understands: untouched.\n\t\tif (isEncodedBody(body)) return await fetch(resource, options as RequestInit);\n\n\t\treturn await fetch(resource, {\n\t\t\t...options,\n\t\t\theaders: withJsonContentType(headers),\n\t\t\tbody: JSON.stringify(body),\n\t\t});\n\t}\n}\n\n/**\n * The header set, with `content-type` filled in only if the caller left it out.\n *\n * Not overwritten: `application/merge-patch+json` and `application/ld+json` are\n * JSON that a server distinguishes, and a transport that flattened them to\n * `application/json` would turn a PATCH into a request the server refuses — for\n * a header the caller had already written correctly.\n */\nfunction withJsonContentType(headers: HeadersInit | undefined): Headers {\n\tconst result = new Headers(headers);\n\tif (!result.has(CONTENT_TYPE)) result.set(CONTENT_TYPE, JSON_CONTENT_TYPE);\n\treturn result;\n}\n\n/**\n * Whether `fetch` can already send this body.\n *\n * Every global here is guarded by `typeof`: core runs in node and React Native\n * as well as a browser, and `ReadableStream` in particular is absent on engines\n * this framework supports. An unguarded `instanceof` against a missing global is\n * a `ReferenceError` on the first request, from a transport, in production.\n *\n * Cheapest and most common first. A string — an already-serialised body — stops\n * on line one.\n */\nfunction isEncodedBody(body: unknown): body is BodyInit {\n\tif (typeof body === \"string\") return true;\n\tif (typeof URLSearchParams !== \"undefined\" && body instanceof URLSearchParams) return true;\n\tif (typeof Blob !== \"undefined\" && body instanceof Blob) return true;\n\tif (body instanceof ArrayBuffer || ArrayBuffer.isView(body)) return true;\n\treturn typeof ReadableStream !== \"undefined\" && body instanceof ReadableStream;\n}\n\n/**\n * Multipart, checked separately because it is the one body whose header is\n * removed rather than added.\n */\nfunction isFormData(body: unknown): body is FormData {\n\treturn typeof FormData !== \"undefined\" && body instanceof FormData;\n}\n","import { ALankaTransportRequest } from \"../_abstractions/lanka-transport-request/ALankaTransportRequest\";\nimport type { ILankaTransportRequestConfig } from \"../_abstractions/lanka-transport-request/ALankaTransportRequest\";\nimport type { TLankaRequestInit } from \"../../_types/TLankaRequestInit\";\nimport { LankaFetchTransport } from \"../../lanka-fetch-transport/LankaFetchTransport\";\nimport { LankaError } from \"../../../errors/lanka-error/LankaError\";\n\n/** The JSON request: parses the body, and refuses a body that is not JSON. */\n/**\n * A request kind that answers a parsed JSON body — what most endpoints return.\n *\n * A gateway holds one, and is handed it rather than constructing it, which is\n * what lets a test give the same gateway a transport that never leaves the\n * process. `createLankaFetchJsonRequest()` builds the same class.\n */\nexport class LankaFetchJsonRequest<\n\tTOptions extends TLankaRequestInit = TLankaRequestInit,\n> extends ALankaTransportRequest<TOptions> {\n\tconstructor(config: ILankaTransportRequestConfig<TOptions> = {}) {\n\t\tsuper(config, () => new LankaFetchTransport());\n\t}\n\n\t/**\n\t * Parses the body, or names the failure.\n\t *\n\t * The content type is read for the ERROR MESSAGE only. Using it to choose\n\t * between two parse paths, where the second answers `{}` for any non-empty\n\t * body it cannot parse, fails silently: the caller's schema is the first thing\n\t * to notice, and the caller's SCREEN is where it shows up.\n\t *\n\t * A measured case: a dev server whose `/api` fell through to the SPA fallback\n\t * answered `200 text/html` with `index.html`. Turned into `{}`, the schema\n\t * refused it and a person read a validator's issue list on the sign-in card. A\n\t * body a JSON transport cannot parse is never a value — it is a misrouted\n\t * request, and saying so names the actual failure.\n\t */\n\tprotected async parse<TReturn>(response: Response): Promise<TReturn> {\n\t\tconst contentType = response.headers.get(\"content-type\");\n\n\t\tconst text = await response.text();\n\t\tif (!text) {\n\t\t\treturn undefined as TReturn;\n\t\t}\n\n\t\ttry {\n\t\t\treturn JSON.parse(text) as TReturn;\n\t\t} catch (error) {\n\t\t\t// `schema`, not `network`: the request arrived, the server answered, and\n\t\t\t// the answer was the wrong shape. Not cosmetic — a network failure\n\t\t\t// invites a retry, while retrying a broken contract is pointless and\n\t\t\t// blaming the user for it more so.\n\t\t\tthrow new LankaError({\n\t\t\t\tkind: \"schema\",\n\t\t\t\tmessage:\n\t\t\t\t\t`Failed to parse JSON response (content-type: ${contentType ?? \"none\"}): ` +\n\t\t\t\t\t`${error instanceof Error ? error.message : String(error)}`,\n\t\t\t\tcause: error,\n\t\t\t});\n\t\t}\n\t}\n}\n","import { TLankaQueryParams } from \"../../_types/TLankaQueryParams\";\nimport { TLankaQueryBuilder } from \"../../_types/TLankaQueryBuilder\";\n\n/**\n * The query string a gateway sends, from the object a method was called with.\n *\n * Arrays become `key[]` repeated, nested objects become `key[inner]`: the shape\n * most JSON APIs read back without being told about it.\n *\n * Plain loops over `Object.keys` rather than `Object.entries` and `forEach`: this\n * runs on every request that carries a filter, and the pair array `entries`\n * builds — two allocations per key, thrown away immediately — is a cost with\n * nothing to show for it.\n */\nexport const buildLankaQueryParams: TLankaQueryBuilder = <T extends Record<string, unknown>>(\n\tinput: T,\n): URLSearchParams => {\n\tconst params = new URLSearchParams();\n\n\tconst append = (key: string, value: TLankaQueryParams): void => {\n\t\tif (value == null) return;\n\n\t\tif (Array.isArray(value)) {\n\t\t\t// The bracketed key once for the whole array, not once per element.\n\t\t\tconst itemKey = `${key}[]`;\n\t\t\tfor (let index = 0; index < value.length; index += 1) append(itemKey, value[index]);\n\n\t\t\treturn;\n\t\t}\n\n\t\tif (typeof value === \"object\") {\n\t\t\tconst inner = value as Record<string, TLankaQueryParams>;\n\t\t\tconst innerKeys = Object.keys(inner);\n\n\t\t\tfor (let index = 0; index < innerKeys.length; index += 1) {\n\t\t\t\tconst innerKey = innerKeys[index];\n\t\t\t\tappend(`${key}[${innerKey}]`, inner[innerKey]);\n\t\t\t}\n\n\t\t\treturn;\n\t\t}\n\n\t\tparams.append(key, String(value));\n\t};\n\n\tconst source = input as Record<string, TLankaQueryParams>;\n\tconst keys = Object.keys(source);\n\n\tfor (let index = 0; index < keys.length; index += 1) append(keys[index], source[keys[index]]);\n\n\treturn params;\n};\n","import type { TLankaRequestInit } from \"../../_types/TLankaRequestInit\";\nimport type { IALankaGatewayConfig } from \"../../_interfaces/IALankaGatewayConfig\";\nimport { lankaLogger } from \"../../../logger/lanka-logger/LankaLogger\";\nimport { LankaFetchJsonRequest } from \"../../request/lanka-fetch-json-request/LankaFetchJsonRequest\";\nimport type { ILankaRequest } from \"../../_interfaces/ILankaRequest\";\nimport type { TLankaExecuteOptions } from \"../../_types/TLankaExecuteOptions\";\nimport { buildLankaQueryParams } from \"../../_utils/build-lanka-query-params/buildLankaQueryParams\";\nimport { TLankaQueryParams } from \"../../_types/TLankaQueryParams\";\nimport { TLankaQueryBuilder } from \"../../_types/TLankaQueryBuilder\";\nimport { getLankaFlags } from \"../../../config/get-lanka-flags/getLankaFlags\";\nimport { getLankaHost } from \"../../../config/get-lanka-host/getLankaHost\";\nimport { lankaStandardValidator } from \"../../../validation/lanka-standard-validator/lankaStandardValidator\";\nimport type { ILankaValidator } from \"../../../validation/lanka-standard-validator/lankaStandardValidator\";\n\nexport abstract class ALankaGateway<TOptions = TLankaRequestInit> {\n\tprotected requestExecutor: ILankaRequest<TOptions>;\n\tprotected queryParamsHandler: TLankaQueryBuilder;\n\n\t/**\n\t * The validator a method checks a response body with.\n\t *\n\t * `config.validationService` when one was given, the Standard Schema port\n\t * otherwise. It used to be accepted by the config and read by nothing: a\n\t * consumer handing a test double to the gateway got the real validator and no\n\t * error, which is the worst kind of ignored option — it looks honoured.\n\t */\n\tprotected readonly validationService: ILankaValidator;\n\n\tprotected readonly useMock: boolean;\n\tprotected readonly basePath: string;\n\n\tprotected constructor(config: IALankaGatewayConfig<TOptions>) {\n\t\tlankaLogger.printGatewayLog(\"Create gateway\", this);\n\t\tconst flags = getLankaFlags();\n\t\tthis.useMock = config.useMock ?? flags.isMockMode ?? false;\n\t\tthis.validationService = config.validationService ?? lankaStandardValidator;\n\n\t\t// A gateway with nothing said about transport talks JSON over `fetch`, which\n\t\t// is what almost every one of them does. Supplying a request is how a gateway\n\t\t// stops being ordinary — a raw `Response`, a multipart upload, a transport\n\t\t// that never leaves the process — and that stays a decision rather than a\n\t\t// line every gateway has to carry to be born.\n\t\t// The cast covers the FRAMEWORK picking its own fallback, and nothing a\n\t\t// consumer does. `TOptions` is unconstrained here on purpose — a gateway may\n\t\t// front a request that never speaks HTTP, and the port promises exactly that\n\t\t// — so the JSON default cannot be proven to fit a `TOptions` nobody has\n\t\t// named yet. A consumer whose options are not fetch-shaped supplies\n\t\t// `request`, and this line never runs for them.\n\t\tthis.requestExecutor = config.request ?? new LankaFetchJsonRequest();\n\n\t\tthis.basePath = config.basePath ?? \"\";\n\t\tthis.queryParamsHandler = config.queryParamsHandler ?? buildLankaQueryParams;\n\t}\n\n\t/**\n\t * Resolves endpoint for request.\n\t * - Absolute paths (starting with \"/\") are returned as-is\n\t * - Relative paths are joined with basePath\n\t * - Query-only strings like \"?a=1\" are attached to basePath\n\t */\n\tprotected endpoint(path: string = \"\"): string {\n\t\t// An absolute URL is detected BEFORE joining with `basePath`, not after:\n\t\t// otherwise `https://other.host/health` first becomes\n\t\t// `/things/https://other.host/health` and there is nothing left to detect.\n\t\tif (isAbsoluteUrl(path)) return path;\n\n\t\t// A path already under the base is one this method produced, and it is\n\t\t// returned as it is: `endpoint()` is idempotent. `request()` resolves\n\t\t// through `endpoint()`, and every gateway in the guide hands it\n\t\t// `this.endpoint(…)`, so each call resolves twice. An absolute base hides\n\t\t// that — the first pass makes an absolute URL — and a RELATIVE one (`/api`)\n\t\t// sent every request to `/api/api/…` (issue #7).\n\t\t//\n\t\t// Decided on the INPUT, before `basePath` is joined, and not on the joined\n\t\t// result: a gateway whose `basePath` happens to start with the base's\n\t\t// segment then resolves exactly as it always did, and only an argument that\n\t\t// already carries the base is left alone. The one reading given up: a path\n\t\t// written as `/api/x` under a base of `/api` means `/api/x`.\n\t\tconst base = withoutTrailingSlashes(getLankaHost().apiBaseUrl);\n\t\tif (base && isUnder(path, base)) return path;\n\n\t\treturn withApiBase(base, this.resolvePath(path));\n\t}\n\n\t/**\n\t * Joins `basePath` and the method path.\n\t */\n\tprivate resolvePath(path: string): string {\n\t\tif (!path) return this.basePath;\n\n\t\tif (path.startsWith(\"/\")) return path;\n\n\t\tif (path.startsWith(\"?\")) return `${this.basePath}${path}`;\n\n\t\t// No leading-slash case here: the check above already returned for one, so\n\t\t// stripping it again was a branch no input could take — uncoverable by\n\t\t// construction, and it counted against the coverage floor that gates this\n\t\t// package.\n\t\tconst left = this.basePath.endsWith(\"/\") ? this.basePath.slice(0, -1) : this.basePath;\n\t\treturn `${left}/${path}`;\n\t}\n\n\tprotected buildQueryParams<T extends object>(params: T): URLSearchParams {\n\t\treturn this.queryParamsHandler(params as Record<string, TLankaQueryParams>);\n\t}\n\n\tprotected async request<TReturn = unknown>(\n\t\tpath: string,\n\t\toptions?: TLankaExecuteOptions<TOptions>,\n\t\tmockHandler?: () => Promise<TReturn>,\n\t): Promise<TReturn> {\n\t\treturn this.requestExecutor.execute<TReturn>(this.endpoint(path), options, mockHandler);\n\t}\n\n\t/**\n\t * Allows to replace request implementation at runtime (e.g. feature flags / tests).\n\t * If you prefer static customization - override `request()` in a subclass.\n\t */\n\tprotected setRequest(request: ILankaRequest<TOptions>): void {\n\t\tthis.requestExecutor = request;\n\t}\n\n\tprotected setQueryParamsHandler(handler: TLankaQueryBuilder): void {\n\t\tthis.queryParamsHandler = handler;\n\t}\n}\n\n/**\n * A scheme plus `//` — a URL that already knows where it is going.\n *\n * A standalone function rather than a method: it is not about a particular\n * gateway, and `endpoint()` needs it before any joining.\n */\nfunction isAbsoluteUrl(path: string): boolean {\n\t// The cheap half first: a scheme needs `://`, and `includes` answers without\n\t// starting the regex engine. Every relative path an application writes — which\n\t// is nearly all of them — stops on this line.\n\tif (!path.includes(\"://\")) return false;\n\n\treturn /^[a-z][a-z\\d+\\-.]*:\\/\\//i.test(path);\n}\n\n/**\n * Prefixes the API base URL from the host contract.\n *\n * Here rather than in every consumer: otherwise each consumer knows the URL\n * and the framework does not, and a realtime plugin would have to know a\n * specific application's build.\n *\n * Declaring the field and not using it would be worse than not declaring it: a\n * declaration nothing is built from is a second truth, free to diverge from\n * the first.\n *\n * An absolute URL never reaches here — `endpoint()` filters it out before the\n * join. The base is passed in rather than read: `endpoint()` has already read\n * it, and the host is not asked twice per request.\n */\nfunction withApiBase(base: string, path: string): string {\n\tif (!base) return path;\n\tif (!path) return base;\n\n\treturn path.startsWith(\"/\") ? `${base}${path}` : `${base}/${path}`;\n}\n\n/**\n * The base itself, or a path below it — compared as a whole segment.\n *\n * `/api-keys` starts with `/api` and is not under it; a bare `startsWith` would\n * take it for already-prefixed and drop the base from a real request.\n */\nfunction isUnder(path: string, base: string): boolean {\n\tif (!path.startsWith(base)) return false;\n\n\tconst next = path.charAt(base.length);\n\treturn next === \"\" || next === \"/\" || next === \"?\";\n}\n\n/**\n * The API base without its trailing slashes, remembered between calls.\n *\n * The host answers the same string for the life of an application, and trimming\n * it is a regex replace otherwise run on every endpoint of every request. One\n * entry is enough: there is one active host, and a second framework in the same\n * process simply replaces what is remembered here.\n */\nlet lastRawBase: string | null = null;\nlet lastTrimmedBase = \"\";\n\nfunction withoutTrailingSlashes(base: string): string {\n\tif (base !== lastRawBase) {\n\t\tlastRawBase = base;\n\t\tlastTrimmedBase = base.replace(/\\/+$/, \"\");\n\t}\n\n\treturn lastTrimmedBase;\n}\n","import { ALankaGateway } from \"../../_abstractions/lanka-gateway/ALankaGateway\";\nimport type { IALankaGatewayConfig } from \"../../_interfaces/IALankaGatewayConfig\";\nimport type { ILankaGatewayContext } from \"../../_interfaces/ILankaGatewayContext\";\n\n/** What a gateway is built from, whichever style builds it. */\nexport interface ILankaGatewayConfig<\n\tTOptions,\n\tTMethods extends object,\n> extends IALankaGatewayConfig<TOptions> {\n\t/** The endpoints this gateway offers, written over its own surface. */\n\tmethods: (context: ILankaGatewayContext<TOptions>) => TMethods;\n}\n\n/**\n * A gateway, without writing a class.\n *\n * The bridge below is the whole mechanism, and it lives here rather than on the\n * base for two reasons. The language reads `protected` from inside a deriving\n * class body and nowhere else, so a factory outside the hierarchy could only\n * reach the public half — the wrong one. And a `toStyleContext` ON the base\n * would put `TOptions` in a method's parameter position, making the class\n * invariant in it: every `ALankaGateway<unknown>` the locator holds would stop\n * accepting a gateway typed for `RequestInit`.\n *\n * One implementation: what comes back is an instance of `ALankaGateway`, so a\n * behaviour fix reaches both styles at once.\n */\nexport const createLankaGateway = <TOptions, TMethods extends object>(\n\tconfig: ILankaGatewayConfig<TOptions, TMethods>,\n): TMethods => {\n\tclass FunctionalGateway extends ALankaGateway<TOptions> {\n\t\t// The base keeps a protected constructor — it is abstract, and a consumer\n\t\t// reaching for `new ALankaGateway()` would get an object with no endpoints.\n\t\t// A subclass may widen it, and this one is the subclass.\n\t\tpublic constructor(gatewayConfig: IALankaGatewayConfig<TOptions>) {\n\t\t\tsuper(gatewayConfig);\n\t\t}\n\n\t\tpublic build(): TMethods {\n\t\t\treturn config.methods({\n\t\t\t\tendpoint: (path) => this.endpoint(path),\n\t\t\t\trequest: (path, options, mockHandler) => this.request(path, options, mockHandler),\n\t\t\t\tbuildQueryParams: (params) => this.buildQueryParams(params),\n\t\t\t\tvalidationService: this.validationService,\n\t\t\t});\n\t\t}\n\t}\n\n\treturn new FunctionalGateway(config).build();\n};\n","import { ALankaTransportRequest } from \"../_abstractions/lanka-transport-request/ALankaTransportRequest\";\nimport type { ILankaTransportRequestConfig } from \"../_abstractions/lanka-transport-request/ALankaTransportRequest\";\nimport type { TLankaRequestInit } from \"../../_types/TLankaRequestInit\";\nimport { LankaFetchTransport } from \"../../lanka-fetch-transport/LankaFetchTransport\";\n\n/**\n * The raw request: hands the `Response` back untouched.\n *\n * The minimal, extensible case — a caller wanting headers, a stream, a blob or a\n * `204` reads them off the response itself. Multipart uploads come through here\n * too: the transport encodes by looking at the body, so posting a `FormData` and\n * posting an object are the same call.\n *\n * `TOptions` is CONSTRAINED to fetch options rather than merely defaulted to\n * them. A consumer widening it — their own `interface IRequestOptions extends\n * TLankaRequestInit` — still gets the shipped transport, because the constraint\n * is what lets the framework hand one over without a cast. Unconstrained, the\n * assignment did not typecheck and core cast its way past it; the cast worked\n * here and was unavailable to the consumer, who wrote a transport instead.\n */\nexport class LankaFetchRequest<\n\tTOptions extends TLankaRequestInit = TLankaRequestInit,\n> extends ALankaTransportRequest<TOptions> {\n\tconstructor(config: ILankaTransportRequestConfig<TOptions> = {}) {\n\t\tsuper(config, () => new LankaFetchTransport());\n\t}\n\n\tprotected parse<TReturn>(response: Response): Promise<TReturn> {\n\t\treturn Promise.resolve(response as unknown as TReturn);\n\t}\n}\n","import { LankaFetchRequest } from \"../../lanka-fetch-request/LankaFetchRequest\";\nimport type { ILankaTransportRequestConfig } from \"../../_abstractions/lanka-transport-request/ALankaTransportRequest\";\nimport type { TLankaRequestInit } from \"../../../_types/TLankaRequestInit\";\n\n/**\n * The functional style of `LankaFetchRequest`: the raw `Response`, for a download or a stream.\n *\n * One line, and that is the point — the factory IS the class, so a behaviour\n * cannot exist in one style and not the other.\n */\nexport const createLankaFetchRequest = <TOptions extends TLankaRequestInit = TLankaRequestInit>(\n\tconfig: ILankaTransportRequestConfig<TOptions> = {},\n): LankaFetchRequest<TOptions> => new LankaFetchRequest<TOptions>(config);\n","import { LankaFetchJsonRequest } from \"../../lanka-fetch-json-request/LankaFetchJsonRequest\";\nimport type { ILankaTransportRequestConfig } from \"../../_abstractions/lanka-transport-request/ALankaTransportRequest\";\nimport type { TLankaRequestInit } from \"../../../_types/TLankaRequestInit\";\n\n/**\n * The functional style of `LankaFetchJsonRequest`: a JSON body, which is what most endpoints answer.\n *\n * One line, and that is the point — the factory IS the class, so a behaviour\n * cannot exist in one style and not the other.\n */\nexport const createLankaFetchJsonRequest = <TOptions extends TLankaRequestInit = TLankaRequestInit>(\n\tconfig: ILankaTransportRequestConfig<TOptions> = {},\n): LankaFetchJsonRequest<TOptions> => new LankaFetchJsonRequest<TOptions>(config);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAeA,IAAM,cAAgC,OAAO,OAAO;AAAA,EACnD,QAAQ;AAAA,EACR,UAAU,MAAM;AAAA,EAChB,WAAW,MAAM;AAAA,EACjB,SAAS,MAAM;AAChB,CAAC;AAMD,IAAM,eAAe,MACpB,OAAO,aAAa,eAAe,SAAS,oBAAoB;AAkBjE,SAAS,sBAAsB,WAAmB,UAAwC;AACzF,MAAI,cAAc;AAClB,MAAI,YAAY;AAChB,MAAI;AACJ,MAAI,UAAU;AAEd,QAAM,QAAQ,MAAY;AACzB,QAAI,UAAU,OAAW;AACz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AAA,QACrB,UAAU,CAAC,SAAS,KAAK,SAAS,IAAI;AAAA,QACtC,SAAS,CAAC,MAAM,SAAS,gBAAgB,KAAK,QAAQ,MAAM,SAAS,WAAW;AAAA,QAChF,kBAAkB,CAAC,WAAW,KAAK,iBAAiB,MAAM;AAAA,QAC1D,mBAAmB,KAAK;AAAA,MACzB,CAAC;AAAA,IACF;AAAA,EACD;AAEA,SAAO,IAAI,kBAAkB,MAAM,EAAE,MAAM;AAC5C;;;AC7BO,IAAM,oBAAN,cAEG,uBAAiC;AAAA,EAC1C,YAAY,SAAiD,CAAC,GAAG;AAChE,UAAM,QAAQ,MAAM,IAAI,oBAAoB,CAAC;AAAA,EAC9C;AAAA,EAEU,MAAe,UAAsC;AAC9D,WAAO,QAAQ,QAAQ,QAA8B;AAAA,EACtD;AACD;;;ACpBO,IAAM,0BAA0B,CACtC,SAAiD,CAAC,MACjB,IAAI,kBAA4B,MAAM;;;ACFjE,IAAM,8BAA8B,CAC1C,SAAiD,CAAC,MACb,IAAI,sBAAgC,MAAM;","names":[]}
package/dist/index.d.ts CHANGED
@@ -1,23 +1,23 @@
1
- export { I as ILankaBootstrapConfig, a as ILankaInstance, b as ILankaInstanceConfig, c as ILankaPlugin, d as ILankaScenarioBootstrapConfig, e as ILankaServiceConfig, f as createLanka } from './createLanka-AuiMfPL9.js';
1
+ export { I as ILankaBootstrapConfig, a as ILankaInstance, b as ILankaInstanceConfig, c as ILankaPlugin, d as ILankaScenarioBootstrapConfig, e as ILankaServiceConfig, f as createLanka } from './createLanka-XbyOz9ld.js';
2
2
  export { ALankaPlugin, ILankaStartOptions, TLankaStartConfig, resetActiveLanka, startLanka } from './bootstrap/index.js';
3
3
  export { ILankaRoleFactory, ILankaRoleOpening, TLankaRoleOpener, defineLankaRole } from './role/index.js';
4
4
  export { ILankaHostConfig, createLankaHost, getLankaFlags, getLankaHost } from './config/index.js';
5
5
  export { I as ILankaFlags, a as ILankaHost, b as ILankaRuntimeConfig } from './ILankaRuntimeConfig-Vl436GWK.js';
6
6
  export { I as ILankaLocatorConfig } from './ALankaLocator-BUCCz0Q5.js';
7
7
  export { lankaLogger } from './logger/index.js';
8
- export { I as ILankaErrorInit, L as LankaError, T as TLankaErrorKind } from './LankaError-D6RWNyLM.js';
8
+ export { I as ILankaErrorInit, L as LankaError, T as TLankaErrorKind } from './LankaError-CfDmuGKc.js';
9
9
  import './createLankaScope-DeElRH-E.js';
10
10
  import './LankaScenarioVMRegistry-CFzCpIFd.js';
11
11
  import './ILankaScenarioVM-DKwjbIRq.js';
12
12
  import './locator/singleton/lanka-singleton-locator/LankaSingletonLocator.js';
13
- import './activeRuntime-DxB62KN4.js';
13
+ import './activeRuntime-1Zj2m1Sx.js';
14
14
  import './ILankaScenario-7J3MoKiY.js';
15
15
  import './LankaScenariosRegistry-DiLN9xwy.js';
16
16
  import './ILankaScenarioMetadata-DgOxvpwx.js';
17
17
  import './lankaHttpInFlight-Bk1eIuSx.js';
18
- import './lankaRequestMiddleware-DAC5kCb7.js';
18
+ import './lankaRequestMiddleware-CbXc1PAV.js';
19
19
  import './locator/gateway/lanka-gateway-locator/LankaGatewayLocator.js';
20
- import './ALankaGateway-CzBISB0L.js';
20
+ import './ALankaGateway-CQrEPUHM.js';
21
21
  import './lankaStandardValidator-BUFnysK0.js';
22
22
  import '@standard-schema/spec';
23
23
  import './ILankaFieldError-D5931-vT.js';
package/dist/index.js CHANGED
@@ -3,11 +3,11 @@ import {
3
3
  createLanka,
4
4
  resetActiveLanka,
5
5
  startLanka
6
- } from "./chunk-JLBSXJRX.js";
6
+ } from "./chunk-YEP54YU5.js";
7
7
  import "./chunk-M4BK6GBV.js";
8
+ import "./chunk-24MUFFHF.js";
8
9
  import "./chunk-3R2NO47A.js";
9
10
  import "./chunk-BMF4TM2Z.js";
10
- import "./chunk-24MUFFHF.js";
11
11
  import "./chunk-JZJ6GXX3.js";
12
12
  import "./chunk-EH5WZSRJ.js";
13
13
  import "./chunk-N3275IPH.js";
@@ -19,7 +19,7 @@ import {
19
19
  import "./chunk-NMFNEVNE.js";
20
20
  import {
21
21
  LankaError
22
- } from "./chunk-G32H73QY.js";
22
+ } from "./chunk-INHAKVSO.js";
23
23
  import {
24
24
  getLankaHost
25
25
  } from "./chunk-JGJBFELR.js";
@@ -18,7 +18,9 @@ interface ILankaRequestContext {
18
18
  */
19
19
  readonly attempt: number;
20
20
  /**
21
- * This attempt's deadline, when middleware assigned one.
21
+ * This attempt's deadline, when middleware assigned one. It stops while the
22
+ * page is seen hidden — a frozen WebView runs no timers — and resumes when it
23
+ * shows.
22
24
  *
23
25
  * Read by CORE before every call into the transport, which is what allows a
24
26
  * deadline per request class: a file upload and a list read cannot share one
@@ -1,4 +1,4 @@
1
- import { A as ALankaGateway } from '../../../ALankaGateway-CzBISB0L.js';
1
+ import { A as ALankaGateway } from '../../../ALankaGateway-CQrEPUHM.js';
2
2
  import { A as ALankaLocator } from '../../../ALankaLocator-BUCCz0Q5.js';
3
3
  import '../../../lankaStandardValidator-BUFnysK0.js';
4
4
  import '@standard-schema/spec';
@@ -1,7 +1,7 @@
1
1
  export { I as ILankaScope } from '../createLankaScope-DeElRH-E.js';
2
2
  export { a as ILankaLocator, I as ILankaLocatorConfig } from '../ALankaLocator-BUCCz0Q5.js';
3
3
  import * as GatewaysModule from '@lanka_di/Gateways';
4
- import { A as ALankaGateway } from '../ALankaGateway-CzBISB0L.js';
4
+ import { A as ALankaGateway } from '../ALankaGateway-CQrEPUHM.js';
5
5
  import * as ScenariosModule from '@lanka_di/Scenarios';
6
6
  import * as SingletonsModule from '@lanka_di/Singletons';
7
7
  export { ILankaSingletonLocatorConfig } from './singleton/lanka-singleton-locator/LankaSingletonLocator.js';
@@ -1,18 +1,18 @@
1
- import { c as ILankaPlugin } from '../createLanka-AuiMfPL9.js';
1
+ import { c as ILankaPlugin } from '../createLanka-XbyOz9ld.js';
2
2
  import '../createLankaScope-DeElRH-E.js';
3
3
  import '../LankaScenarioVMRegistry-CFzCpIFd.js';
4
4
  import '../ILankaScenarioVM-DKwjbIRq.js';
5
5
  import '../locator/singleton/lanka-singleton-locator/LankaSingletonLocator.js';
6
6
  import '../ALankaLocator-BUCCz0Q5.js';
7
- import '../activeRuntime-DxB62KN4.js';
7
+ import '../activeRuntime-1Zj2m1Sx.js';
8
8
  import '../ILankaScenario-7J3MoKiY.js';
9
9
  import '../LankaScenariosRegistry-DiLN9xwy.js';
10
10
  import '../ILankaScenarioMetadata-DgOxvpwx.js';
11
11
  import '../ILankaRuntimeConfig-Vl436GWK.js';
12
12
  import '../lankaHttpInFlight-Bk1eIuSx.js';
13
- import '../lankaRequestMiddleware-DAC5kCb7.js';
13
+ import '../lankaRequestMiddleware-CbXc1PAV.js';
14
14
  import '../locator/gateway/lanka-gateway-locator/LankaGatewayLocator.js';
15
- import '../ALankaGateway-CzBISB0L.js';
15
+ import '../ALankaGateway-CQrEPUHM.js';
16
16
  import '../lankaStandardValidator-BUFnysK0.js';
17
17
  import '@standard-schema/spec';
18
18
  import '../ILankaFieldError-D5931-vT.js';
@@ -1,5 +1,5 @@
1
1
  export { I as ILankaValidator, T as TLankaSchema, a as TLankaValidationResult, l as lankaStandardValidator } from '../lankaStandardValidator-BUFnysK0.js';
2
- import { L as LankaError } from '../LankaError-D6RWNyLM.js';
2
+ import { L as LankaError } from '../LankaError-CfDmuGKc.js';
3
3
  import { I as ILankaFieldError } from '../ILankaFieldError-D5931-vT.js';
4
4
  import '@standard-schema/spec';
5
5
 
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  lankaStandardValidator
3
- } from "../chunk-HVSQOMRE.js";
3
+ } from "../chunk-BIJTUWUD.js";
4
4
  import {
5
5
  LankaValidationError
6
- } from "../chunk-CRIRTOLB.js";
7
- import "../chunk-G32H73QY.js";
6
+ } from "../chunk-VI4DY5PN.js";
7
+ import "../chunk-INHAKVSO.js";
8
8
  export {
9
9
  LankaValidationError,
10
10
  lankaStandardValidator
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lanka",
3
- "version": "2.2.2",
3
+ "version": "2.3.0",
4
4
  "type": "module",
5
5
  "description": "core: Fourteen subsystems, one peer dependency, six extension points.",
6
6
  "license": "MIT",
@@ -5,7 +5,7 @@ license: MIT
5
5
  metadata:
6
6
  author: lankajs
7
7
  package: lanka
8
- version: "2.2.2"
8
+ version: "2.3.0"
9
9
  ---
10
10
 
11
11
  # lanka — core
@@ -213,6 +213,10 @@ without touching a screen.
213
213
 
214
214
  `LankaError` carries a kind: `network` · `timeout` · `aborted` · `http` ·
215
215
  `schema` · `domain`. Branch on it. `aborted` is shown to nobody — the user left.
216
+ `isFromBackground` marks a `network` or `aborted` failure of an attempt during
217
+ which the page hid or unloaded — on a mobile WebView, usually the platform cutting
218
+ a frozen request. Segment telemetry by it; do not drop it. Request deadlines
219
+ stop while the app is in the background, so a `timeout` is real slowness.
216
220
 
217
221
  Refuse locally with the same shape rather than a bare throw:
218
222
  `Promise.reject(createLankaApiError(400, ["a search needs a term"]))`.
@@ -292,16 +296,16 @@ decides. Resetting the form erases what they were typing.
292
296
 
293
297
  ## Symptom → cause
294
298
 
295
- | What you see | What it is |
296
- | --------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------- |
297
- | a scenario handler never fires | `lanka.bootstrap()` was never awaited, or the ViewModel was built after it |
298
- | a locator name resolves to a refusal | registered after construction, or never registered |
299
- | the screen freezes with no error | a key read through a getter, past the tracking proxy — set `enableAccessTrackingOptimization: false` on that ViewModel |
300
- | "module not found" for `@lanka_di/…` | `@lankajs/tool-di` is not installed, or the alias is missing |
301
- | a test sees another test's events | the instance was replaced without `dispose()` — use `resetLanka()` |
302
- | "lanka used before an instance existed", only in a BUILT bundle | a ViewModel read the locator while its own module was evaluated, ahead of `createLanka` — declare `scenarioHandlers` as a factory (below) |
299
+ | What you see | What it is |
300
+ | --------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- |
301
+ | a scenario handler never fires | `lanka.bootstrap()` was never awaited, or the ViewModel was built after it |
302
+ | a locator name resolves to a refusal | registered after construction, or never registered |
303
+ | the screen freezes with no error | a key read through a getter, past the tracking proxy — set `enableAccessTrackingOptimization: false` on that ViewModel |
304
+ | "module not found" for `@lanka_di/…` | `@lankajs/tool-di` is not installed, or the alias is missing |
305
+ | a test sees another test's events | the instance was replaced without `dispose()` — use `resetLanka()` |
306
+ | "lanka used before an instance existed", only in a BUILT bundle | a ViewModel read the locator while its own module was evaluated, ahead of `createLanka` — declare `scenarioHandlers` as a factory (below) |
303
307
  | "…ran in another evaluation of lanka", after upgrading lanka | the open page kept the old lanka and a module loaded since got the new files — reload the page; restart the dev server if it pre-bundles nothing of lanka |
304
- | "one was active in this copy and has been cleared" | a timer, a subscription or a request outlived `dispose()` — or the next instance was never created and activated |
308
+ | "one was active in this copy and has been cleared" | a timer, a subscription or a request outlived `dispose()` — or the next instance was never created and activated |
305
309
 
306
310
  Do **not** fix the frozen screen by destructuring a value "for the side effect":
307
311
  it reads as dead code and the next refactor deletes it.
@@ -1,6 +1,6 @@
1
1
  <!-- Generated from core/GUIDE.md by scripts/skills.mjs. Edit the guide. -->
2
2
 
3
- > **`lanka@2.2.2`** — this document describes that version.
3
+ > **`lanka@2.3.0`** — this document describes that version.
4
4
  >
5
5
  > Install: `npm install lanka zustand` (the peers are not optional; only npm adds a missing one for you).
6
6
  >
@@ -459,6 +459,25 @@ its own timer into one signal and still tells the two apart: a timed-out request
459
459
  raises `timeout` and is shown to the user, a caller-aborted one raises `aborted`
460
460
  and stays silent, because the user has already left.
461
461
 
462
+ **The deadline stops while the app is in the background.** A mobile WebView is
463
+ frozen when the user leaves it — an external link, an app switch, a locked
464
+ screen — and timers do not run while it is; an overdue timer fires at once on
465
+ resume. A plain timer therefore reported `timeout` for a request that was never
466
+ slow. Now, when the page is SEEN to hide during the attempt (`visibilitychange`
467
+ to `"hidden"`, or `pagehide`), the deadline pauses, and the rest runs when the
468
+ page shows again. A page already hidden when the request starts runs its clock
469
+ as before — some WebViews report `hidden` from load and never change it. Where
470
+ there is no `document` (Node, SSR, React Native) nothing changes. A request in a
471
+ desktop tab that is switched away from mid-flight is paused the same way.
472
+
473
+ **A failure says whether the app went to the background.** `error.isFromBackground`
474
+ is `true` on a `network` or `aborted` failure that core tagged, of an attempt
475
+ during which the page was seen to hide or unload. It tells WHEN, not why: on a
476
+ mobile WebView the platform usually cut the request; on a desktop tab the server
477
+ may just as well have failed. Segment your error telemetry by it rather than
478
+ dropping what it marks. It is never set on a `timeout` — the deadline already
479
+ stops in the background, so a timeout is real slowness.
480
+
462
481
  ### Counting requests in flight
463
482
 
464
483
  ```ts
@@ -5,7 +5,7 @@ license: MIT
5
5
  metadata:
6
6
  author: lankajs
7
7
  package: lanka
8
- version: "2.2.2"
8
+ version: "2.3.0"
9
9
  ---
10
10
 
11
11
  # lanka — which package, and what it costs
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/errors/lanka-error/LankaError.ts"],"sourcesContent":["import type { ILankaApiError } from \"../_interfaces/ILankaApiError\";\nimport type { ILankaFieldError } from \"../_interfaces/ILankaFieldError\";\n\n/**\n * How a request ended.\n *\n * Six kinds rather than one, for one reason: each demands something DIFFERENT of\n * the interface. A distinction that implies no different behaviour is\n * superfluous, which is why there is no seventh.\n */\nexport type TLankaErrorKind =\n\t/** Never reached the server: dropped link, DNS failure, no network. Offer a retry. */\n\t| \"network\"\n\t/** Reached it; the response never came. Also a retry, but a different message. */\n\t| \"timeout\"\n\t/** Cancelled by the caller. Nothing to show: the user left. */\n\t| \"aborted\"\n\t/** The server answered with an error status; what to show depends on it. */\n\t| \"http\"\n\t/** A response arrived in the wrong shape. A break, not the user's fault. */\n\t| \"schema\"\n\t/** The server refused deliberately and named the reason. Show what it said. */\n\t| \"domain\";\n\nexport interface ILankaErrorInit {\n\tkind: TLankaErrorKind;\n\tmessage: string;\n\t/** HTTP status, when there was one. */\n\tstatus?: number;\n\t/** The domain failure code — what the application branches on. */\n\tcode?: string;\n\t/** Details: server messages, or paths to the fields that failed validation. */\n\tissues?: readonly string[];\n\t/**\n\t * The failures that have an input to be shown at, with the path in segments.\n\t *\n\t * Beside `issues` rather than instead of it: `issues` is the banner's list and\n\t * is promised; this is the form's, and a failure may have either, both or\n\t * neither. Absent means \"nothing here has an address\", not \"unknown\".\n\t */\n\tfields?: readonly ILankaFieldError[];\n\t/**\n\t * The parsed ERROR response body, when there was one and it was JSON.\n\t *\n\t * Travels with the error because a `Response` is read once: without this field\n\t * a plugin extracting the domain failure code would read an already-drained\n\t * stream and get nothing. Core does not look into the body; it carries it.\n\t */\n\tbody?: unknown;\n\t/** The original error, when this one wraps it. */\n\tcause?: unknown;\n}\n\n/**\n * One failure type for every layer of the framework.\n *\n * Without a tagged kind, an app cannot tell a network failure from a timeout,\n * from a broken schema, from a deliberate domain refusal — so it builds its own\n * error contract ON TOP of the framework, and builds it once per application.\n *\n * Implements `ILankaApiError`: `status` and `errors` are present, so code reading\n * them the old way keeps working.\n *\n * What is NOT here: parsing a particular response body format. Which JSON a\n * backend sends is policy, and policy lives in `@lankajs/plugin-http`. Core knows\n * only that it has a failure and must name its kind.\n */\nexport class LankaError extends Error implements ILankaApiError {\n\treadonly kind: TLankaErrorKind;\n\treadonly status?: number;\n\treadonly code?: string;\n\treadonly issues?: readonly string[];\n\t/**\n\t * The failures with an input to be shown at. See `ILankaErrorInit.fields`.\n\t *\n\t * The array given is the array kept — unlike `errors`, which copies `issues`\n\t * on every read. `readonly` carries the promise, and this is read on the way\n\t * to a form, once, where a copy would buy nothing.\n\t */\n\treadonly fields?: readonly ILankaFieldError[];\n\t/** The parsed error response body; core carries it without reading it. */\n\treadonly body?: unknown;\n\n\tconstructor(init: ILankaErrorInit) {\n\t\tsuper(init.message, init.cause === undefined ? undefined : { cause: init.cause });\n\t\tthis.name = \"LankaError\";\n\t\tthis.kind = init.kind;\n\t\tthis.status = init.status;\n\t\tthis.code = init.code;\n\t\tthis.issues = init.issues;\n\t\tthis.fields = init.fields;\n\t\tthis.body = init.body;\n\n\t\t// The prototype chain is pinned explicitly: without it `instanceof` breaks\n\t\t// for a consumer whose bundler downlevels to ES5, and breaks silently —\n\t\t// `catch` simply fails to recognise its own error.\n\t\tObject.setPrototypeOf(this, LankaError.prototype);\n\t}\n\n\t/** The `ILankaApiError` field. The details are the message list. */\n\tget errors(): string[] | undefined {\n\t\treturn this.issues ? [...this.issues] : undefined;\n\t}\n\n\t/**\n\t * Whether to show this to the user.\n\t *\n\t * A cancelled request is the one failure that must NOT be reported: its cause\n\t * is that the user left before the response, and a toast would catch them on\n\t * another screen.\n\t */\n\tget isSilent(): boolean {\n\t\treturn this.kind === \"aborted\";\n\t}\n\n\t/**\n\t * Recognises our error among others.\n\t *\n\t * Checks the name rather than `instanceof` alone: a consumer may end up with\n\t * two copies of the package — adjacent majors in the dependency tree — and\n\t * then `instanceof` answers `false` for an error that is ours by every other\n\t * sign.\n\t */\n\tstatic is(value: unknown): value is LankaError {\n\t\treturn (\n\t\t\tvalue instanceof LankaError || (value instanceof Error && value.name === \"LankaError\")\n\t\t);\n\t}\n}\n"],"mappings":";AAmEO,IAAM,aAAN,MAAM,oBAAmB,MAAgC;AAAA,EACtD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA;AAAA;AAAA,EAEA;AAAA,EAET,YAAY,MAAuB;AAClC,UAAM,KAAK,SAAS,KAAK,UAAU,SAAY,SAAY,EAAE,OAAO,KAAK,MAAM,CAAC;AAChF,SAAK,OAAO;AACZ,SAAK,OAAO,KAAK;AACjB,SAAK,SAAS,KAAK;AACnB,SAAK,OAAO,KAAK;AACjB,SAAK,SAAS,KAAK;AACnB,SAAK,SAAS,KAAK;AACnB,SAAK,OAAO,KAAK;AAKjB,WAAO,eAAe,MAAM,YAAW,SAAS;AAAA,EACjD;AAAA;AAAA,EAGA,IAAI,SAA+B;AAClC,WAAO,KAAK,SAAS,CAAC,GAAG,KAAK,MAAM,IAAI;AAAA,EACzC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,IAAI,WAAoB;AACvB,WAAO,KAAK,SAAS;AAAA,EACtB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,OAAO,GAAG,OAAqC;AAC9C,WACC,iBAAiB,eAAe,iBAAiB,SAAS,MAAM,SAAS;AAAA,EAE3E;AACD;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/gateway/request/lankaRequestMiddleware.ts"],"sourcesContent":["/**\n * What middleware knows about the request it wraps.\n *\n * `options` is deliberately `unknown`: every transport has its own —\n * `RequestInit` for fetch, something else for the next one. Core does not read\n * them, it passes them along.\n */\nexport interface ILankaRequestContext {\n\treadonly endpoint: string;\n\treadonly options: unknown;\n\t/**\n\t * Which attempt this is, counting from one.\n\t *\n\t * In the context rather than in the middleware itself, because a retry may be\n\t * started by someone other than the one counting: an auth refresh restarts the\n\t * request, and the retrying middleware must not mistake that for its own\n\t * second attempt.\n\t */\n\treadonly attempt: number;\n\t/**\n\t * This attempt's deadline, when middleware assigned one.\n\t *\n\t * Read by CORE before every call into the transport, which is what allows a\n\t * deadline per request class: a file upload and a list read cannot share one\n\t * value, and the policy knows that difference while the framework does not.\n\t */\n\treadonly timeoutMs?: number;\n}\n\n/**\n * A wrapper around a request.\n *\n * ## A wrapper rather than `onRequest` / `onResponse` / `onError`\n *\n * Three hooks cannot express RETRY. `onError` can replace an error but cannot\n * run the request again — and retry plus auth refresh are the two main abilities\n * a request-policy plugin exists for. A wrapper expresses those and everything\n * the hooks expressed.\n *\n * ## Why the objection to `next()` does not carry over\n *\n * On the event bus, middleware that skips `next` SILENCES the event: subscribers\n * do not run and nothing records it. Here, skipping `next` means returning a\n * value instead of a request — and the caller receives that value, so the\n * decision is visible.\n *\n * ## Order\n *\n * Registered first wraps all the rest: it sees the request before everyone and\n * the response after everyone — ordinary layer semantics, where \"outer\" means\n * outer.\n */\nexport type TLankaRequestMiddleware = (\n\tctx: ILankaRequestContext,\n\tnext: (ctx: ILankaRequestContext) => Promise<unknown>,\n) => Promise<unknown>;\n\n/**\n * Folds the chain into one function.\n *\n * An empty chain returns `perform` as-is, with no wrappers and no cost: an app\n * without a request-policy plugin has no middleware at all and must not pay for\n * their absence.\n */\nexport function composeLankaRequestMiddleware(\n\tmiddleware: readonly TLankaRequestMiddleware[],\n\tperform: (ctx: ILankaRequestContext) => Promise<unknown>,\n): (ctx: ILankaRequestContext) => Promise<unknown> {\n\tif (middleware.length === 0) return perform;\n\n\treturn middleware.reduceRight<(ctx: ILankaRequestContext) => Promise<unknown>>(\n\t\t(next, current) => (ctx) => current(ctx, next),\n\t\tperform,\n\t);\n}\n"],"mappings":";AAgEO,SAAS,8BACf,YACA,SACkD;AAClD,MAAI,WAAW,WAAW,EAAG,QAAO;AAEpC,SAAO,WAAW;AAAA,IACjB,CAAC,MAAM,YAAY,CAAC,QAAQ,QAAQ,KAAK,IAAI;AAAA,IAC7C;AAAA,EACD;AACD;","names":[]}