@iveri/contracts 0.120.0 → 0.121.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -154,7 +154,9 @@ Inspect mode: `Endpoint`, `CaptureSummary`/`CaptureDetail`, `Provider` with its
154
154
  `SignatureManifest`/`HandshakeManifest`, `Replay`, `SignatureDiagnostic`.
155
155
 
156
156
  Gateway mode: `Destination`, `Route` with its `HeaderMatcher`/`BodyMatcher`, `Delivery` and
157
- `DeliveryAttempt`.
157
+ `DeliveryAttempt`. A route test — would this route have matched this capture? — answers a
158
+ `RouteTestResult` of `RouteCriterionResult`s, with `RouteCriterion` and `RouteCriterionMiss`
159
+ saying which criterion and why it missed; `TestRouteBody` asks it of criteria not saved yet.
158
160
 
159
161
  Plus the request bodies for each, and the seven enums they are built from — `SignatureVerdict`,
160
162
  `SignatureAlgorithm`, `SignatureEncoding`, `SignatureHeaderScheme`, `HandshakeKind`,
@@ -284,6 +286,9 @@ Conduit's outbox.
284
286
  `localization:render` permissions.
285
287
  - Version `0.100.0` adds `notification:send-any`, the password-reset bodies and Conduit's usage metrics.
286
288
  - Version `0.101.0` adds `UsageHistory`, a company's closed months of a product by metric.
289
+ - Version `0.121.0` adds Conduit's route test: `RouteTestResult`, `TestRouteBody`, `RouteCriterion` and
290
+ `RouteCriterionMiss`. (Tagged first as `v0.119.0`, which npm refused once 0.120.0 was out; 0.119.0 does not
291
+ exist on npm.)
287
292
  - Version `0.120.0` adds `chat:embed:manage-any` and an optional `tenantId` on the embed requests, so HR opens every
288
293
  company's conversations from its operator-workspace key.
289
294
  - Widening a type is minor; narrowing it is major.
@@ -17,6 +17,9 @@ export * from './handshake-kind.enum.js';
17
17
  export * from './match-operator.enum.js';
18
18
  export * from './provider.type.js';
19
19
  export * from './replay.type.js';
20
+ export * from './route-criterion-miss.enum.js';
21
+ export * from './route-criterion.enum.js';
22
+ export * from './route-test.type.js';
20
23
  export * from './route.type.js';
21
24
  export * from './signature-algorithm.enum.js';
22
25
  export * from './signature-encoding.enum.js';
@@ -17,6 +17,9 @@ export * from './handshake-kind.enum.js';
17
17
  export * from './match-operator.enum.js';
18
18
  export * from './provider.type.js';
19
19
  export * from './replay.type.js';
20
+ export * from './route-criterion-miss.enum.js';
21
+ export * from './route-criterion.enum.js';
22
+ export * from './route-test.type.js';
20
23
  export * from './route.type.js';
21
24
  export * from './signature-algorithm.enum.js';
