@entifix/service-shell 0.11.0 → 0.12.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 +1 -4
- package/dist/auth/require-organization.d.ts +1 -1
- package/dist/auth/require-organization.d.ts.map +1 -1
- package/dist/auth/require-organization.js.map +1 -1
- package/dist/auth/require-principal.d.ts +9 -55
- package/dist/auth/require-principal.d.ts.map +1 -1
- package/dist/auth/require-principal.js +15 -13
- package/dist/auth/require-principal.js.map +1 -1
- package/dist/auth/require-service-crossing.d.ts.map +1 -1
- package/dist/auth/require-service-crossing.js +3 -13
- package/dist/auth/require-service-crossing.js.map +1 -1
- package/dist/auth/shared-token.d.ts +2 -0
- package/dist/auth/shared-token.d.ts.map +1 -1
- package/dist/auth/shared-token.js +2 -2
- package/dist/auth/shared-token.js.map +1 -1
- package/dist/auth/verified-context.d.ts +1 -2
- package/dist/auth/verified-context.d.ts.map +1 -1
- package/dist/auth/verified-context.js.map +1 -1
- package/dist/entity-facet-routes.d.ts +2 -2
- package/dist/entity-facet-routes.d.ts.map +1 -1
- package/dist/entity-facet-routes.js.map +1 -1
- package/dist/entity-route-guard.d.ts +2 -2
- package/dist/entity-route-guard.d.ts.map +1 -1
- package/dist/entity-route-guard.js.map +1 -1
- package/dist/entity-routes.d.ts +1 -1
- package/dist/entity-routes.d.ts.map +1 -1
- package/dist/entity-routes.js.map +1 -1
- package/dist/http-api/build-api.d.ts +78 -0
- package/dist/http-api/build-api.d.ts.map +1 -0
- package/dist/http-api/build-api.js +189 -0
- package/dist/http-api/build-api.js.map +1 -0
- package/dist/http-api/entity-api.d.ts +69 -0
- package/dist/http-api/entity-api.d.ts.map +1 -0
- package/dist/http-api/entity-api.js +522 -0
- package/dist/http-api/entity-api.js.map +1 -0
- package/dist/http-api/guards.d.ts +92 -0
- package/dist/http-api/guards.d.ts.map +1 -0
- package/dist/http-api/guards.js +131 -0
- package/dist/http-api/guards.js.map +1 -0
- package/dist/http-api/index.d.ts +6 -0
- package/dist/http-api/index.d.ts.map +1 -0
- package/dist/http-api/index.js +7 -0
- package/dist/http-api/index.js.map +1 -0
- package/dist/http-api/problem-codec.d.ts +14 -0
- package/dist/http-api/problem-codec.d.ts.map +1 -0
- package/dist/http-api/problem-codec.js +26 -0
- package/dist/http-api/problem-codec.js.map +1 -0
- package/dist/http-api/service-group.d.ts +74 -0
- package/dist/http-api/service-group.d.ts.map +1 -0
- package/dist/http-api/service-group.js +168 -0
- package/dist/http-api/service-group.js.map +1 -0
- package/dist/idempotency.d.ts +9 -4
- package/dist/idempotency.d.ts.map +1 -1
- package/dist/idempotency.js +11 -6
- package/dist/idempotency.js.map +1 -1
- package/dist/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -2
- package/dist/index.js.map +1 -1
- package/dist/make-service.d.ts +39 -6
- package/dist/make-service.d.ts.map +1 -1
- package/dist/make-service.js +54 -16
- package/dist/make-service.js.map +1 -1
- package/dist/narrowing.d.ts +1 -15
- package/dist/narrowing.d.ts.map +1 -1
- package/dist/narrowing.js.map +1 -1
- package/dist/respond.d.ts +6 -4
- package/dist/respond.d.ts.map +1 -1
- package/dist/respond.js +11 -7
- package/dist/respond.js.map +1 -1
- package/dist/serve-test-service.d.ts +2 -1
- package/dist/serve-test-service.d.ts.map +1 -1
- package/dist/serve-test-service.js.map +1 -1
- package/package.json +7 -6
- package/dist/health-routes.d.ts +0 -24
- package/dist/health-routes.d.ts.map +0 -1
- package/dist/health-routes.js +0 -86
- package/dist/health-routes.js.map +0 -1
- package/dist/service-description-route.d.ts +0 -66
- package/dist/service-description-route.d.ts.map +0 -1
- package/dist/service-description-route.js +0 -60
- package/dist/service-description-route.js.map +0 -1
package/README.md
CHANGED
|
@@ -19,15 +19,12 @@ pnpm add @opentelemetry/api @effect/opentelemetry @opentelemetry/sdk-trace-base
|
|
|
19
19
|
| Import | What it holds |
|
|
20
20
|
| -------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
21
21
|
| `@entifix/service-shell` | What a route set is written against: `makeEntityRoutes`, `makeEntityFacetRoutes` (`GET <entity>/$facets`, over the host's `EntityFacetCounterFactoryTag`), `requirePrincipal`, `requirePermission`, `requireOrganization`, `requireServiceCrossing`, `requireSharedToken`, `entityMetadataRoute`, health and SSE routes |
|
|
22
|
-
| `@entifix/service-shell/runtime` | Running a service: `makeService`, `makeServerLayer`, `loadRemoteConfiguration`. Needs `@effect/platform-node`
|
|
22
|
+
| `@entifix/service-shell/runtime` | Running a service: `makeService`, `makeServerLayer`, `makeWorker` (a process with no HTTP server — a second runner), `loadRemoteConfiguration`. Needs `@effect/platform-node` |
|
|
23
23
|
| `@entifix/service-shell/observability` | `makeObservabilityLayer` and the OpenTelemetry wiring. Needs `@effect/opentelemetry` and the OpenTelemetry SDK packages |
|
|
24
24
|
| `@entifix/service-shell/testing` | `serveTestService`, a service on an ephemeral port for a spec |
|
|
25
25
|
|
|
26
26
|
The runtime and observability halves are optional peers: a package that only declares routes installs neither. The configuration service's URL and credential, and the header and secret that gate `GET /api/$service`, are values the host passes — `loadRemoteConfiguration({ url, headers })` and `makeService({ description: { header, token } })`.
|
|
27
27
|
|
|
28
|
-
------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
29
|
-
| `@entifix/service-shell` | `makeService`, `makeServerLayer`, `makeEntityRoutes`, `makeEntityFacetRoutes`, `requirePrincipal`, `requirePermission`, `requireOrganization`, `entityMetadataRoute`, `loadRemoteConfiguration`, `makeObservabilityLayer`, `serveTestService` |
|
|
30
|
-
|
|
31
28
|
---
|
|
32
29
|
|
|
33
30
|
Tier 4 (app framework) of entifix — a package depends only on its own tier or below. See [the tiers](https://github.com/r10c-technologies/entifix#the-tiers-and-what-you-are-allowed-to-install). MIT licensed.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Permission } from '@entifix/authz';
|
|
2
|
+
import type { RequestPrincipal } from '@entifix/business';
|
|
2
3
|
import { Effect } from 'effect';
|
|
3
|
-
import { type RequestPrincipal } from './require-principal.js';
|
|
4
4
|
/**
|
|
5
5
|
* Guard a **tenant-plane** handler: authenticate, check the permission, and
|
|
6
6
|
* require that the session names an organization.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"require-organization.d.ts","sourceRoot":"","sources":["../../src/auth/require-organization.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"require-organization.d.ts","sourceRoot":"","sources":["../../src/auth/require-organization.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAkBhC;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,eAAO,MAAM,mBAAmB,GAC7B,YAAY,UAAU,MACtB,CAAC,EAAE,CAAC,EAAE,CAAC,EACN,KAAK,CACH,cAAc,EAAE,MAAM,EACtB,SAAS,EAAE,gBAAgB,KACxB,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,gPAa1B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/auth/require-organization.ts"],"sourcesContent":["import type { Permission } from '@entifix/authz';\nimport { Effect } from 'effect';\n\nimport { NoActiveOrganization, refuse } from './failures.js';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../src/auth/require-organization.ts"],"sourcesContent":["import type { Permission } from '@entifix/authz';\nimport type { RequestPrincipal } from '@entifix/business';\nimport { Effect } from 'effect';\n\nimport { NoActiveOrganization, refuse } from './failures.js';\nimport { requirePermission } from './require-principal.js';\n\n/**\n * `409` rather than `403`: the caller is authenticated and permitted, but the\n * session names no organization, so there is no storage to read. An operator\n * hits this by design — crossing into a tenant is an explicit, audited\n * act-as-organization re-mint, never a widening of the default —\n * and a member of several organizations hits it before choosing one. The `code`\n * is a key in the shared `errors` catalog, so a client renders \"select an\n * organization\" instead of \"forbidden\" — a claim a host has to check its\n * catalog against, because for a while it was simply false and the code\n * reached the browser as its own literal text.\n */\nconst noOrganization = refuse(new NoActiveOrganization());\n\n/**\n * Guard a **tenant-plane** handler: authenticate, check the permission, and\n * require that the session names an organization.\n *\n * **This is the first of exactly two ways a request resolves the organization\n * it acts for, and the only *user-facing* one**.\n * The second is {@link requireServiceCrossing}: an explicit `organizationId`\n * presented with a service token *and* a narrow route permission, for a\n * platform-plane caller acting for an organization it was handed rather than one\n * it picked.\n *\n * There is no third path, no fallback and no operator branch. A request\n * satisfying neither guard never reaches a tenant handle at all, which is what\n * keeps the most sensitive capability in the system from being the *absence* of\n * a condition.\n *\n * The organization is handed to the handler so it can resolve its own storage\n * through a `TenantDatabaseResolver`. Resolution happens **inside the request**\n * — the connection pool is a boot-time `Layer`, and a per-request `Layer` would\n * rebuild the pool per request.\n *\n * Here the value comes from the verified token and nowhere else. A route\n * parameter or a body field naming an organization would be caller-controlled,\n * which is the whole failure this guard exists to prevent — and is exactly why\n * the other path honours a caller-named organization only *after* the caller has\n * proved it is the fleet.\n */\nexport const requireOrganization =\n (permission: Permission) =>\n <A, E, R>(\n use: (\n organizationId: string,\n principal: RequestPrincipal,\n ) => Effect.Effect<A, E, R>,\n ) =>\n requirePermission(permission)(principal =>\n // `Effect.gen` rather than a ternary: the two branches have different\n // success types, and a conditional expression would unify them against\n // the first one instead of widening. `requirePrincipal` yields for the\n // same reason.\n Effect.gen(function* () {\n if (principal.organizationId === undefined) {\n return yield* noOrganization;\n }\n return yield* use(principal.organizationId, principal);\n }),\n );\n"],"names":["Effect","NoActiveOrganization","refuse","requirePermission","noOrganization","requireOrganization","permission","use","principal","gen","organizationId","undefined"],"mappings":"AAEA,SAASA,MAAM,QAAQ,SAAS;AAEhC,SAASC,oBAAoB,EAAEC,MAAM,QAAQ,gBAAgB;AAC7D,SAASC,iBAAiB,QAAQ,yBAAyB;AAE3D;;;;;;;;;;CAUC,GACD,MAAMC,iBAAiBF,OAAO,IAAID;AAElC;;;;;;;;;;;;;;;;;;;;;;;;;;CA0BC,GACD,OAAO,MAAMI,sBACX,CAACC,aACD,CACEC,MAKAJ,kBAAkBG,YAAYE,CAAAA,YAC5B,sEAAsE;YACtE,uEAAuE;YACvE,uEAAuE;YACvE,eAAe;YACfR,OAAOS,GAAG,CAAC;gBACT,IAAID,UAAUE,cAAc,KAAKC,WAAW;oBAC1C,OAAO,OAAOP;gBAChB;gBACA,OAAO,OAAOG,IAAIC,UAAUE,cAAc,EAAEF;YAC9C,IACA"}
|
|
@@ -1,62 +1,16 @@
|
|
|
1
1
|
import { type Permission, PolicyDecisionTag } from '@entifix/authz';
|
|
2
|
-
import { type
|
|
3
|
-
import { Effect } from 'effect';
|
|
2
|
+
import { type RequestPrincipal, TokenServiceTag } from '@entifix/business';
|
|
3
|
+
import { Effect, Option } from 'effect';
|
|
4
4
|
import { HttpServerRequest } from 'effect/http';
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
* `
|
|
8
|
-
*
|
|
6
|
+
* Resolve the caller's principal from the request, or `None`. Reads the token
|
|
7
|
+
* from the `entifix_at` cookie (the Next app forwards it) or an
|
|
8
|
+
* `Authorization: Bearer` header and verifies it statelessly via
|
|
9
|
+
* {@link TokenServiceTag} — no store round trip on the hot path.
|
|
9
10
|
*/
|
|
10
|
-
export
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
readonly sessionId: string;
|
|
14
|
-
readonly roles: readonly string[];
|
|
15
|
-
/**
|
|
16
|
-
* The organization this request acts for — the storage routing key, absent
|
|
17
|
-
* for a caller with no tenant scope (a buyer, or an operator). Kept out of
|
|
18
|
-
* `attributes` deliberately: attributes are policy inputs, this decides which
|
|
19
|
-
* database a handler reads.
|
|
20
|
-
*/
|
|
21
|
-
readonly organizationId?: string;
|
|
22
|
-
/**
|
|
23
|
-
* Which population the caller belongs to — buyer, vendor staff, or platform
|
|
24
|
-
* staff. Carried so a handler never has to infer it from an absent
|
|
25
|
-
* `organizationId`, which a buyer and an operator share.
|
|
26
|
-
*
|
|
27
|
-
* Context, not a grant: what the caller may *do* still comes from `roles`
|
|
28
|
-
* through {@link PolicyDecisionTag}.
|
|
29
|
-
*/
|
|
30
|
-
readonly partyRole?: string;
|
|
31
|
-
/**
|
|
32
|
-
* The party behind the account — the `Individual` id, absent for an account
|
|
33
|
-
* with no party record.
|
|
34
|
-
*
|
|
35
|
-
* Same rule as the two fields above: it comes from the verified token and
|
|
36
|
-
* never from anything the caller sets on the request. It says *whose* records
|
|
37
|
-
* these are, which is what a route scoping a read to its caller needs; it
|
|
38
|
-
* says nothing about what may be done with them.
|
|
39
|
-
*/
|
|
40
|
-
readonly partyId?: string;
|
|
41
|
-
/**
|
|
42
|
-
* When the verified token stops being valid, as a Unix timestamp in seconds.
|
|
43
|
-
*
|
|
44
|
-
* Every REST route is already bounded by it implicitly — verification is
|
|
45
|
-
* stateless, so the next call after expiry simply fails. A **held-open**
|
|
46
|
-
* response has no next call, so `GET /api/transaction/events` reads it and
|
|
47
|
-
* closes the connection there. Absent when the token carries no
|
|
48
|
-
* `exp`, which a signed one always does; the guard is for the type, not for a
|
|
49
|
-
* case the fleet produces.
|
|
50
|
-
*/
|
|
51
|
-
readonly expiresAt?: number;
|
|
52
|
-
/**
|
|
53
|
-
* What the caller's active organization was provisioned for, off the
|
|
54
|
-
* verified token. Context for a resolver, never a
|
|
55
|
-
* grant: a variant requires an entitlement before its predicate is read.
|
|
56
|
-
*/
|
|
57
|
-
readonly entitlements?: readonly string[];
|
|
58
|
-
readonly attributes: Readonly<Record<string, unknown>>;
|
|
59
|
-
}
|
|
11
|
+
export declare const resolveRequestPrincipal: Effect.Effect<Option.Option<RequestPrincipal>, never, TokenServiceTag | HttpServerRequest.HttpServerRequest>;
|
|
12
|
+
/** Whether the policy lets `principal` do what `permission` names. */
|
|
13
|
+
export declare const permits: (principal: RequestPrincipal, permission: Permission) => Effect.Effect<boolean, never, PolicyDecisionTag>;
|
|
60
14
|
/**
|
|
61
15
|
* Guard a handler behind a valid access token — authentication only. Any
|
|
62
16
|
* missing or invalid token is a `401`; the wrapped handler's own errors are
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"require-principal.d.ts","sourceRoot":"","sources":["../../src/auth/require-principal.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,UAAU,EACf,iBAAiB,EAClB,MAAM,gBAAgB,CAAC;AACxB,OAAO,
|
|
1
|
+
{"version":3,"file":"require-principal.d.ts","sourceRoot":"","sources":["../../src/auth/require-principal.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,UAAU,EACf,iBAAiB,EAClB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,KAAK,gBAAgB,EAErB,eAAe,EAChB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACxC,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AA6ChD;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,8GAWlC,CAAC;AAEH,sEAAsE;AACtE,eAAO,MAAM,OAAO,GAAI,WAAW,gBAAgB,EAAE,YAAY,UAAU,qDASvE,CAAC;AAEL;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,GAAI,CAAC,EAAE,CAAC,EAAE,CAAC,EACtC,KAAK,CAAC,SAAS,EAAE,gBAAgB,KAAK,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,iJAQ1D,CAAC;AAEL;;;;;;;;GAQG;AACH,eAAO,MAAM,iBAAiB,GAC3B,YAAY,UAAU,MACtB,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,SAAS,EAAE,gBAAgB,KAAK,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,qKAYlE,CAAC"}
|
|
@@ -48,7 +48,7 @@ const forbidden = (permission)=>refuse(new Forbidden({
|
|
|
48
48
|
* from the `entifix_at` cookie (the Next app forwards it) or an
|
|
49
49
|
* `Authorization: Bearer` header and verifies it statelessly via
|
|
50
50
|
* {@link TokenServiceTag} — no store round trip on the hot path.
|
|
51
|
-
*/ const
|
|
51
|
+
*/ export const resolveRequestPrincipal = Effect.gen(function*() {
|
|
52
52
|
var _req_cookies_ACCESS_COOKIE;
|
|
53
53
|
const req = yield* HttpServerRequest.HttpServerRequest;
|
|
54
54
|
const token = (_req_cookies_ACCESS_COOKIE = req.cookies[ACCESS_COOKIE]) != null ? _req_cookies_ACCESS_COOKIE : bearerToken(req.headers['authorization']);
|
|
@@ -59,12 +59,23 @@ const forbidden = (permission)=>refuse(new Forbidden({
|
|
|
59
59
|
const claims = yield* tokens.verify(token).pipe(Effect.option);
|
|
60
60
|
return Option.map(claims, claimsToPrincipal);
|
|
61
61
|
});
|
|
62
|
+
/** Whether the policy lets `principal` do what `permission` names. */ export const permits = (principal, permission)=>Effect.gen(function*() {
|
|
63
|
+
const { resource, action } = parsePermission(permission);
|
|
64
|
+
const policy = yield* PolicyDecisionTag;
|
|
65
|
+
return policy.decide({
|
|
66
|
+
subject: {
|
|
67
|
+
roles: principal.roles
|
|
68
|
+
},
|
|
69
|
+
resource,
|
|
70
|
+
action
|
|
71
|
+
});
|
|
72
|
+
});
|
|
62
73
|
/**
|
|
63
74
|
* Guard a handler behind a valid access token — authentication only. Any
|
|
64
75
|
* missing or invalid token is a `401`; the wrapped handler's own errors are
|
|
65
76
|
* left intact.
|
|
66
77
|
*/ export const requirePrincipal = (use)=>Effect.gen(function*() {
|
|
67
|
-
const principal = yield*
|
|
78
|
+
const principal = yield* resolveRequestPrincipal;
|
|
68
79
|
if (Option.isNone(principal)) {
|
|
69
80
|
return yield* unauthenticated;
|
|
70
81
|
}
|
|
@@ -79,20 +90,11 @@ const forbidden = (permission)=>refuse(new Forbidden({
|
|
|
79
90
|
* **This is the authorization boundary.** Filtering a nav menu or hiding a page
|
|
80
91
|
* is presentation; a route that skips this guard is open regardless.
|
|
81
92
|
*/ export const requirePermission = (permission)=>(use)=>Effect.gen(function*() {
|
|
82
|
-
const principal = yield*
|
|
93
|
+
const principal = yield* resolveRequestPrincipal;
|
|
83
94
|
if (Option.isNone(principal)) {
|
|
84
95
|
return yield* unauthenticated;
|
|
85
96
|
}
|
|
86
|
-
|
|
87
|
-
const policy = yield* PolicyDecisionTag;
|
|
88
|
-
const allowed = policy.decide({
|
|
89
|
-
subject: {
|
|
90
|
-
roles: principal.value.roles
|
|
91
|
-
},
|
|
92
|
-
resource,
|
|
93
|
-
action
|
|
94
|
-
});
|
|
95
|
-
if (!allowed) {
|
|
97
|
+
if (!(yield* permits(principal.value, permission))) {
|
|
96
98
|
return yield* forbidden(permission);
|
|
97
99
|
}
|
|
98
100
|
return yield* use(principal.value);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/auth/require-principal.ts"],"sourcesContent":["import {\n parsePermission,\n type Permission,\n PolicyDecisionTag,\n} from '@entifix/authz';\nimport { type TokenClaims
|
|
1
|
+
{"version":3,"sources":["../../src/auth/require-principal.ts"],"sourcesContent":["import {\n parsePermission,\n type Permission,\n PolicyDecisionTag,\n} from '@entifix/authz';\nimport {\n type RequestPrincipal,\n type TokenClaims,\n TokenServiceTag,\n} from '@entifix/business';\nimport { ACCESS_COOKIE, Forbidden, Unauthenticated } from '@entifix/core';\nimport { Effect, Option } from 'effect';\nimport { HttpServerRequest } from 'effect/http';\n\nimport { refuse } from './failures.js';\n\n/** Extract a bearer token from an `Authorization` header, if present. */\nconst bearerToken = (authorization: string | undefined): string | undefined => {\n if (authorization === undefined) {\n return undefined;\n }\n const [scheme, value] = authorization.split(' ');\n return scheme?.toLowerCase() === 'bearer' ? value : undefined;\n};\n\n/** Rebuild the request principal from verified token claims. */\nconst claimsToPrincipal = (claims: TokenClaims): RequestPrincipal => ({\n userId: claims.userId,\n subject: claims.subject,\n sessionId: claims.sessionId,\n roles: claims.roles,\n // The organization comes from the *verified* token and nowhere else — never\n // from a route parameter, a query string or a body, all of which the caller\n // controls. That is what makes tenant isolation a property of the session\n // rather than of every handler remembering to check.\n organizationId: claims.activeOrganizationId,\n // Same rule, same reason: it comes from the verified token, never from\n // anything the caller can set on the request.\n partyRole: claims.partyRole,\n partyId: claims.partyId,\n // `TokenClaims` carries an index signature, so `exp` arrives as `unknown`\n // even though jose always sets it — hence the guard rather than a cast.\n expiresAt: typeof claims.exp === 'number' ? claims.exp : undefined,\n entitlements: claims.entitlements ?? [],\n // Rich/volatile attributes are not in the token; a handler that needs them\n // reads the session store by `sessionId`.\n attributes: {},\n});\n\n// `code` is a key in the shared `errors` catalog; `error` stays English for\n// logs. `permission` is deliberately still in the 403 — it says which grant was\n// missing, which is diagnostic, not a leak.\nconst unauthenticated = refuse(new Unauthenticated());\n\nconst forbidden = (permission: Permission) =>\n refuse(new Forbidden({ permission }));\n\n/**\n * Resolve the caller's principal from the request, or `None`. Reads the token\n * from the `entifix_at` cookie (the Next app forwards it) or an\n * `Authorization: Bearer` header and verifies it statelessly via\n * {@link TokenServiceTag} — no store round trip on the hot path.\n */\nexport const resolveRequestPrincipal = Effect.gen(function* () {\n const req = yield* HttpServerRequest.HttpServerRequest;\n const token =\n req.cookies[ACCESS_COOKIE] ?? bearerToken(req.headers['authorization']);\n if (token === undefined) {\n return Option.none<RequestPrincipal>();\n }\n\n const tokens = yield* TokenServiceTag;\n const claims = yield* tokens.verify(token).pipe(Effect.option);\n return Option.map(claims, claimsToPrincipal);\n});\n\n/** Whether the policy lets `principal` do what `permission` names. */\nexport const permits = (principal: RequestPrincipal, permission: Permission) =>\n Effect.gen(function* () {\n const { resource, action } = parsePermission(permission);\n const policy = yield* PolicyDecisionTag;\n return policy.decide({\n subject: { roles: principal.roles },\n resource,\n action,\n });\n });\n\n/**\n * Guard a handler behind a valid access token — authentication only. Any\n * missing or invalid token is a `401`; the wrapped handler's own errors are\n * left intact.\n */\nexport const requirePrincipal = <A, E, R>(\n use: (principal: RequestPrincipal) => Effect.Effect<A, E, R>,\n) =>\n Effect.gen(function* () {\n const principal = yield* resolveRequestPrincipal;\n if (Option.isNone(principal)) {\n return yield* unauthenticated;\n }\n return yield* use(principal.value);\n });\n\n/**\n * Guard a handler behind a permission. Authenticates as above, then asks\n * {@link PolicyDecisionTag} whether this subject may perform the action — so\n * the two failure modes stay distinguishable: `401` means \"sign in\", `403`\n * means \"signed in, not allowed\".\n *\n * **This is the authorization boundary.** Filtering a nav menu or hiding a page\n * is presentation; a route that skips this guard is open regardless.\n */\nexport const requirePermission =\n (permission: Permission) =>\n <A, E, R>(use: (principal: RequestPrincipal) => Effect.Effect<A, E, R>) =>\n Effect.gen(function* () {\n const principal = yield* resolveRequestPrincipal;\n if (Option.isNone(principal)) {\n return yield* unauthenticated;\n }\n\n if (!(yield* permits(principal.value, permission))) {\n return yield* forbidden(permission);\n }\n\n return yield* use(principal.value);\n });\n"],"names":["parsePermission","PolicyDecisionTag","TokenServiceTag","ACCESS_COOKIE","Forbidden","Unauthenticated","Effect","Option","HttpServerRequest","refuse","bearerToken","authorization","undefined","scheme","value","split","toLowerCase","claimsToPrincipal","claims","userId","subject","sessionId","roles","organizationId","activeOrganizationId","partyRole","partyId","expiresAt","exp","entitlements","attributes","unauthenticated","forbidden","permission","resolveRequestPrincipal","gen","req","token","cookies","headers","none","tokens","verify","pipe","option","map","permits","principal","resource","action","policy","decide","requirePrincipal","use","isNone","requirePermission"],"mappings":"AAAA,SACEA,eAAe,EAEfC,iBAAiB,QACZ,iBAAiB;AACxB,SAGEC,eAAe,QACV,oBAAoB;AAC3B,SAASC,aAAa,EAAEC,SAAS,EAAEC,eAAe,QAAQ,gBAAgB;AAC1E,SAASC,MAAM,EAAEC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ossing.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"require-service-crossing.d.ts","sourceRoot":"","sources":["../../src/auth/require-service-crossing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAAE,wBAAwB,EAAE,MAAM,gBAAgB,CAAC;AAE3E,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACzC,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAKhD;;;;;;;;;GASG;AACH,eAAO,MAAM,qBAAqB,qBAAqB,CAAC;AAExD;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,mBAAmB,sBAAsB,CAAC;AAEvD;;;GAGG;AACH,eAAO,MAAM,iBAAiB,iBAAiB,CAAC;;AAEhD;;;;;;;;GAQG;AACH,qBAAa,uBAAwB,SAAQ,4BAGf;CAAG;AAmBjC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,eAAO,MAAM,sBAAsB,GAChC,YAAY,UAAU,MACtB,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,cAAc,EAAE,MAAM,KAAK,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,oLAwB7D,CAAC;AAEP;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,eAAe,GACzB,YAAY,UAAU,MACtB,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,oLAenC,CAAC"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { timingSafeEqual } from 'node:crypto';
|
|
2
1
|
import { ServiceCrossingPolicyTag } from '@entifix/authz';
|
|
3
2
|
import { Forbidden, Invalid, Unauthenticated } from '@entifix/core';
|
|
4
3
|
import { Context, Effect } from 'effect';
|
|
5
4
|
import { HttpServerRequest } from 'effect/http';
|
|
6
5
|
import { refuse } from './failures.js';
|
|
6
|
+
import { tokenMatches } from './shared-token.js';
|
|
7
7
|
/**
|
|
8
8
|
* The header carrying the crossing secret.
|
|
9
9
|
*
|
|
@@ -41,16 +41,6 @@ import { refuse } from './failures.js';
|
|
|
41
41
|
* fetch as `mongo.uri` and can be rotated without redeploying a container.
|
|
42
42
|
*/ export class ServiceCrossingTokenTag extends Context.Service()('ServiceCrossingTokenTag') {
|
|
43
43
|
}
|
|
44
|
-
/** Constant-time comparison, so the secret cannot be recovered byte by byte. */ const matches = (provided, expected)=>{
|
|
45
|
-
// An empty credential is refused outright, on either side: two empty
|
|
46
|
-
// buffers compare equal, so an unset secret would admit an empty header.
|
|
47
|
-
if (provided === undefined || provided === '' || expected === '') return false;
|
|
48
|
-
const left = Buffer.from(provided);
|
|
49
|
-
const right = Buffer.from(expected);
|
|
50
|
-
// `timingSafeEqual` throws on a length mismatch, so lengths are compared
|
|
51
|
-
// first — the length of a shared secret is not what protects it.
|
|
52
|
-
return left.length === right.length && timingSafeEqual(left, right);
|
|
53
|
-
};
|
|
54
44
|
const unauthenticated = refuse(new Unauthenticated());
|
|
55
45
|
const forbidden = (permission)=>refuse(new Forbidden({
|
|
56
46
|
permission
|
|
@@ -111,7 +101,7 @@ const organizationRequired = refuse(new Invalid({
|
|
|
111
101
|
var _request_headers_ORGANIZATION_HEADER;
|
|
112
102
|
const request = yield* HttpServerRequest.HttpServerRequest;
|
|
113
103
|
const expected = yield* ServiceCrossingTokenTag;
|
|
114
|
-
if (!
|
|
104
|
+
if (!tokenMatches(request.headers[CROSSING_TOKEN_HEADER], expected)) {
|
|
115
105
|
return yield* unauthenticated;
|
|
116
106
|
}
|
|
117
107
|
const crossing = yield* ServiceCrossingPolicyTag;
|
|
@@ -147,7 +137,7 @@ const organizationRequired = refuse(new Invalid({
|
|
|
147
137
|
*/ export const requireCrossing = (permission)=>(route)=>Effect.gen(function*() {
|
|
148
138
|
const request = yield* HttpServerRequest.HttpServerRequest;
|
|
149
139
|
const expected = yield* ServiceCrossingTokenTag;
|
|
150
|
-
if (!
|
|
140
|
+
if (!tokenMatches(request.headers[CROSSING_TOKEN_HEADER], expected)) {
|
|
151
141
|
return yield* unauthenticated;
|
|
152
142
|
}
|
|
153
143
|
const crossing = yield* ServiceCrossingPolicyTag;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/auth/require-service-crossing.ts"],"sourcesContent":["import { timingSafeEqual } from 'node:crypto';\n\nimport { type Permission, ServiceCrossingPolicyTag } from '@entifix/authz';\nimport { Forbidden, Invalid, Unauthenticated } from '@entifix/core';\nimport { Context, Effect } from 'effect';\nimport { HttpServerRequest } from 'effect/http';\n\nimport { refuse } from './failures.js';\n\n/**\n * The header carrying the crossing secret.\n *\n * ⚠️ **Deliberately not `x-service-token`.** That header is config-service's\n * fleet lookup, and the two secrets are not comparable: one grants a\n * configuration *read*, this one a tenant-data *write* for any organization the\n * caller names. Sharing the header name is how a proxy configured to forward the\n * fleet token ends up presenting it to a route that writes stock, and how a\n * copy-pasted value looks right while being the wrong secret entirely.\n */\nexport const CROSSING_TOKEN_HEADER = 'x-crossing-token';\n\n/**\n * The header naming the organization the caller is acting for.\n *\n * It rides beside the token rather than inside the request body because\n * entities are organization-agnostic by rule — no `organizationId` member, no\n * tenant filter — so there is nowhere in an entity envelope for it to live. A\n * header also serves the crossings that carry no body at all (releasing a hold,\n * converting one), which a body field would have needed a second convention for.\n *\n * On its own it grants **nothing**: it is only read after the token has proved\n * the caller is the fleet, so the input the caller controls is never the input\n * that authorizes.\n */\nexport const ORGANIZATION_HEADER = 'x-organization-id';\n\n/**\n * The header a saga dispatch carries its command id in — what a participant\n * dedupes a redelivered command on, and what its unit of work claims.\n */\nexport const COMMAND_ID_HEADER = 'x-command-id';\n\n/**\n * The crossing secret this service expects, provided at the composition root\n * from its own configuration.\n *\n * A `Context.Tag` rather than an environment read, which is the difference from\n * {@link requireServiceToken}: the value is a per-service secret held in\n * config-service as an `is_secret` row, so it arrives through the same boot\n * fetch as `mongo.uri` and can be rotated without redeploying a container.\n */\nexport class ServiceCrossingTokenTag extends Context.Service<\n ServiceCrossingTokenTag,\n string\n>()('ServiceCrossingTokenTag') {}\n\n/** Constant-time comparison, so the secret cannot be recovered byte by byte. */\nconst matches = (provided: string | undefined, expected: string): boolean => {\n // An empty credential is refused outright, on either side: two empty\n // buffers compare equal, so an unset secret would admit an empty header.\n if (provided === undefined || provided === '' || expected === '')\n return false;\n const left = Buffer.from(provided);\n const right = Buffer.from(expected);\n // `timingSafeEqual` throws on a length mismatch, so lengths are compared\n // first — the length of a shared secret is not what protects it.\n return left.length === right.length && timingSafeEqual(left, right);\n};\n\nconst unauthenticated = refuse(new Unauthenticated());\n\nconst forbidden = (permission: Permission) =>\n refuse(new Forbidden({ permission }));\n\nconst organizationRequired = refuse(\n new Invalid({\n errors: [\n {\n pointer: `/headers/${ORGANIZATION_HEADER}`,\n detail: `${ORGANIZATION_HEADER} is required`,\n code: 'organizationRequired',\n },\n ],\n }),\n);\n\n/**\n * Guard a **service-to-service** tenant crossing: the second — and only other —\n * way a request resolves the organization it acts for.\n *\n * The first is {@link requireOrganization}, which reads the session's\n * `activeOrganizationId` and is the only *user-facing* resolution. This one\n * exists because a platform-plane caller sometimes acts for an organization the\n * principal is not a member of: checkout reserving a vendor's stock, where the\n * organization comes from the **item** and a buyer's session carries none — and\n * never will, since making a buyer a member of every vendor they buy from would\n * be a far worse breach than the problem it solved.\n *\n * There is no third path, no fallback and no operator branch. A request\n * satisfying neither guard simply never reaches a tenant handle. An operator\n * reaching into a tenant is a *different* mechanism — a person choosing an\n * organization, which needs a human's permission, a time box and a record of\n * the crossing — and does not belong in this guard.\n *\n * ⚠️ **This guard reads no cookie and no `Authorization` header, and that is\n * the design.** A route guarded here accepts the crossing token and nothing\n * else: two accepted credentials on one route means the weaker one is the\n * security level. It matters concretely — `super-admin` holds `*:*:*`, which\n * matches every crossing permission, so a route that also took a session would\n * be reachable by an operator's browser tab.\n *\n * Three checks, in this order, so nothing is revealed before fleet membership is\n * proven:\n *\n * 1. the token, compared in constant time → `401`;\n * 2. the permission, against `ServiceCrossingPolicyTag` → `403`. The token\n * proves the caller is the fleet; it does not say what the caller may do, and\n * fleet membership is not a capability;\n * 3. the organization header, non-blank → `400`.\n *\n * **The residual, stated rather than argued away**: a shared secret\n * means any process holding it can name any organization. What bounds it is the\n * permission above, the fact that only the slices needing it are configured with\n * the key, and the request log. What would remove it is an RS256 service token\n * carrying a scope claim, which is named work rather than a gap nobody noticed.\n */\nexport const requireServiceCrossing =\n (permission: Permission) =>\n <A, E, R>(use: (organizationId: string) => Effect.Effect<A, E, R>) =>\n // The return type is inferred rather than written out, for the reason\n // `requireServiceToken` records: `HttpServerResponse.json` contributes an\n // `HttpBodyError` to the failure channel, and spelling the type out while\n // omitting it is what makes the declaration emit fail invisibly.\n Effect.gen(function* () {\n const request = yield* HttpServerRequest.HttpServerRequest;\n const expected = yield* ServiceCrossingTokenTag;\n\n if (!matches(request.headers[CROSSING_TOKEN_HEADER], expected)) {\n return yield* unauthenticated;\n }\n\n const crossing = yield* ServiceCrossingPolicyTag;\n if (!crossing.allows(permission)) {\n return yield* forbidden(permission);\n }\n\n const organizationId = request.headers[ORGANIZATION_HEADER]?.trim();\n if (organizationId === undefined || organizationId === '') {\n return yield* organizationRequired;\n }\n\n return yield* use(organizationId);\n });\n\n/**\n * The same fleet check, for a participant that has **no organization to name**.\n *\n * ⚠️ **A platform-plane store is the whole difference.** `requireServiceCrossing`\n * above ends with an organization header because it is about to resolve a tenant\n * database handle from it, and a blank one there would read some other vendor's\n * storage. order-service names one database at boot, so there is no handle to\n * choose — and demanding a header nothing consumes would be theatre that a\n * caller learns to satisfy with any value.\n *\n * What is unchanged, and is the part that matters: the token proves the caller\n * is the fleet, the host's `ServiceCrossingPolicy` says what the fleet may do,\n * and **no session is accepted**. A saga step is not a person's act — the buyer\n * behind a checkout holds no grant over the order the coordinator is writing on\n * their behalf, and accepting their session here would make the weaker\n * credential the security level.\n *\n * The recorded residual carries over verbatim: a shared secret means any process\n * holding it can act, bounded by the permission and by which slices are\n * configured with the key.\n */\nexport const requireCrossing =\n (permission: Permission) =>\n <A, E, R>(route: Effect.Effect<A, E, R>) =>\n Effect.gen(function* () {\n const request = yield* HttpServerRequest.HttpServerRequest;\n const expected = yield* ServiceCrossingTokenTag;\n\n if (!matches(request.headers[CROSSING_TOKEN_HEADER], expected)) {\n return yield* unauthenticated;\n }\n\n const crossing = yield* ServiceCrossingPolicyTag;\n if (!crossing.allows(permission)) {\n return yield* forbidden(permission);\n }\n\n return yield* route;\n });\n"],"names":["timingSafeEqual","ServiceCrossingPolicyTag","Forbidden","Invalid","Unauthenticated","Context","Effect","HttpServerRequest","refuse","CROSSING_TOKEN_HEADER","ORGANIZATION_HEADER","COMMAND_ID_HEADER","ServiceCrossingTokenTag","Service","matches","provided","expected","undefined","left","Buffer","from","right","length","unauthenticated","forbidden","permission","organizationRequired","errors","pointer","detail","code","requireServiceCrossing","use","gen","request","headers","crossing","allows","organizationId","trim","requireCrossing","route"],"mappings":"AAAA,SAASA,eAAe,QAAQ,cAAc;AAE9C,SAA0BC,wBAAwB,QAAQ,iBAAiB;AAC3E,SAASC,SAAS,EAAEC,OAAO,EAAEC,eAAe,QAAQ,gBAAgB;AACpE,SAASC,OAAO,EAAEC,MAAM,QAAQ,SAAS;AACzC,SAASC,iBAAiB,QAAQ,cAAc;AAEhD,SAASC,MAAM,QAAQ,gBAAgB;AAEvC;;;;;;;;;CASC,GACD,OAAO,MAAMC,wBAAwB,mBAAmB;AAExD;;;;;;;;;;;;CAYC,GACD,OAAO,MAAMC,sBAAsB,oBAAoB;AAEvD;;;CAGC,GACD,OAAO,MAAMC,oBAAoB,eAAe;AAEhD;;;;;;;;CAQC,GACD,OAAO,MAAMC,gCAAgCP,QAAQQ,OAAO,GAGxD;AAA4B;AAEhC,8EAA8E,GAC9E,MAAMC,UAAU,CAACC,UAA8BC;IAC7C,qEAAqE;I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;;;;;;;;;;;;;;;;CAoBC,GACD,OAAO,MAAME,kBACX,CAACf,aACD,CAAUgB,QACRnC,OAAO2B,GAAG,CAAC;YACT,MAAMC,UAAU,OAAO3B,kBAAkBA,iBAAiB;YAC1D,MAAMS,WAAW,OAAOJ;YAExB,IAAI,CAACE,QAAQoB,QAAQC,OAAO,CAAC1B,sBAAsB,EAAEO,WAAW;gBAC9D,OAAO,OAAOO;YAChB;YAEA,MAAMa,WAAW,OAAOnC;YACxB,IAAI,CAACmC,SAASC,MAAM,CAACZ,aAAa;gBAChC,OAAO,OAAOD,UAAUC;YAC1B;YAEA,OAAO,OAAOgB;QAChB,GAAG"}
|
|
1
|
+
{"version":3,"sources":["../../src/auth/require-service-crossing.ts"],"sourcesContent":["import { type Permission, ServiceCrossingPolicyTag } from '@entifix/authz';\nimport { Forbidden, Invalid, Unauthenticated } from '@entifix/core';\nimport { Context, Effect } from 'effect';\nimport { HttpServerRequest } from 'effect/http';\n\nimport { refuse } from './failures.js';\nimport { tokenMatches } from './shared-token.js';\n\n/**\n * The header carrying the crossing secret.\n *\n * ⚠️ **Deliberately not `x-service-token`.** That header is config-service's\n * fleet lookup, and the two secrets are not comparable: one grants a\n * configuration *read*, this one a tenant-data *write* for any organization the\n * caller names. Sharing the header name is how a proxy configured to forward the\n * fleet token ends up presenting it to a route that writes stock, and how a\n * copy-pasted value looks right while being the wrong secret entirely.\n */\nexport const CROSSING_TOKEN_HEADER = 'x-crossing-token';\n\n/**\n * The header naming the organization the caller is acting for.\n *\n * It rides beside the token rather than inside the request body because\n * entities are organization-agnostic by rule — no `organizationId` member, no\n * tenant filter — so there is nowhere in an entity envelope for it to live. A\n * header also serves the crossings that carry no body at all (releasing a hold,\n * converting one), which a body field would have needed a second convention for.\n *\n * On its own it grants **nothing**: it is only read after the token has proved\n * the caller is the fleet, so the input the caller controls is never the input\n * that authorizes.\n */\nexport const ORGANIZATION_HEADER = 'x-organization-id';\n\n/**\n * The header a saga dispatch carries its command id in — what a participant\n * dedupes a redelivered command on, and what its unit of work claims.\n */\nexport const COMMAND_ID_HEADER = 'x-command-id';\n\n/**\n * The crossing secret this service expects, provided at the composition root\n * from its own configuration.\n *\n * A `Context.Tag` rather than an environment read, which is the difference from\n * {@link requireServiceToken}: the value is a per-service secret held in\n * config-service as an `is_secret` row, so it arrives through the same boot\n * fetch as `mongo.uri` and can be rotated without redeploying a container.\n */\nexport class ServiceCrossingTokenTag extends Context.Service<\n ServiceCrossingTokenTag,\n string\n>()('ServiceCrossingTokenTag') {}\n\nconst unauthenticated = refuse(new Unauthenticated());\n\nconst forbidden = (permission: Permission) =>\n refuse(new Forbidden({ permission }));\n\nconst organizationRequired = refuse(\n new Invalid({\n errors: [\n {\n pointer: `/headers/${ORGANIZATION_HEADER}`,\n detail: `${ORGANIZATION_HEADER} is required`,\n code: 'organizationRequired',\n },\n ],\n }),\n);\n\n/**\n * Guard a **service-to-service** tenant crossing: the second — and only other —\n * way a request resolves the organization it acts for.\n *\n * The first is {@link requireOrganization}, which reads the session's\n * `activeOrganizationId` and is the only *user-facing* resolution. This one\n * exists because a platform-plane caller sometimes acts for an organization the\n * principal is not a member of: checkout reserving a vendor's stock, where the\n * organization comes from the **item** and a buyer's session carries none — and\n * never will, since making a buyer a member of every vendor they buy from would\n * be a far worse breach than the problem it solved.\n *\n * There is no third path, no fallback and no operator branch. A request\n * satisfying neither guard simply never reaches a tenant handle. An operator\n * reaching into a tenant is a *different* mechanism — a person choosing an\n * organization, which needs a human's permission, a time box and a record of\n * the crossing — and does not belong in this guard.\n *\n * ⚠️ **This guard reads no cookie and no `Authorization` header, and that is\n * the design.** A route guarded here accepts the crossing token and nothing\n * else: two accepted credentials on one route means the weaker one is the\n * security level. It matters concretely — `super-admin` holds `*:*:*`, which\n * matches every crossing permission, so a route that also took a session would\n * be reachable by an operator's browser tab.\n *\n * Three checks, in this order, so nothing is revealed before fleet membership is\n * proven:\n *\n * 1. the token, compared in constant time → `401`;\n * 2. the permission, against `ServiceCrossingPolicyTag` → `403`. The token\n * proves the caller is the fleet; it does not say what the caller may do, and\n * fleet membership is not a capability;\n * 3. the organization header, non-blank → `400`.\n *\n * **The residual, stated rather than argued away**: a shared secret\n * means any process holding it can name any organization. What bounds it is the\n * permission above, the fact that only the slices needing it are configured with\n * the key, and the request log. What would remove it is an RS256 service token\n * carrying a scope claim, which is named work rather than a gap nobody noticed.\n */\nexport const requireServiceCrossing =\n (permission: Permission) =>\n <A, E, R>(use: (organizationId: string) => Effect.Effect<A, E, R>) =>\n // The return type is inferred rather than written out, for the reason\n // `requireServiceToken` records: `HttpServerResponse.json` contributes an\n // `HttpBodyError` to the failure channel, and spelling the type out while\n // omitting it is what makes the declaration emit fail invisibly.\n Effect.gen(function* () {\n const request = yield* HttpServerRequest.HttpServerRequest;\n const expected = yield* ServiceCrossingTokenTag;\n\n if (!tokenMatches(request.headers[CROSSING_TOKEN_HEADER], expected)) {\n return yield* unauthenticated;\n }\n\n const crossing = yield* ServiceCrossingPolicyTag;\n if (!crossing.allows(permission)) {\n return yield* forbidden(permission);\n }\n\n const organizationId = request.headers[ORGANIZATION_HEADER]?.trim();\n if (organizationId === undefined || organizationId === '') {\n return yield* organizationRequired;\n }\n\n return yield* use(organizationId);\n });\n\n/**\n * The same fleet check, for a participant that has **no organization to name**.\n *\n * ⚠️ **A platform-plane store is the whole difference.** `requireServiceCrossing`\n * above ends with an organization header because it is about to resolve a tenant\n * database handle from it, and a blank one there would read some other vendor's\n * storage. order-service names one database at boot, so there is no handle to\n * choose — and demanding a header nothing consumes would be theatre that a\n * caller learns to satisfy with any value.\n *\n * What is unchanged, and is the part that matters: the token proves the caller\n * is the fleet, the host's `ServiceCrossingPolicy` says what the fleet may do,\n * and **no session is accepted**. A saga step is not a person's act — the buyer\n * behind a checkout holds no grant over the order the coordinator is writing on\n * their behalf, and accepting their session here would make the weaker\n * credential the security level.\n *\n * The recorded residual carries over verbatim: a shared secret means any process\n * holding it can act, bounded by the permission and by which slices are\n * configured with the key.\n */\nexport const requireCrossing =\n (permission: Permission) =>\n <A, E, R>(route: Effect.Effect<A, E, R>) =>\n Effect.gen(function* () {\n const request = yield* HttpServerRequest.HttpServerRequest;\n const expected = yield* ServiceCrossingTokenTag;\n\n if (!tokenMatches(request.headers[CROSSING_TOKEN_HEADER], expected)) {\n return yield* unauthenticated;\n }\n\n const crossing = yield* ServiceCrossingPolicyTag;\n if (!crossing.allows(permission)) {\n return yield* forbidden(permission);\n }\n\n return yield* route;\n });\n"],"names":["ServiceCrossingPolicyTag","Forbidden","Invalid","Unauthenticated","Context","Effect","HttpServerRequest","refuse","tokenMatches","CROSSING_TOKEN_HEADER","ORGANIZATION_HEADER","COMMAND_ID_HEADER","ServiceCrossingTokenTag","Service","unauthenticated","forbidden","permission","organizationRequired","errors","pointer","detail","code","requireServiceCrossing","use","gen","request","expected","headers","crossing","allows","organizationId","trim","undefined","requireCrossing","route"],"mappings":"AAAA,SAA0BA,wBAAwB,QAAQ,iBAAiB;AAC3E,SAASC,SAAS,EAAEC,OAAO,EAAEC,eAAe,QAAQ,gBAAgB;AACpE,SAASC,OAAO,EAAEC,MAAM,QAAQ,SAAS;AACzC,SAASC,iBAAiB,QAAQ,cAAc;AAEhD,SAASC,MAAM,QAAQ,gBAAgB;AACvC,SAASC,YAAY,QAAQ,oBAAoB;AAEjD;;;;;;;;;CASC,GACD,OAAO,MAAMC,wBAAwB,mBAAmB;AAExD;;;;;;;;;;;;CAYC,GACD,OAAO,MAAMC,sBAAsB,oBAAoB;AAEvD;;;CAGC,GACD,OAAO,MAAMC,oBAAoB,eAAe;AAEhD;;;;;;;;CAQC,GACD,OAAO,MAAMC,gCAAgCR,QAAQS,OAAO,GAGxD;AAA4B;AAEhC,MAAMC,kBAAkBP,OAAO,IAAIJ;AAEnC,MAAMY,YAAY,CAACC,aACjBT,OAAO,IAAIN,UAAU;QAAEe;IAAW;AAEpC,MAAMC,uBAAuBV,OAC3B,IAAIL,QAAQ;IACVgB,QAAQ;QACN;YACEC,SAAS,C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18
18
|
*/
|
|
19
19
|
readonly token: () => string;
|
|
20
20
|
}
|
|
21
|
+
/** Constant-time comparison, so the token cannot be recovered byte by byte. */
|
|
22
|
+
export declare const tokenMatches: (provided: string | undefined, expected: string) => boolean;
|
|
21
23
|
/**
|
|
22
24
|
* Serves `route` only to a caller presenting the shared token.
|
|
23
25
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared-token.d.ts","sourceRoot":"","sources":["../../src/auth/shared-token.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAIhD;;;;;;;GAOG;AACH,MAAM,WAAW,WAAW;IAC1B,uEAAuE;IACvE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB;;;;OAIG;IACH,QAAQ,CAAC,KAAK,EAAE,MAAM,MAAM,CAAC;CAC9B;
|
|
1
|
+
{"version":3,"file":"shared-token.d.ts","sourceRoot":"","sources":["../../src/auth/shared-token.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAIhD;;;;;;;GAOG;AACH,MAAM,WAAW,WAAW;IAC1B,uEAAuE;IACvE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB;;;;OAIG;IACH,QAAQ,CAAC,KAAK,EAAE,MAAM,MAAM,CAAC;CAC9B;AAED,+EAA+E;AAC/E,eAAO,MAAM,YAAY,GACvB,UAAU,MAAM,GAAG,SAAS,EAC5B,UAAU,MAAM,KACf,OAUF,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,kBAAkB,GAC5B,QAAQ,WAAW,MACnB,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,+HAYnC,CAAC"}
|
|
@@ -3,7 +3,7 @@ import { Unauthenticated } from '@entifix/core';
|
|
|
3
3
|
import { Effect } from 'effect';
|
|
4
4
|
import { HttpServerRequest } from 'effect/http';
|
|
5
5
|
import { refuse } from './failures.js';
|
|
6
|
-
/** Constant-time comparison, so the token cannot be recovered byte by byte. */ const
|
|
6
|
+
/** Constant-time comparison, so the token cannot be recovered byte by byte. */ export const tokenMatches = (provided, expected)=>{
|
|
7
7
|
// An empty credential is refused outright, on either side: two empty
|
|
8
8
|
// buffers compare equal, so an unset secret would admit an empty header.
|
|
9
9
|
if (provided === undefined || provided === '' || expected === '') return false;
|
|
@@ -29,7 +29,7 @@ import { refuse } from './failures.js';
|
|
|
29
29
|
// out while omitting it is what makes `tsc` refuse the declaration emit.
|
|
30
30
|
Effect.gen(function*() {
|
|
31
31
|
const request = yield* HttpServerRequest.HttpServerRequest;
|
|
32
|
-
if (!
|
|
32
|
+
if (!tokenMatches(request.headers[shared.header], shared.token())) {
|
|
33
33
|
return yield* refuse(new Unauthenticated());
|
|
34
34
|
}
|
|
35
35
|
return yield* route;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/auth/shared-token.ts"],"sourcesContent":["import { timingSafeEqual } from 'node:crypto';\n\nimport { Unauthenticated } from '@entifix/core';\nimport { Effect } from 'effect';\nimport { HttpServerRequest } from 'effect/http';\n\nimport { refuse } from './failures.js';\n\n/**\n * A secret every caller of a route presents in one header.\n *\n * Both halves are the host's. Which header carries it and where the expected\n * value comes from are a deployment's conventions — a fleet-wide environment\n * variable, a mounted secret, a fixed value in a test — so the framework takes\n * them as values rather than naming either.\n */\nexport interface SharedToken {\n /** The request header the token travels in, e.g. `x-service-token`. */\n readonly header: string;\n /**\n * The expected token, asked for on each request rather than captured once —\n * so a rotated secret, or a test that sets one, takes effect without a\n * restart.\n */\n readonly token: () => string;\n}\n\n/** Constant-time comparison, so the token cannot be recovered byte by byte. */\
|
|
1
|
+
{"version":3,"sources":["../../src/auth/shared-token.ts"],"sourcesContent":["import { timingSafeEqual } from 'node:crypto';\n\nimport { Unauthenticated } from '@entifix/core';\nimport { Effect } from 'effect';\nimport { HttpServerRequest } from 'effect/http';\n\nimport { refuse } from './failures.js';\n\n/**\n * A secret every caller of a route presents in one header.\n *\n * Both halves are the host's. Which header carries it and where the expected\n * value comes from are a deployment's conventions — a fleet-wide environment\n * variable, a mounted secret, a fixed value in a test — so the framework takes\n * them as values rather than naming either.\n */\nexport interface SharedToken {\n /** The request header the token travels in, e.g. `x-service-token`. */\n readonly header: string;\n /**\n * The expected token, asked for on each request rather than captured once —\n * so a rotated secret, or a test that sets one, takes effect without a\n * restart.\n */\n readonly token: () => string;\n}\n\n/** Constant-time comparison, so the token cannot be recovered byte by byte. */\nexport const tokenMatches = (\n provided: string | undefined,\n expected: string,\n): boolean => {\n // An empty credential is refused outright, on either side: two empty\n // buffers compare equal, so an unset secret would admit an empty header.\n if (provided === undefined || provided === '' || expected === '')\n return false;\n const left = Buffer.from(provided);\n const right = Buffer.from(expected);\n // `timingSafeEqual` throws on a length mismatch, so the lengths are compared\n // first — the length of a shared secret is not what protects it.\n return left.length === right.length && timingSafeEqual(left, right);\n};\n\n/**\n * Serves `route` only to a caller presenting the shared token.\n *\n * ⚠️ This is **not** identity: every caller presents the same value, so it\n * proves membership of whatever group holds the secret and nothing more. It is\n * the right shape for a route whose readers are machines — a fleet fetching its\n * configuration at boot, tooling reading a service's wiring — and the wrong one\n * for anything a person or a browser reaches.\n *\n * Health endpoints should stay unguarded: a probe cannot hold a credential, and\n * a readiness check that needs one becomes an authentication problem.\n */\nexport const requireSharedToken =\n (shared: SharedToken) =>\n <A, E, R>(route: Effect.Effect<A, E, R>) =>\n // The return type is inferred rather than written out: `HttpServerResponse.json`\n // contributes an `HttpBodyError` to the failure channel, and spelling the type\n // out while omitting it is what makes `tsc` refuse the declaration emit.\n Effect.gen(function* () {\n const request = yield* HttpServerRequest.HttpServerRequest;\n\n if (!tokenMatches(request.headers[shared.header], shared.token())) {\n return yield* refuse(new Unauthenticated());\n }\n\n return yield* route;\n });\n"],"names":["timingSafeEqual","Unauthenticated","Effect","HttpServerRequest","refuse","tokenMatches","provided","expected","undefined","left","Buffer","from","right","length","requireSharedToken","shared","route","gen","request","headers","header","token"],"mappings":"AAAA,SAASA,eAAe,QAAQ,cAAc;AAE9C,SAASC,eAAe,QAAQ,gBAAgB;AAChD,SAASC,MAAM,QAAQ,SAAS;AAChC,SAASC,iBAAiB,QAAQ,cAAc;AAEhD,SAASC,MAAM,QAAQ,gBAAgB;AAqBvC,6EAA6E,GAC7E,OAAO,MAAMC,eAAe,CAC1BC,UACAC;IAEA,qEAAqE;IACrE,yEAAyE;IACzE,IAAID,aAAaE,aAAaF,aAAa,MAAMC,aAAa,IAC5D,OAAO;IACT,MAAME,OAAOC,OAAOC,IAAI,CAACL;IACzB,MAAMM,QAAQF,OAAOC,IAAI,CAACJ;IAC1B,6EAA6E;IAC7E,iEAAiE;IACjE,OAAOE,KAAKI,MAAM,KAAKD,MAAMC,MAAM,IAAIb,gBAAgBS,MAAMG;AAC/D,EAAE;AAEF;;;;;;;;;;;CAWC,GACD,OAAO,MAAME,qBACX,CAACC,SACD,CAAUC,QACR,iFAAiF;QACjF,+EAA+E;QAC/E,yEAAyE;QACzEd,OAAOe,GAAG,CAAC;YACT,MAAMC,UAAU,OAAOf,kBAAkBA,iBAAiB;YAE1D,IAAI,CAACE,aAAaa,QAAQC,OAAO,CAACJ,OAAOK,MAAM,CAAC,EAAEL,OAAOM,KAAK,KAAK;gBACjE,OAAO,OAAOjB,OAAO,IAAIH;YAC3B;YAEA,OAAO,OAAOe;QAChB,GAAG"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { type VerifiedContext, VerifiedContextTag } from '@entifix/business';
|
|
1
|
+
import { type RequestPrincipal, type VerifiedContext, VerifiedContextTag } from '@entifix/business';
|
|
2
2
|
import { Context, Effect } from 'effect';
|
|
3
|
-
import type { RequestPrincipal } from './require-principal.js';
|
|
4
3
|
declare const VerifiedContextConfigTag_base: Context.ServiceClass<VerifiedContextConfigTag, "@entifix/service-shell/VerifiedContextConfig", Readonly<Record<string, unknown>>>;
|
|
5
4
|
/**
|
|
6
5
|
* The configuration dials a resolver's predicates may read, provided by the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"verified-context.d.ts","sourceRoot":"","sources":["../../src/auth/verified-context.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"verified-context.d.ts","sourceRoot":"","sources":["../../src/auth/verified-context.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACpB,kBAAkB,EACnB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,OAAO,EAAE,MAAM,EAAU,MAAM,QAAQ,CAAC;;AAEjD;;;;GAIG;AACH,qBAAa,wBAAyB,SAAQ,6BAGK;CAAG;AAEtD;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,GAC5B,WAAW,gBAAgB,GAAG,SAAS,EACvC,SAAQ,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAM,KAC7C,eAaC,CAAC;AAEL;;;GAGG;AACH,eAAO,MAAM,mBAAmB,GAAI,CAAC,EAAE,CAAC,EAAE,CAAC,EACzC,WAAW,gBAAgB,GAAG,SAAS,EACvC,KAAK,CAAC,QAAQ,EAAE,eAAe,KAAK,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,KACzD,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC,EAAE,kBAAkB,CAAC,CAUjD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/auth/verified-context.ts"],"sourcesContent":["import { type VerifiedContext
|
|
1
|
+
{"version":3,"sources":["../../src/auth/verified-context.ts"],"sourcesContent":["import {\n type RequestPrincipal,\n type VerifiedContext,\n VerifiedContextTag,\n} from '@entifix/business';\nimport { verifiedContext } from '@entifix/business/verified';\nimport { Context, Effect, Option } from 'effect';\n\n/**\n * The configuration dials a resolver's predicates may read, provided by the\n * composition root. Optional: a service that resolves nothing on a dial\n * provides none, and its contexts carry an empty `config`.\n */\nexport class VerifiedContextConfigTag extends Context.Service<\n VerifiedContextConfigTag,\n Readonly<Record<string, unknown>>\n>()('@entifix/service-shell/VerifiedContextConfig') {}\n\n/**\n * The verified context of a caller: what their verified token says, and the\n * service's dials — never anything the request carries\n * ([ADR 0015](../../../../../docs/adr/0015-composed-flows-and-use-case-resolution.md)).\n * No principal is an anonymous caller: no organization, no party, nothing held.\n */\nexport const verifiedContextOf = (\n principal: RequestPrincipal | undefined,\n config: Readonly<Record<string, unknown>> = {},\n): VerifiedContext =>\n verifiedContext({\n ...(principal?.organizationId === undefined\n ? {}\n : { organizationId: principal.organizationId }),\n ...(principal?.partyId === undefined ? {} : { partyId: principal.partyId }),\n ...(principal?.partyRole === undefined\n ? {}\n : { partyRole: principal.partyRole }),\n entitlements: principal?.entitlements ?? [],\n roles: principal?.roles ?? [],\n flags: [],\n config,\n });\n\n/**\n * Runs `use` with the caller's verified context built and provided as\n * {@link VerifiedContextTag} — the one place a request's context is made.\n */\nexport const withVerifiedContext = <A, E, R>(\n principal: RequestPrincipal | undefined,\n use: (verified: VerifiedContext) => Effect.Effect<A, E, R>,\n): Effect.Effect<A, E, Exclude<R, VerifiedContextTag>> =>\n Effect.gen(function* () {\n const config = yield* Effect.serviceOption(VerifiedContextConfigTag);\n const verified = verifiedContextOf(\n principal,\n Option.getOrElse(config, () => ({})),\n );\n return yield* use(verified).pipe(\n Effect.provideService(VerifiedContextTag, verified),\n );\n });\n"],"names":["VerifiedContextTag","verifiedContext","Context","Effect","Option","VerifiedContextConfigTag","Service","verifiedContextOf","principal","config","organizationId","undefined","partyId","partyRole","entitlements","roles","flags","withVerifiedContext","use","gen","serviceOption","verified","getOrElse","pipe","provideService"],"mappings":";AAAA,SAGEA,kBAAkB,QACb,oBAAoB;AAC3B,SAASC,eAAe,QAAQ,6BAA6B;AAC7D,SAASC,OAAO,EAAEC,MAAM,EAAEC,MAAM,QAAQ,SAAS;AAEjD;;;;CAIC,GACD,OAAO,MAAMC,iCAAiCH,QAAQI,OAAO,GAGzD;AAAiD;AAErD;;;;;CAKC,GACD,OAAO,MAAMC,oBAAoB,CAC/BC,WACAC,SAA4C,CAAC,CAAC;;WAE9CR,gBAAgB,aACVO,CAAAA,6BAAAA,UAAWE,cAAc,MAAKC,YAC9B,CAAC,IACD;QAAED,gBAAgBF,UAAUE,cAAc;IAAC,GAC3CF,CAAAA,6BAAAA,UAAWI,OAAO,MAAKD,YAAY,CAAC,IAAI;QAAEC,SAASJ,UAAUI,OAAO;IAAC,GACrEJ,CAAAA,6BAAAA,UAAWK,SAAS,MAAKF,YACzB,CAAC,IACD;QAAEE,WAAWL,UAAUK,SAAS;IAAC;QACrCC,YAAY,UAAEN,6BAAAA,UAAWM,YAAY,mBAAI,EAAE;QAC3CC,KAAK,WAAEP,6BAAAA,UAAWO,KAAK,oBAAI,EAAE;QAC7BC,OAAO,EAAE;QACTP;;EACC;AAEL;;;CAGC,GACD,OAAO,MAAMQ,sBAAsB,CACjCT,WACAU,MAEAf,OAAOgB,GAAG,CAAC;QACT,MAAMV,SAAS,OAAON,OAAOiB,aAAa,CAACf;QAC3C,MAAMgB,WAAWd,kBACfC,WACAJ,OAAOkB,SAAS,CAACb,QAAQ,IAAO,CAAA,CAAC,CAAA;QAEnC,OAAO,OAAOS,IAAIG,UAAUE,IAAI,CAC9BpB,OAAOqB,cAAc,CAACxB,oBAAoBqB;IAE9C,GAAG"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import type { NarrowingRules } from '@entifix/business';
|
|
1
2
|
import { EntityFacetCounterFactoryTag } from '@entifix/business';
|
|
2
3
|
import { type Entity, type EntityConstructor } from '@entifix/core';
|
|
3
4
|
import { Effect } from 'effect';
|
|
4
5
|
import { HttpRouter } from 'effect/http';
|
|
5
6
|
import { type EntityReadScope, type EntityRouteContext, type EntityRouteGuard } from './entity-route-guard.js';
|
|
6
|
-
import { type NarrowingRules } from './narrowing.js';
|
|
7
7
|
import { type FailurePolicy } from './respond.js';
|
|
8
8
|
export interface EntityFacetRoutesOptions<T extends Entity, R, G extends EntityRouteGuard = EntityRouteGuard> {
|
|
9
9
|
/** Who may count: the guard the entity's `list` has, as a rule. */
|
|
@@ -38,7 +38,7 @@ export interface EntityFacetRoutesOptions<T extends Entity, R, G extends EntityR
|
|
|
38
38
|
* **conjoined into every facet's filtering**, never substituted, so no query
|
|
39
39
|
* string can count past it; `'none'` answers every member empty.
|
|
40
40
|
*/
|
|
41
|
-
export declare const makeEntityFacetRoutes: <T extends Entity, R = never, const G extends EntityRouteGuard = never>(entityConstructor: EntityConstructor<T>, options: EntityFacetRoutesOptions<T, R, G>) => import("effect/Layer").Layer<never, never, HttpRouter.HttpRouter | HttpRouter.Request<"Requires",
|
|
41
|
+
export declare const makeEntityFacetRoutes: <T extends Entity, R = never, const G extends EntityRouteGuard = never>(entityConstructor: EntityConstructor<T>, options: EntityFacetRoutesOptions<T, R, G>) => import("effect/Layer").Layer<never, never, HttpRouter.HttpRouter | HttpRouter.Request<"Requires", import("@entifix/business").TokenServiceTag> | HttpRouter.Request<"Requires", EntityFacetCounterFactoryTag> | HttpRouter.Request<"Requires", import("@entifix/authz").PolicyDecisionTag> | HttpRouter.Request.From<"Requires", Exclude<Exclude<R, HttpRouter.Provided>, HttpRouter.Provided>> | HttpRouter.Request.From<"Requires", Exclude<Exclude<G extends {
|
|
42
42
|
readonly kind: "crossing";
|
|
43
43
|
} ? import("@entifix/authz").ServiceCrossingPolicyTag | import("./index.js").ServiceCrossingTokenTag : never, HttpRouter.Provided>, HttpRouter.Provided>>>;
|
|
44
44
|
//# sourceMappingURL=entity-facet-routes.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entity-facet-routes.d.ts","sourceRoot":"","sources":["../src/entity-facet-routes.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,4BAA4B,EAG7B,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAEL,KAAK,MAAM,EACX,KAAK,iBAAiB,EAMvB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,UAAU,EAAyC,MAAM,aAAa,CAAC;AAEhF,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,EAGtB,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"entity-facet-routes.d.ts","sourceRoot":"","sources":["../src/entity-facet-routes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAa,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnE,OAAO,EACL,4BAA4B,EAG7B,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAEL,KAAK,MAAM,EACX,KAAK,iBAAiB,EAMvB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,UAAU,EAAyC,MAAM,aAAa,CAAC;AAEhF,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,EAGtB,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAEL,KAAK,aAAa,EAEnB,MAAM,cAAc,CAAC;AAGtB,MAAM,WAAW,wBAAwB,CACvC,CAAC,SAAS,MAAM,EAChB,CAAC,EACD,CAAC,SAAS,gBAAgB,GAAG,gBAAgB;IAE7C,mEAAmE;IACnE,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC;IAClB,0EAA0E;IAC1E,QAAQ,CAAC,QAAQ,CAAC,EAAE,IAAI,MAAM,EAAE,CAAC;IACjC;;;;OAIG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,CACf,OAAO,EAAE,kBAAkB,KACxB,MAAM,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;IACjD;;;OAGG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,cAAc,CAAC,CAAC,CAAC,CAAC;IACvC,wDAAwD;IACxD,QAAQ,CAAC,MAAM,CAAC,EAAE,aAAa,CAAC;CACjC;AAED;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,qBAAqB,GAChC,CAAC,SAAS,MAAM,EAChB,CAAC,GAAG,KAAK,EAGT,KAAK,CAAC,CAAC,SAAS,gBAAgB,GAAG,KAAK,EAExC,mBAAmB,iBAAiB,CAAC,CAAC,CAAC,EACvC,SAAS,wBAAwB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;;0JAyF3C,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/entity-facet-routes.ts"],"sourcesContent":["import {\n EntityFacetCounterFactoryTag,\n EntityFacetCounterTag,\n facetCountsUCFactory,\n} from '@entifix/business';\nimport type { EntifixFailure } from '@entifix/core';\nimport {\n EntifixBuildError,\n type Entity,\n type EntityConstructor,\n type EntityFacetCounts,\n type EntityFacetQuery,\n envelopeEntityName,\n makeEntityFacetsEnvelope,\n parseFacetQueryParams,\n} from '@entifix/core';\nimport { Effect } from 'effect';\nimport { HttpRouter, HttpServerRequest, HttpServerResponse } from 'effect/http';\n\nimport {\n type EntityReadScope,\n type EntityRouteContext,\n type EntityRouteGuard,\n guardRoute,\n type GuardServices,\n} from './entity-route-guard.js';\nimport {
|
|
1
|
+
{"version":3,"sources":["../src/entity-facet-routes.ts"],"sourcesContent":["import type { Narrowing, NarrowingRules } from '@entifix/business';\nimport {\n EntityFacetCounterFactoryTag,\n EntityFacetCounterTag,\n facetCountsUCFactory,\n} from '@entifix/business';\nimport type { EntifixFailure } from '@entifix/core';\nimport {\n EntifixBuildError,\n type Entity,\n type EntityConstructor,\n type EntityFacetCounts,\n type EntityFacetQuery,\n envelopeEntityName,\n makeEntityFacetsEnvelope,\n parseFacetQueryParams,\n} from '@entifix/core';\nimport { Effect } from 'effect';\nimport { HttpRouter, HttpServerRequest, HttpServerResponse } from 'effect/http';\n\nimport {\n type EntityReadScope,\n type EntityRouteContext,\n type EntityRouteGuard,\n guardRoute,\n type GuardServices,\n} from './entity-route-guard.js';\nimport { narrowingFor } from './narrowing.js';\nimport {\n defaultFailurePolicy,\n type FailurePolicy,\n respond,\n} from './respond.js';\nimport { legacyAnswer } from './route-responses.js';\n\nexport interface EntityFacetRoutesOptions<\n T extends Entity,\n R,\n G extends EntityRouteGuard = EntityRouteGuard,\n> {\n /** Who may count: the guard the entity's `list` has, as a rule. */\n readonly guard: G;\n /** Defaults to `/api/<entity key>`; the route is `<basePath>/$facets`. */\n readonly basePath?: `/${string}`;\n /**\n * Narrows the counts to the records this caller may see — the same scope\n * the entity's `list` takes, so a count never reveals a record the list\n * would not.\n */\n readonly scope?: (\n context: EntityRouteContext,\n ) => Effect.Effect<EntityReadScope<T>, never, R>;\n /**\n * The same narrowing the entity's `list` takes, as resolver rules — so a\n * count equals the narrowed list. Replaces `scope`; naming both throws.\n */\n readonly narrowing?: NarrowingRules<T>;\n /** How the count's failures are answered and logged. */\n readonly policy?: FailurePolicy;\n}\n\n/**\n * `GET <base>/$facets` — how many of the entity's records hold each value of\n * each `facet` member, each under its own `rsql.<member>` filtering — bound to\n * storage through the host's {@link EntityFacetCounterFactoryTag}.\n *\n * A route of its own beside `makeEntityRoutes` rather than a sixth verb, so it\n * is the one route set that requires a counter: a host that mounts it without\n * binding one fails to compile, and a host that never counts binds nothing.\n *\n * The query is parsed against the entity's metadata, so only a `filterable`\n * member is counted and every malformed request is a `400`. A scope is\n * **conjoined into every facet's filtering**, never substituted, so no query\n * string can count past it; `'none'` answers every member empty.\n */\nexport const makeEntityFacetRoutes = <\n T extends Entity,\n R = never,\n // `never` for the reason `makeEntityRoutes` gives: a caller naming `R`\n // explicitly must not widen the guard to every kind there is.\n const G extends EntityRouteGuard = never,\n>(\n entityConstructor: EntityConstructor<T>,\n options: EntityFacetRoutesOptions<T, R, G>,\n) => {\n const base: `/${string}` =\n options.basePath ?? `/api/${envelopeEntityName(entityConstructor)}`;\n\n const readQueries = Effect.gen(function* () {\n const request = yield* HttpServerRequest.HttpServerRequest;\n const search = new URL(request.url, 'http://localhost').searchParams;\n return yield* Effect.try({\n try: () => parseFacetQueryParams(entityConstructor, search),\n catch: error => error as EntifixBuildError,\n });\n });\n\n const narrowed = (\n queries: EntityFacetQuery<T>[],\n narrowing: Exclude<Narrowing<T>, 'nothing'>,\n ): EntityFacetQuery<T>[] =>\n narrowing === 'unscoped'\n ? queries\n : queries.map(query => ({\n ...query,\n filtering: [...(query.filtering ?? []), narrowing],\n }));\n\n if (options.narrowing !== undefined && options.scope !== undefined)\n throw new Error(\n `the facet route for '${envelopeEntityName(entityConstructor)}' names both ` +\n '`narrowing` and `scope`; `narrowing` replaces `scope`, so name one.',\n );\n\n /** A scope, as the narrowing this route applies. */\n const asNarrowing = (scope: EntityReadScope<T>): Narrowing<T> =>\n scope === 'all' ? 'unscoped' : scope === 'none' ? 'nothing' : scope.filter;\n\n const count = (context: EntityRouteContext) =>\n Effect.gen(function* () {\n const queries = yield* readQueries;\n const narrowing =\n options.narrowing !== undefined && context.verified !== undefined\n ? narrowingFor(options.narrowing, context.verified)\n : asNarrowing(\n options.scope ? yield* options.scope(context) : ('all' as const),\n );\n if (narrowing === 'nothing') {\n // Still parsed: whether a query is well-formed must not depend on who\n // asked.\n const empty: EntityFacetCounts = Object.fromEntries(\n queries.map(({ member }) => [member, []]),\n );\n return yield* HttpServerResponse.json(\n makeEntityFacetsEnvelope(entityConstructor, empty),\n );\n }\n const factory = yield* EntityFacetCounterFactoryTag;\n const counter = yield* factory.for(entityConstructor, {\n ...(context.organizationId === undefined\n ? {}\n : { organizationId: context.organizationId }),\n });\n const counts = yield* facetCountsUCFactory<T>(\n narrowed(queries, narrowing),\n ).pipe(Effect.provideService(EntityFacetCounterTag, counter));\n return yield* HttpServerResponse.json(\n makeEntityFacetsEnvelope(entityConstructor, counts),\n );\n }).pipe(Effect.catch(legacyAnswer('invalidQuery')));\n\n const handler = respond(\n guardRoute(\n entityConstructor,\n options.guard,\n 'read',\n count,\n ) as Effect.Effect<\n HttpServerResponse.HttpServerResponse,\n EntifixFailure,\n | R\n | EntityFacetCounterFactoryTag\n | GuardServices<G>\n | HttpServerRequest.HttpServerRequest\n | HttpRouter.RouteContext\n >,\n options.policy ?? defaultFailurePolicy,\n );\n\n return HttpRouter.addAll([\n HttpRouter.route('GET', `${base}/$facets`, handler),\n ]);\n};\n"],"names":["EntityFacetCounterFactoryTag","EntityFacetCounterTag","facetCountsUCFactory","envelopeEntityName","makeEntityFacetsEnvelope","parseFacetQueryParams","Effect","HttpRouter","HttpServerRequest","HttpServerResponse","guardRoute","narrowingFor","defaultFailurePolicy","respond","legacyAnswer","makeEntityFacetRoutes","entityConstructor","options","base","basePath","readQueries","gen","request","search","URL","url","searchParams","try","catch","error","narrowed","queries","narrowing","map","query","filtering","undefined","scope","Error","asNarrowing","filter","count","context","verified","empty","Object","fromEntries","member","json","factory","counter","for","organizationId","counts","pipe","provideService","handler","guard","policy","addAll","route"],"mappings":";AACA,SACEA,4BAA4B,EAC5BC,qBAAqB,EACrBC,oBAAoB,QACf,oBAAoB;AAE3B,SAMEC,kBAAkB,EAClBC,wBAAwB,EACxBC,qBAAqB,QAChB,gBAAgB;AACvB,SAASC,MAAM,QAAQ,SAAS;AAChC,SAASC,UAAU,EAAEC,iBAAiB,EAAEC,kBAAkB,QAAQ,cAAc;AAEhF,SAIEC,UAAU,QAEL,0BAA0B;AACjC,SAASC,YAAY,QAAQ,iBAAiB;AAC9C,SACEC,oBAAoB,EAEpBC,OAAO,QACF,eAAe;AACtB,SAASC,YAAY,QAAQ,uBAAuB;AA4BpD;;;;;;;;;;;;;CAaC,GACD,OAAO,MAAMC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G,CAAC,CAAC,EAAEc,MAAM,EAAE,GAAK;wBAACA;wBAAQ,EAAE;qBAAC;gBAE1C,OAAO,OAAOtC,mBAAmBuC,IAAI,CACnC5C,yBAAyBY,mBAAmB4B;YAEhD;YACA,MAAMK,UAAU,OAAOjD;YACvB,MAAMkD,UAAU,OAAOD,QAAQE,GAAG,CAACnC,mBAAmB,aAChD0B,QAAQU,cAAc,KAAKhB,YAC3B,CAAC,IACD;gBAAEgB,gBAAgBV,QAAQU,cAAc;YAAC;YAE/C,MAAMC,SAAS,OAAOnD,qBACpB4B,SAASC,SAASC,YAClBsB,IAAI,CAAChD,OAAOiD,cAAc,CAACtD,uBAAuBiD;YACpD,OAAO,OAAOzC,mBAAmBuC,IAAI,CACnC5C,yBAAyBY,mBAAmBqC;QAEhD,GAAGC,IAAI,CAAChD,OAAOsB,KAAK,CAACd,aAAa;IAEpC,MAAM0C,UAAU3C,QACdH,WACEM,mBACAC,QAAQwC,KAAK,EACb,QACAhB,SAUFxB,kBAAAA,QAAQyC,MAAM,YAAdzC,kBAAkBL;IAGpB,OAAOL,WAAWoD,MAAM,CAAC;QACvBpD,WAAWqD,KAAK,CAAC,OAAO,GAAG1C,KAAK,QAAQ,CAAC,EAAEsC;KAC5C;AACH,EAAE"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { type Action, type PolicyDecisionTag, type ServiceCrossingPolicyTag } from '@entifix/authz';
|
|
2
|
-
import type { RepositoryScope, TokenServiceTag, VerifiedContext } from '@entifix/business';
|
|
2
|
+
import type { RepositoryScope, RequestPrincipal, TokenServiceTag, VerifiedContext } from '@entifix/business';
|
|
3
3
|
import type { Entity, EntityConstructor, FilterGroup } from '@entifix/core';
|
|
4
4
|
import type { Effect } from 'effect';
|
|
5
|
-
import { type
|
|
5
|
+
import { type ServiceCrossingTokenTag } from './auth/index.js';
|
|
6
6
|
/**
|
|
7
7
|
* Who may reach a route, and where the organization a per-organization store
|
|
8
8
|
* needs comes from.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entity-route-guard.d.ts","sourceRoot":"","sources":["../src/entity-route-guard.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,MAAM,EAEX,KAAK,iBAAiB,EACtB,KAAK,wBAAwB,EAC9B,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EACV,eAAe,EACf,eAAe,EACf,eAAe,EAChB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,MAAM,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAErC,OAAO,
|
|
1
|
+
{"version":3,"file":"entity-route-guard.d.ts","sourceRoot":"","sources":["../src/entity-route-guard.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,MAAM,EAEX,KAAK,iBAAiB,EACtB,KAAK,wBAAwB,EAC9B,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EACV,eAAe,EACf,gBAAgB,EAChB,eAAe,EACf,eAAe,EAChB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,MAAM,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAErC,OAAO,EAKL,KAAK,uBAAuB,EAE7B,MAAM,iBAAiB,CAAC;AAEzB;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,gBAAgB,GACxB;IAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAA;CAAE,GAC3B;IAAE,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAA;CAAE,GAC/B;IAAE,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAA;CAAE,GACjC;IAAE,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAAC,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAA;CAAE,CAAC;AAElE,4DAA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