22
25
  export * from './signature-encoding.enum.js';
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Why one criterion of a route did not match a request.
3
+ *
4
+ * A closed set, so a client can say it in the reader's language and an operator can tell the five
5
+ * remedies apart. Three of them say the body could not be read at all, and they are separate
6
+ * because the fixes are: an empty body needs a different route, an oversized one is a limit, and
7
+ * a form-encoded one needs a path or header criterion instead, since a body matcher cannot read
8
+ * inside a form.
9
+ *
10
+ * Every one of them means **not matched**. A criterion that cannot be evaluated does not match:
11
+ * a gateway that forwards on "I could not tell" sends a customer's data somewhere they did not ask
12
+ * for.
13
+ */
14
+ export declare enum RouteCriterionMiss {
15
+ /** The request carried a value, and it is not the one the rule asks for. */
16
+ DIFFERENT_VALUE = "different-value",
17
+ /**
18
+ * The header, or the body field, is not on the request. A body path that resolves to an
19
+ * object, an array or `null` counts as absent too: a matcher compares strings.
20
+ */
21
+ FIELD_ABSENT = "field-absent",
22
+ /** The operator compares against a value and the rule gives none. */
23
+ NO_OPERAND = "no-operand",
24
+ /** A body matcher, and the request had no body. */
25
+ BODY_EMPTY = "body-empty",
26
+ /** A body matcher, and the body is over the 1 MB the gateway parses for routing. */
27
+ BODY_TOO_LARGE = "body-too-large",
28
+ /** A body matcher, and the body is not JSON — form-encoded, XML, or malformed. */
29
+ BODY_NOT_JSON = "body-not-json"
30
+ }
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Why one criterion of a route did not match a request.
3
+ *
4
+ * A closed set, so a client can say it in the reader's language and an operator can tell the five
5
+ * remedies apart. Three of them say the body could not be read at all, and they are separate
6
+ * because the fixes are: an empty body needs a different route, an oversized one is a limit, and
7
+ * a form-encoded one needs a path or header criterion instead, since a body matcher cannot read
8
+ * inside a form.
9
+ *
10
+ * Every one of them means **not matched**. A criterion that cannot be evaluated does not match:
11
+ * a gateway that forwards on "I could not tell" sends a customer's data somewhere they did not ask
12
+ * for.
13
+ */
14
+ export var RouteCriterionMiss;
15
+ (function (RouteCriterionMiss) {
16
+ /** The request carried a value, and it is not the one the rule asks for. */
17
+ RouteCriterionMiss["DIFFERENT_VALUE"] = "different-value";
18
+ /**
19
+ * The header, or the body field, is not on the request. A body path that resolves to an
20
+ * object, an array or `null` counts as absent too: a matcher compares strings.
21
+ */
22
+ RouteCriterionMiss["FIELD_ABSENT"] = "field-absent";
23
+ /** The operator compares against a value and the rule gives none. */
24
+ RouteCriterionMiss["NO_OPERAND"] = "no-operand";
25
+ /** A body matcher, and the request had no body. */
26
+ RouteCriterionMiss["BODY_EMPTY"] = "body-empty";
27
+ /** A body matcher, and the body is over the 1 MB the gateway parses for routing. */
28
+ RouteCriterionMiss["BODY_TOO_LARGE"] = "body-too-large";
29
+ /** A body matcher, and the body is not JSON — form-encoded, XML, or malformed. */
30
+ RouteCriterionMiss["BODY_NOT_JSON"] = "body-not-json";
31
+ })(RouteCriterionMiss || (RouteCriterionMiss = {}));
@@ -0,0 +1,14 @@
1
+ /**
2
+ * One kind of condition a route can set, in the order the gateway evaluates them.
3
+ *
4
+ * The order is the evaluator's, not an arbitrary listing: a route test reports criteria in it, so
5
+ * the first criterion that missed is the one the gateway stopped at.
6
+ */
7
+ export declare enum RouteCriterion {
8
+ ENDPOINT = "endpoint",
9
+ PROVIDER = "provider",
10
+ METHOD = "method",
11
+ PATH = "path",
12
+ HEADER = "header",
13
+ BODY = "body"
14
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * One kind of condition a route can set, in the order the gateway evaluates them.
3
+ *
4
+ * The order is the evaluator's, not an arbitrary listing: a route test reports criteria in it, so
5
+ * the first criterion that missed is the one the gateway stopped at.
6
+ */
7
+ export var RouteCriterion;
8
+ (function (RouteCriterion) {
9
+ RouteCriterion["ENDPOINT"] = "endpoint";
10
+ RouteCriterion["PROVIDER"] = "provider";
11
+ RouteCriterion["METHOD"] = "method";
12
+ RouteCriterion["PATH"] = "path";
13
+ RouteCriterion["HEADER"] = "header";
14
+ RouteCriterion["BODY"] = "body";
15
+ })(RouteCriterion || (RouteCriterion = {}));
@@ -0,0 +1,85 @@
1
+ import type { Nullable } from '../../type/nil.type.js';
2
+ import type { UUID } from '../../type/uuid.type.js';
3
+ import type { MatchOperator } from './match-operator.enum.js';
4
+ import type { RouteCriterionMiss } from './route-criterion-miss.enum.js';
5
+ import type { RouteCriterion } from './route-criterion.enum.js';
6
+ import type { BodyMatcherInput, HeaderMatcherInput } from './route.type.js';
7
+ /** How one criterion of a route fared against one capture. */
8
+ export interface RouteCriterionResult {
9
+ criterion: RouteCriterion;
10
+ /** The header name or the body path. Null for the other four criteria. */
11
+ field: Nullable<string>;
12
+ /** The header or body matcher's operator. Null for the other four, which compare for equality or by glob. */
13
+ operator: Nullable<MatchOperator>;
14
+ /**
15
+ * What the rule asks for: the endpoint id, provider key, method, path glob, or the matcher's
16
+ * operand. Null for `exists`, which takes none.
17
+ */
18
+ expected: Nullable<string>;
19
+ /**
20
+ * What the capture carried, exactly as the matcher compared it — a repeated header joined
21
+ * with `, `, a body leaf as its JSON spelling. Null when it carried nothing there. Cut to
22
+ * 1000 characters and ended with `…` when longer; the comparison used the whole value.
23
+ */
24
+ actual: Nullable<string>;
25
+ matched: boolean;
26
+ /** Null when the criterion matched. */
27
+ miss: Nullable<RouteCriterionMiss>;
28
+ }
29
+ /** A route that stops evaluation before another one is reached. */
30
+ export interface RouteTestStopper {
31
+ id: UUID;
32
+ name: string;
33
+ }
34
+ /**
35
+ * `GET /api/v1/routes/:routeId/test?captureId=` and `POST /api/v1/routes/test`.
36
+ *
37
+ * Evaluated by the same matcher the gateway runs on every inbound request, against the stored
38
+ * capture as it arrived. Nothing is sent and nothing is written.
39
+ */
40
+ export interface RouteTestResult {
41
+ captureId: UUID;
42
+ /** Every criterion matched. A route that sets no criterion matches every request. */
43
+ matched: boolean;
44
+ /**
45
+ * Only the criteria the route sets, in the order the gateway evaluates them. Unlike the
46
+ * gateway, which stops at the first miss, every criterion is evaluated, so an operator sees
47
+ * all of what is wrong at once.
48
+ */
49
+ criteria: RouteCriterionResult[];
50
+ /**
51
+ * An earlier active route with `stopOnMatch` that also matches this capture, so the gateway
52
+ * stops before it reaches this one: the route matches and would still not fire. Null when
53
+ * nothing stands in the way. Reported whether or not this route matched.
54
+ */
55
+ stoppedBy: Nullable<RouteTestStopper>;
56
+ /**
57
+ * The endpoint's provider key the provider criterion was compared with. A capture does not
58
+ * record it, so this is the endpoint's **current** key; null when the endpoint has none or is
59
+ * gone.
60
+ */
61
+ providerKey: Nullable<string>;
62
+ }
63
+ /**
64
+ * `POST /api/v1/routes/test`: criteria not saved yet, as a route form holds them.
65
+ *
66
+ * The criteria take the same values and the same "absent means any" meaning as
67
+ * `CreateRouteBody`, and are normalised the same way before they are evaluated.
68
+ */
69
+ export interface TestRouteBody {
70
+ captureId: UUID;
71
+ /**
72
+ * The route being edited, if any: it is not reported as stopping itself, and its age decides
73
+ * its place among routes of the same priority. Omitted for a route not created yet, which
74
+ * would be evaluated after every existing route of its priority.
75
+ */
76
+ routeId?: Nullable<UUID>;
77
+ endpointId?: Nullable<UUID>;
78
+ providerKey?: Nullable<string>;
79
+ method?: Nullable<string>;
80
+ pathPattern?: Nullable<string>;
81
+ headerMatchers?: Nullable<HeaderMatcherInput[]>;
82
+ bodyMatchers?: Nullable<BodyMatcherInput[]>;
83
+ /** Decides which routes are evaluated before it. Default 100, as on create. */
84
+ priority?: Nullable<number>;
85
+ }
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iveri/contracts",
3
- "version": "0.120.0",
3
+ "version": "0.121.0",
4
4
  "description": "Wire contracts shared by every Iveri backend and frontend. Zero runtime dependencies.",
5
5
  "license": "MIT",
6
6
  "repository": {