@dads-framework/access 0.0.0-stage → 0.1.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/LICENSE.md +21 -0
- package/README.md +78 -2
- package/dist/access.tsbuildinfo +1 -0
- package/dist/core/access-model.d.ts +30 -0
- package/dist/core/access-model.d.ts.map +1 -0
- package/dist/core/access-model.js +27 -0
- package/dist/core/access-model.js.map +1 -0
- package/dist/core/catalog-only.d.ts +42 -0
- package/dist/core/catalog-only.d.ts.map +1 -0
- package/dist/core/catalog-only.js +29 -0
- package/dist/core/catalog-only.js.map +1 -0
- package/dist/core/combinators.d.ts +25 -0
- package/dist/core/combinators.d.ts.map +1 -0
- package/dist/core/combinators.js +61 -0
- package/dist/core/combinators.js.map +1 -0
- package/dist/core/compare-access-ir.d.ts +9 -0
- package/dist/core/compare-access-ir.d.ts.map +1 -0
- package/dist/core/compare-access-ir.js +170 -0
- package/dist/core/compare-access-ir.js.map +1 -0
- package/dist/core/conformance.d.ts +21 -0
- package/dist/core/conformance.d.ts.map +1 -0
- package/dist/core/conformance.js +87 -0
- package/dist/core/conformance.js.map +1 -0
- package/dist/core/emit-ir.d.ts +8 -0
- package/dist/core/emit-ir.d.ts.map +1 -0
- package/dist/core/emit-ir.js +103 -0
- package/dist/core/emit-ir.js.map +1 -0
- package/dist/core/emit-zed.d.ts +9 -0
- package/dist/core/emit-zed.d.ts.map +1 -0
- package/dist/core/emit-zed.js +76 -0
- package/dist/core/emit-zed.js.map +1 -0
- package/dist/core/entity-handle.d.ts +39 -0
- package/dist/core/entity-handle.d.ts.map +1 -0
- package/dist/core/entity-handle.js +15 -0
- package/dist/core/entity-handle.js.map +1 -0
- package/dist/core/entity-kinds.d.ts +24 -0
- package/dist/core/entity-kinds.d.ts.map +1 -0
- package/dist/core/entity-kinds.js +30 -0
- package/dist/core/entity-kinds.js.map +1 -0
- package/dist/core/generated-header.d.ts +4 -0
- package/dist/core/generated-header.d.ts.map +1 -0
- package/dist/core/generated-header.js +6 -0
- package/dist/core/generated-header.js.map +1 -0
- package/dist/core/grantable.d.ts +62 -0
- package/dist/core/grantable.d.ts.map +1 -0
- package/dist/core/grantable.js +31 -0
- package/dist/core/grantable.js.map +1 -0
- package/dist/core/holders.d.ts +26 -0
- package/dist/core/holders.d.ts.map +1 -0
- package/dist/core/holders.js +38 -0
- package/dist/core/holders.js.map +1 -0
- package/dist/core/ir.d.ts +51 -0
- package/dist/core/ir.d.ts.map +1 -0
- package/dist/core/ir.js +2 -0
- package/dist/core/ir.js.map +1 -0
- package/dist/core/lifecycle.d.ts +10 -0
- package/dist/core/lifecycle.d.ts.map +1 -0
- package/dist/core/lifecycle.js +4 -0
- package/dist/core/lifecycle.js.map +1 -0
- package/dist/core/model.d.ts +43 -0
- package/dist/core/model.d.ts.map +1 -0
- package/dist/core/model.js +100 -0
- package/dist/core/model.js.map +1 -0
- package/dist/core/parse-zed.d.ts +8 -0
- package/dist/core/parse-zed.d.ts.map +1 -0
- package/dist/core/parse-zed.js +197 -0
- package/dist/core/parse-zed.js.map +1 -0
- package/dist/core/refs.d.ts +43 -0
- package/dist/core/refs.d.ts.map +1 -0
- package/dist/core/refs.js +28 -0
- package/dist/core/refs.js.map +1 -0
- package/dist/core/scope-binding-check.d.ts +11 -0
- package/dist/core/scope-binding-check.d.ts.map +1 -0
- package/dist/core/scope-binding-check.js +51 -0
- package/dist/core/scope-binding-check.js.map +1 -0
- package/dist/core/scope-bindings.d.ts +47 -0
- package/dist/core/scope-bindings.d.ts.map +1 -0
- package/dist/core/scope-bindings.js +8 -0
- package/dist/core/scope-bindings.js.map +1 -0
- package/dist/core/scope-plan-read.d.ts +9 -0
- package/dist/core/scope-plan-read.d.ts.map +1 -0
- package/dist/core/scope-plan-read.js +44 -0
- package/dist/core/scope-plan-read.js.map +1 -0
- package/dist/core/scope-plan-simplify.d.ts +5 -0
- package/dist/core/scope-plan-simplify.d.ts.map +1 -0
- package/dist/core/scope-plan-simplify.js +71 -0
- package/dist/core/scope-plan-simplify.js.map +1 -0
- package/dist/core/scope-plan.d.ts +77 -0
- package/dist/core/scope-plan.d.ts.map +1 -0
- package/dist/core/scope-plan.js +190 -0
- package/dist/core/scope-plan.js.map +1 -0
- package/dist/core/visible-record-exceptions.d.ts +21 -0
- package/dist/core/visible-record-exceptions.d.ts.map +1 -0
- package/dist/core/visible-record-exceptions.js +27 -0
- package/dist/core/visible-record-exceptions.js.map +1 -0
- package/dist/core/world.d.ts +44 -0
- package/dist/core/world.d.ts.map +1 -0
- package/dist/core/world.js +60 -0
- package/dist/core/world.js.map +1 -0
- package/dist/core/write-artifacts.d.ts +15 -0
- package/dist/core/write-artifacts.d.ts.map +1 -0
- package/dist/core/write-artifacts.js +53 -0
- package/dist/core/write-artifacts.js.map +1 -0
- package/dist/core/zod-enums.d.ts +3 -0
- package/dist/core/zod-enums.d.ts.map +1 -0
- package/dist/core/zod-enums.js +9 -0
- package/dist/core/zod-enums.js.map +1 -0
- package/dist/index.d.ts +40 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -0
- package/dist/runtime/access-changes.d.ts +92 -0
- package/dist/runtime/access-changes.d.ts.map +1 -0
- package/dist/runtime/access-changes.js +57 -0
- package/dist/runtime/access-changes.js.map +1 -0
- package/dist/runtime/answer-once-authorization.d.ts +40 -0
- package/dist/runtime/answer-once-authorization.d.ts.map +1 -0
- package/dist/runtime/answer-once-authorization.js +172 -0
- package/dist/runtime/answer-once-authorization.js.map +1 -0
- package/dist/runtime/apply-access-changes-after-commit.d.ts +39 -0
- package/dist/runtime/apply-access-changes-after-commit.d.ts.map +1 -0
- package/dist/runtime/apply-access-changes-after-commit.js +37 -0
- package/dist/runtime/apply-access-changes-after-commit.js.map +1 -0
- package/dist/runtime/authorization-consistency-cookie.d.ts +9 -0
- package/dist/runtime/authorization-consistency-cookie.d.ts.map +1 -0
- package/dist/runtime/authorization-consistency-cookie.js +46 -0
- package/dist/runtime/authorization-consistency-cookie.js.map +1 -0
- package/dist/runtime/authorization-consistency.d.ts +6 -0
- package/dist/runtime/authorization-consistency.d.ts.map +1 -0
- package/dist/runtime/authorization-consistency.js +23 -0
- package/dist/runtime/authorization-consistency.js.map +1 -0
- package/dist/runtime/authorization.d.ts +137 -0
- package/dist/runtime/authorization.d.ts.map +1 -0
- package/dist/runtime/authorization.js +35 -0
- package/dist/runtime/authorization.js.map +1 -0
- package/dist/runtime/fake-authorization.d.ts +39 -0
- package/dist/runtime/fake-authorization.d.ts.map +1 -0
- package/dist/runtime/fake-authorization.js +147 -0
- package/dist/runtime/fake-authorization.js.map +1 -0
- package/dist/runtime/index.d.ts +13 -0
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/index.js +12 -0
- package/dist/runtime/index.js.map +1 -0
- package/dist/runtime/owner-lock.d.ts +36 -0
- package/dist/runtime/owner-lock.d.ts.map +1 -0
- package/dist/runtime/owner-lock.js +102 -0
- package/dist/runtime/owner-lock.js.map +1 -0
- package/dist/runtime/present-token.d.ts +2 -0
- package/dist/runtime/present-token.d.ts.map +1 -0
- package/dist/runtime/present-token.js +4 -0
- package/dist/runtime/present-token.js.map +1 -0
- package/dist/runtime/question-identity.d.ts +5 -0
- package/dist/runtime/question-identity.d.ts.map +1 -0
- package/dist/runtime/question-identity.js +16 -0
- package/dist/runtime/question-identity.js.map +1 -0
- package/dist/runtime/recording-authorization.d.ts +39 -0
- package/dist/runtime/recording-authorization.d.ts.map +1 -0
- package/dist/runtime/recording-authorization.js +56 -0
- package/dist/runtime/recording-authorization.js.map +1 -0
- package/dist/runtime/relationship-page.d.ts +12 -0
- package/dist/runtime/relationship-page.d.ts.map +1 -0
- package/dist/runtime/relationship-page.js +2 -0
- package/dist/runtime/relationship-page.js.map +1 -0
- package/dist/runtime/request-subject.d.ts +49 -0
- package/dist/runtime/request-subject.d.ts.map +1 -0
- package/dist/runtime/request-subject.js +8 -0
- package/dist/runtime/request-subject.js.map +1 -0
- package/dist/runtime/resolve-read-consistency.d.ts +15 -0
- package/dist/runtime/resolve-read-consistency.d.ts.map +1 -0
- package/dist/runtime/resolve-read-consistency.js +13 -0
- package/dist/runtime/resolve-read-consistency.js.map +1 -0
- package/dist/runtime/route-access.d.ts +66 -0
- package/dist/runtime/route-access.d.ts.map +1 -0
- package/dist/runtime/route-access.js +35 -0
- package/dist/runtime/route-access.js.map +1 -0
- package/dist/runtime/scope-answer.d.ts +47 -0
- package/dist/runtime/scope-answer.d.ts.map +1 -0
- package/dist/runtime/scope-answer.js +84 -0
- package/dist/runtime/scope-answer.js.map +1 -0
- package/dist/runtime/testing.d.ts +4 -0
- package/dist/runtime/testing.d.ts.map +1 -0
- package/dist/runtime/testing.js +4 -0
- package/dist/runtime/testing.js.map +1 -0
- package/dist/schema/apply-desired-schema.d.ts +20 -0
- package/dist/schema/apply-desired-schema.d.ts.map +1 -0
- package/dist/schema/apply-desired-schema.js +115 -0
- package/dist/schema/apply-desired-schema.js.map +1 -0
- package/dist/schema/authorization-schema-store.d.ts +13 -0
- package/dist/schema/authorization-schema-store.d.ts.map +1 -0
- package/dist/schema/authorization-schema-store.js +3 -0
- package/dist/schema/authorization-schema-store.js.map +1 -0
- package/dist/schema/index.d.ts +6 -0
- package/dist/schema/index.d.ts.map +1 -0
- package/dist/schema/index.js +6 -0
- package/dist/schema/index.js.map +1 -0
- package/dist/schema/logic/parse-write-schema-blocker.d.ts +16 -0
- package/dist/schema/logic/parse-write-schema-blocker.d.ts.map +1 -0
- package/dist/schema/logic/parse-write-schema-blocker.js +42 -0
- package/dist/schema/logic/parse-write-schema-blocker.js.map +1 -0
- package/dist/schema/logic/parse-zed-schema-surface.d.ts +11 -0
- package/dist/schema/logic/parse-zed-schema-surface.d.ts.map +1 -0
- package/dist/schema/logic/parse-zed-schema-surface.js +54 -0
- package/dist/schema/logic/parse-zed-schema-surface.js.map +1 -0
- package/dist/schema/logic/plan-schema-contraction.d.ts +9 -0
- package/dist/schema/logic/plan-schema-contraction.d.ts.map +1 -0
- package/dist/schema/logic/plan-schema-contraction.js +21 -0
- package/dist/schema/logic/plan-schema-contraction.js.map +1 -0
- package/package.json +50 -4
package/dist/index.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export { asPermissionTerm, both, excluding, gated, through, } from "./core/combinators.js";
|
|
2
|
+
export { checkAccessConformance, missingGrantingAdvisories, } from "./core/conformance.js";
|
|
3
|
+
export { accessIrDefinitionsDiff, accessIrDiff, } from "./core/compare-access-ir.js";
|
|
4
|
+
export { catalogOnly, isCatalogOnlyCapability } from "./core/catalog-only.js";
|
|
5
|
+
export { emitAccessIr } from "./core/emit-ir.js";
|
|
6
|
+
export { emitZed, emitZedForDefinitions } from "./core/emit-zed.js";
|
|
7
|
+
export { entityHandle } from "./core/entity-handle.js";
|
|
8
|
+
export { entitiesWithoutKind, entityKindOf, isSparseDirectGrant, } from "./core/entity-kinds.js";
|
|
9
|
+
export { allowVisibleOnRecordUntil, expiredVisibleRecordExceptions, visibleRecordException, } from "./core/visible-record-exceptions.js";
|
|
10
|
+
export { scopeBindings } from "./core/scope-bindings.js";
|
|
11
|
+
export { compileScopePlan, compileScopePlanInSchema, describeScopePlan, distinctScopeLookups, planScope, scopeSchema, } from "./core/scope-plan.js";
|
|
12
|
+
export { checkScopeBindings, checkScopeBindingsInSchema, } from "./core/scope-binding-check.js";
|
|
13
|
+
export { GENERATED_ZED_HEADER, isGeneratedByAccessKit, } from "./core/generated-header.js";
|
|
14
|
+
export { grantable, isGrantableRole } from "./core/grantable.js";
|
|
15
|
+
export { membersOf, wildcard } from "./core/holders.js";
|
|
16
|
+
export { lifecycleTrigger } from "./core/lifecycle.js";
|
|
17
|
+
export { access } from "./core/model.js";
|
|
18
|
+
export { parseZed } from "./core/parse-zed.js";
|
|
19
|
+
export { isPermissionToken, isRoleToken, permissionToken, roleToken, } from "./core/refs.js";
|
|
20
|
+
export { accessModel } from "./core/access-model.js";
|
|
21
|
+
export { world } from "./core/world.js";
|
|
22
|
+
export { writeAccessArtifacts } from "./core/write-artifacts.js";
|
|
23
|
+
export { zodEnumFromNames } from "./core/zod-enums.js";
|
|
24
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,IAAI,EACJ,SAAS,EACT,KAAK,EACL,OAAO,GACR,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EACL,sBAAsB,EACtB,yBAAyB,GAC1B,MAAM,uBAAuB,CAAC;AAK/B,OAAO,EACL,uBAAuB,EACvB,YAAY,GACb,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AAE9E,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AACpE,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAEvD,OAAO,EACL,mBAAmB,EACnB,YAAY,EACZ,mBAAmB,GACpB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,yBAAyB,EACzB,8BAA8B,EAC9B,sBAAsB,GACvB,MAAM,qCAAqC,CAAC;AAE7C,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAMzD,OAAO,EACL,gBAAgB,EAChB,wBAAwB,EACxB,iBAAiB,EACjB,oBAAoB,EACpB,SAAS,EACT,WAAW,GACZ,MAAM,sBAAsB,CAAC;AAS9B,OAAO,EACL,kBAAkB,EAClB,0BAA0B,GAC3B,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACL,oBAAoB,EACpB,sBAAsB,GACvB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AASjE,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAcxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAEvD,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAOzC,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EACL,iBAAiB,EACjB,WAAW,EACX,eAAe,EACf,SAAS,GACV,MAAM,gBAAgB,CAAC;AAYxB,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAMrD,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAYxC,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAEjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import type { RelationshipWrite } from "./authorization.js";
|
|
2
|
+
import type { OwnerLockLease } from "./owner-lock.js";
|
|
3
|
+
export declare const OUTBOX_OPERATION_VALUES: readonly ["WRITE", "DELETE"];
|
|
4
|
+
export type OutboxOperation = (typeof OUTBOX_OPERATION_VALUES)[number];
|
|
5
|
+
/**
|
|
6
|
+
* One authorization fact awaiting projection.
|
|
7
|
+
*
|
|
8
|
+
* `idempotencyKey` is what makes at-least-once delivery safe: the same fact
|
|
9
|
+
* enqueued twice is one row, so a retried transaction cannot double-project.
|
|
10
|
+
* Callers derive it from the change they are recording (see
|
|
11
|
+
* `outboxKeyForRelationship`), never from a random value — a random key would
|
|
12
|
+
* make every retry a new fact.
|
|
13
|
+
*
|
|
14
|
+
* `ownerPartitionId` is the UUID of the exact authority slice this fact
|
|
15
|
+
* belongs to. The application chooses the partition key. The projector and lifecycle revocations
|
|
16
|
+
* coordinate on it so an older opposite fact cannot be applied after its
|
|
17
|
+
* replacement.
|
|
18
|
+
*/
|
|
19
|
+
export type AccessChange = {
|
|
20
|
+
readonly idempotencyKey: string;
|
|
21
|
+
readonly operation: OutboxOperation;
|
|
22
|
+
readonly relationship: RelationshipWrite;
|
|
23
|
+
readonly ownerPartitionId: string | null;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Implemented by PostgresEnqueueAccessChanges; FakeEnqueueAccessChanges in unit
|
|
27
|
+
* tests.
|
|
28
|
+
*/
|
|
29
|
+
export declare abstract class EnqueueAccessChanges<Tx> {
|
|
30
|
+
/**
|
|
31
|
+
* Append entries inside the caller's transaction. Re-enqueuing an entry
|
|
32
|
+
* whose `idempotencyKey` is already present is a no-op, not a conflict:
|
|
33
|
+
* recording the same fact twice must never fail the state change that
|
|
34
|
+
* caused it.
|
|
35
|
+
*/
|
|
36
|
+
abstract enqueue(entries: readonly AccessChange[], tx: Tx): Promise<void>;
|
|
37
|
+
/**
|
|
38
|
+
* Task-specific replacement ordering for a caller that proves one active
|
|
39
|
+
* provenance source per exact relationship. This terminally supersedes an
|
|
40
|
+
* older exact PENDING/FAILED fact with the opposite operation, records when
|
|
41
|
+
* and which idempotency key superseded it, and enqueues the replacement in
|
|
42
|
+
* the same transaction. SUPERSEDED is terminal but non-error, so lastError
|
|
43
|
+
* stays null. Every entry must name a non-null owner partition; other domains
|
|
44
|
+
* and ordinary facts must use enqueue.
|
|
45
|
+
*/
|
|
46
|
+
abstract enqueueReplacingOpposite(entries: readonly AccessChange[], tx: Tx, lease: OwnerLockLease): Promise<void>;
|
|
47
|
+
/**
|
|
48
|
+
* Append entries that have NO row of their own, supplying the handle
|
|
49
|
+
* internally so a caller still never holds one.
|
|
50
|
+
*
|
|
51
|
+
* This is not a convenience alternative to `enqueue` and must not be used
|
|
52
|
+
* where a state change exists: the whole value of `enqueue` is that the row
|
|
53
|
+
* and its fact cannot disagree, and reaching for `append` beside an insert
|
|
54
|
+
* throws that away silently. It exists for revocations that cannot enqueue
|
|
55
|
+
* through an owning row transaction; `revokeAccess` supplies the internal
|
|
56
|
+
* handle and still applies the relationship removal synchronously.
|
|
57
|
+
*/
|
|
58
|
+
abstract append(entries: readonly AccessChange[]): Promise<void>;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* The WRITE facts a creating mutation hands to its writer.
|
|
62
|
+
*
|
|
63
|
+
* The caller states its ownership tuples as data, and the writer commits them in
|
|
64
|
+
* the same transaction as the insert — replacing the older sequential
|
|
65
|
+
* `writeRelationships` call, which could be interrupted between the row and
|
|
66
|
+
* the fact and leave a resource nobody could reach.
|
|
67
|
+
*
|
|
68
|
+
* `cause` is the id of the row being created, which is why creates mint their
|
|
69
|
+
* id in the mutation: the fact has to name the resource before the insert
|
|
70
|
+
* happens.
|
|
71
|
+
*/
|
|
72
|
+
export declare function accessChangesToWrite(relationships: readonly RelationshipWrite[], cause: string, ownerPartitionId: string | null): AccessChange[];
|
|
73
|
+
/**
|
|
74
|
+
* The canonical idempotency key for a relationship change: stable across
|
|
75
|
+
* retries of the same logical change, distinct for every different one.
|
|
76
|
+
*
|
|
77
|
+
* `cause` is what makes it stable rather than merely unique — normally the id
|
|
78
|
+
* of the state change being recorded (the created row, the ended session). Two
|
|
79
|
+
* different causes writing the same tuple are two facts and must both be
|
|
80
|
+
* enqueued; one cause retried is one fact.
|
|
81
|
+
*
|
|
82
|
+
* **The exception is a revocation whose row is reused or absent.** A
|
|
83
|
+
* membership row moves add → remove → add → remove, while a
|
|
84
|
+
* relationship-only revocation has no spent row at all. A derived key would
|
|
85
|
+
* make a later removal collide with the first and never be projected — which
|
|
86
|
+
* is lingering access. Those sites mint a fresh cause on purpose. For a DELETE
|
|
87
|
+
* the failure directions are not symmetric: a duplicate is a no-op in SpiceDB,
|
|
88
|
+
* a suppressed one is a security hole. See
|
|
89
|
+
* `docs/architecture/authorization.md#choosing-a-facts-cause`.
|
|
90
|
+
*/
|
|
91
|
+
export declare function outboxKeyForRelationship(operation: OutboxOperation, relationship: RelationshipWrite, cause: string): string;
|
|
92
|
+
//# sourceMappingURL=access-changes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"access-changes.d.ts","sourceRo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;;;;;;;;;;GAiBG;AACH,wBAAgB,wBAAwB,CACtC,SAAS,EAAE,eAAe,EAC1B,YAAY,EAAE,iBAAiB,EAC/B,KAAK,EAAE,MAAM,GACZ,MAAM,CAUR"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
export const OUTBOX_OPERATION_VALUES = ["WRITE", "DELETE"];
|
|
2
|
+
/**
|
|
3
|
+
* Implemented by PostgresEnqueueAccessChanges; FakeEnqueueAccessChanges in unit
|
|
4
|
+
* tests.
|
|
5
|
+
*/
|
|
6
|
+
export class EnqueueAccessChanges {
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* The WRITE facts a creating mutation hands to its writer.
|
|
10
|
+
*
|
|
11
|
+
* The caller states its ownership tuples as data, and the writer commits them in
|
|
12
|
+
* the same transaction as the insert — replacing the older sequential
|
|
13
|
+
* `writeRelationships` call, which could be interrupted between the row and
|
|
14
|
+
* the fact and leave a resource nobody could reach.
|
|
15
|
+
*
|
|
16
|
+
* `cause` is the id of the row being created, which is why creates mint their
|
|
17
|
+
* id in the mutation: the fact has to name the resource before the insert
|
|
18
|
+
* happens.
|
|
19
|
+
*/
|
|
20
|
+
export function accessChangesToWrite(relationships, cause, ownerPartitionId) {
|
|
21
|
+
return relationships.map((relationship) => ({
|
|
22
|
+
idempotencyKey: outboxKeyForRelationship("WRITE", relationship, cause),
|
|
23
|
+
operation: "WRITE",
|
|
24
|
+
relationship,
|
|
25
|
+
ownerPartitionId,
|
|
26
|
+
}));
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* The canonical idempotency key for a relationship change: stable across
|
|
30
|
+
* retries of the same logical change, distinct for every different one.
|
|
31
|
+
*
|
|
32
|
+
* `cause` is what makes it stable rather than merely unique — normally the id
|
|
33
|
+
* of the state change being recorded (the created row, the ended session). Two
|
|
34
|
+
* different causes writing the same tuple are two facts and must both be
|
|
35
|
+
* enqueued; one cause retried is one fact.
|
|
36
|
+
*
|
|
37
|
+
* **The exception is a revocation whose row is reused or absent.** A
|
|
38
|
+
* membership row moves add → remove → add → remove, while a
|
|
39
|
+
* relationship-only revocation has no spent row at all. A derived key would
|
|
40
|
+
* make a later removal collide with the first and never be projected — which
|
|
41
|
+
* is lingering access. Those sites mint a fresh cause on purpose. For a DELETE
|
|
42
|
+
* the failure directions are not symmetric: a duplicate is a no-op in SpiceDB,
|
|
43
|
+
* a suppressed one is a security hole. See
|
|
44
|
+
* `docs/architecture/authorization.md#choosing-a-facts-cause`.
|
|
45
|
+
*/
|
|
46
|
+
export function outboxKeyForRelationship(operation, relationship, cause) {
|
|
47
|
+
const { resource, relation, subject } = relationship;
|
|
48
|
+
const subjectRelation = subject.relation ? `#${subject.relation}` : "";
|
|
49
|
+
return [
|
|
50
|
+
operation,
|
|
51
|
+
`${resource.type}:${resource.id}`,
|
|
52
|
+
relation,
|
|
53
|
+
`${subject.type}:${subject.id}${subjectRelation}`,
|
|
54
|
+
cause,
|
|
55
|
+
].join("|");
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=access-changes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"access-changes.js","sourceRoot":"","sources":["../../src/runtime/access-changes.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,OAAO,EAAE,QAAQ,CAAU,CAAC;AAyBpE;;;GAGG;AACH,MAAM,OAAgB,oBAAoB;CAoCzC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,oBAAoB,CAClC,aAA2C,EAC3C,KAAa,EACb,gBAA+B;IAE/B,OAAO,aAAa,CAAC,GAAG,CAAC,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC;QAC1C,cAAc,EAAE,wBAAwB,CAAC,OAAO,EAAE,YAAY,EAAE,KAAK,CAAC;QACtE,SAAS,EAAE,OAAO;QAClB,YAAY;QACZ,gBAAgB;KACjB,CAAC,CAAC,CAAC;AACN,CAAC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,wBAAwB,CACtC,SAA0B,EAC1B,YAA+B,EAC/B,KAAa;IAEb,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,YAAY,CAAC;IACrD,MAAM,eAAe,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IACvE,OAAO;QACL,SAAS;QACT,GAAG,QAAQ,CAAC,IAAI,IAAI,QAAQ,CAAC,EAAE,EAAE;QACjC,QAAQ;QACR,GAAG,OAAO,CAAC,IAAI,IAAI,OAAO,CAAC,EAAE,GAAG,eAAe,EAAE;QACjD,KAAK;KACN,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The authorization port, answering each identical read once per scope.
|
|
3
|
+
*
|
|
4
|
+
* A route that checks access at the edge and again in its handler, or a
|
|
5
|
+
* projection that asks the same question for every company it lists, like
|
|
6
|
+
* the launcher a platform administrator sees, otherwise pays one SpiceDB
|
|
7
|
+
* round trip per repeat. Inside `answeringEachQuestionOnce` — the HTTP kit
|
|
8
|
+
* opens one per request — a repeated `check`, batch item or
|
|
9
|
+
* `lookupResources` shares the first answer. The scope lives for one
|
|
10
|
+
* request, and any write through this port forgets every answer, so the
|
|
11
|
+
* request still sees its own grants and revocations. Outside a scope every
|
|
12
|
+
* call forwards.
|
|
13
|
+
*
|
|
14
|
+
* Inside a scope, single `check` calls that miss in the same tick — a
|
|
15
|
+
* `Promise.all` of checks, say — also travel together: they are gathered,
|
|
16
|
+
* grouped by `consistency` and `consistencyToken`, and sent as one
|
|
17
|
+
* `checkEach` per group (at most 128 questions each), so the tally counts
|
|
18
|
+
* one round trip per group. A tick with one miss in a group sends a plain
|
|
19
|
+
* `check`, as before. Each caller gets its own answer, and fails exactly as
|
|
20
|
+
* a lone `check` would: a group whose call fails rejects only its own
|
|
21
|
+
* callers, and a question SpiceDB answers with an item error rejects only
|
|
22
|
+
* that question's caller. Without `checkEach` behind it, checks go one by one.
|
|
23
|
+
*/
|
|
24
|
+
import { Authorization, type DirectSubjectLookup, type PermissionQuery, type RelationshipFilter, type RelationshipWrite, type ResourceLookup, type SpiceDbConsistencyToken, type SubjectRef } from "./authorization.js";
|
|
25
|
+
export declare class AnswerOnceAuthorization extends Authorization {
|
|
26
|
+
#private;
|
|
27
|
+
constructor(inner: Authorization);
|
|
28
|
+
check(query: PermissionQuery): Promise<boolean>;
|
|
29
|
+
checkMany(queries: readonly PermissionQuery[]): Promise<readonly boolean[]>;
|
|
30
|
+
lookupResources(query: ResourceLookup): Promise<readonly string[]>;
|
|
31
|
+
writeRelationships(writes: readonly RelationshipWrite[]): Promise<SpiceDbConsistencyToken>;
|
|
32
|
+
deleteRelationships(filter: RelationshipFilter): Promise<SpiceDbConsistencyToken>;
|
|
33
|
+
relationshipExists(filter: {
|
|
34
|
+
resourceType: string;
|
|
35
|
+
resourceId: string;
|
|
36
|
+
relation: string;
|
|
37
|
+
}): Promise<boolean>;
|
|
38
|
+
listDirectSubjects(query: DirectSubjectLookup): Promise<readonly SubjectRef[]>;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=answer-once-authorization.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"answer-once-authorization.d.ts","sourceRoot":"","sources":["../../src/runtime/answer-once-authorization.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAOH,OAAO,EACL,aAAa,EAEb,KAAK,mBAAmB,EAExB,KAAK,eAAe,EACpB,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,KAAK,cAAc,EACnB,KAAK,uBAAuB,EAC5B,KAAK,UAAU,EAChB,MAAM,oBAAoB,CAAC;AAc5B,qBAAa,uBAAwB,SAAQ,aAAa;;IAOxD,YAAY,KAAK,EAAE,aAAa,EAG/B;IAEQ,KAAK,CAAC,KAAK,EAAE,eAAe,GAAG,OAAO,CAAC,OAAO,CAAC,CAMvD;IAsDc,SAAS,CACtB,OAAO,EAAE,SAAS,eAAe,EAAE,GAClC,OAAO,CAAC,SAAS,OAAO,EAAE,CAAC,CAc7B;IA8BQ,eAAe,CAAC,KAAK,EAAE,cAAc,GAAG,OAAO,CAAC,SAAS,MAAM,EAAE,CAAC,CAI1E;IAEQ,kBAAkB,CACzB,MAAM,EAAE,SAAS,iBAAiB,EAAE,GACnC,OAAO,CAAC,uBAAuB,CAAC,CAElC;IAEQ,mBAAmB,CAC1B,MAAM,EAAE,kBAAkB,GACzB,OAAO,CAAC,uBAAuB,CAAC,CAIlC;IAEQ,kBAAkB,CAAC,MAAM,EAAE;QAClC,YAAY,EAAE,MAAM,CAAC;QACrB,UAAU,EAAE,MAAM,CAAC;QACnB,QAAQ,EAAE,MAAM,CAAC;KAClB,GAAG,OAAO,CAAC,OAAO,CAAC,CAEnB;IAEQ,kBAAkB,CACzB,KAAK,EAAE,mBAAmB,GACzB,OAAO,CAAC,SAAS,UAAU,EAAE,CAAC,CAEhC;CAmBF"}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The authorization port, answering each identical read once per scope.
|
|
3
|
+
*
|
|
4
|
+
* A route that checks access at the edge and again in its handler, or a
|
|
5
|
+
* projection that asks the same question for every company it lists, like
|
|
6
|
+
* the launcher a platform administrator sees, otherwise pays one SpiceDB
|
|
7
|
+
* round trip per repeat. Inside `answeringEachQuestionOnce` — the HTTP kit
|
|
8
|
+
* opens one per request — a repeated `check`, batch item or
|
|
9
|
+
* `lookupResources` shares the first answer. The scope lives for one
|
|
10
|
+
* request, and any write through this port forgets every answer, so the
|
|
11
|
+
* request still sees its own grants and revocations. Outside a scope every
|
|
12
|
+
* call forwards.
|
|
13
|
+
*
|
|
14
|
+
* Inside a scope, single `check` calls that miss in the same tick — a
|
|
15
|
+
* `Promise.all` of checks, say — also travel together: they are gathered,
|
|
16
|
+
* grouped by `consistency` and `consistencyToken`, and sent as one
|
|
17
|
+
* `checkEach` per group (at most 128 questions each), so the tally counts
|
|
18
|
+
* one round trip per group. A tick with one miss in a group sends a plain
|
|
19
|
+
* `check`, as before. Each caller gets its own answer, and fails exactly as
|
|
20
|
+
* a lone `check` would: a group whose call fails rejects only its own
|
|
21
|
+
* callers, and a question SpiceDB answers with an item error rejects only
|
|
22
|
+
* that question's caller. Without `checkEach` behind it, checks go one by one.
|
|
23
|
+
*/
|
|
24
|
+
import { AnswersOncePerScope, OneValuePerScope, } from "@dads-framework/request-work";
|
|
25
|
+
import { Authorization, checkOutcome, } from "./authorization.js";
|
|
26
|
+
import { lookupQuestionIdentity, permissionQuestionIdentity, } from "./question-identity.js";
|
|
27
|
+
const PERMISSION_BATCH_SIZE = 128;
|
|
28
|
+
export class AnswerOnceAuthorization extends Authorization {
|
|
29
|
+
#inner;
|
|
30
|
+
#checks = new AnswersOncePerScope();
|
|
31
|
+
#lookups = new AnswersOncePerScope();
|
|
32
|
+
/** This tick's gathered checks in the current scope, by consistency group. */
|
|
33
|
+
#gathering = new OneValuePerScope();
|
|
34
|
+
constructor(inner) {
|
|
35
|
+
super();
|
|
36
|
+
this.#inner = inner;
|
|
37
|
+
}
|
|
38
|
+
check(query) {
|
|
39
|
+
return this.#checks.answer(checkKey(query), () => this.#gathering.inScope() && this.#inner.checkEach !== undefined
|
|
40
|
+
? this.#gatherCheck(query)
|
|
41
|
+
: this.#inner.check(query));
|
|
42
|
+
}
|
|
43
|
+
/** Joins this tick's group for the query's consistency; its index is its answer. */
|
|
44
|
+
#gatherCheck(query) {
|
|
45
|
+
const groupKey = consistencyKey(query);
|
|
46
|
+
const groups = this.#gathering.get() ?? this.#startGathering();
|
|
47
|
+
const group = groups.get(groupKey) ?? this.#openGroup(groups, groupKey);
|
|
48
|
+
const index = group.queries.length;
|
|
49
|
+
group.queries.push(query);
|
|
50
|
+
if (group.queries.length === PERMISSION_BATCH_SIZE)
|
|
51
|
+
groups.delete(groupKey);
|
|
52
|
+
return group.outcomes.then((outcomes) => {
|
|
53
|
+
const outcome = outcomes[index];
|
|
54
|
+
if (outcome === undefined) {
|
|
55
|
+
throw new Error("a gathered permission check came back unanswered");
|
|
56
|
+
}
|
|
57
|
+
// An item error rejects its caller, exactly as a lone check throws.
|
|
58
|
+
if (outcome.kind === "failed")
|
|
59
|
+
throw outcome.error;
|
|
60
|
+
return outcome.allowed;
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
#startGathering() {
|
|
64
|
+
const groups = new Map();
|
|
65
|
+
this.#gathering.set(groups);
|
|
66
|
+
return groups;
|
|
67
|
+
}
|
|
68
|
+
/** A group sends once the tick that opened it has finished gathering. */
|
|
69
|
+
#openGroup(groups, groupKey) {
|
|
70
|
+
const queries = [];
|
|
71
|
+
const outcomes = Promise.resolve().then(() => {
|
|
72
|
+
if (groups.get(groupKey) === group)
|
|
73
|
+
groups.delete(groupKey);
|
|
74
|
+
return this.#sendGathered(queries);
|
|
75
|
+
});
|
|
76
|
+
const group = { queries, outcomes };
|
|
77
|
+
groups.set(groupKey, group);
|
|
78
|
+
return group;
|
|
79
|
+
}
|
|
80
|
+
#sendGathered(queries) {
|
|
81
|
+
const checkEach = this.#inner.checkEach?.bind(this.#inner);
|
|
82
|
+
if (checkEach === undefined || queries.length === 1) {
|
|
83
|
+
return Promise.all(queries.map((query) => checkOutcome(() => this.#inner.check(query))));
|
|
84
|
+
}
|
|
85
|
+
return checkEach(queries);
|
|
86
|
+
}
|
|
87
|
+
async checkMany(queries) {
|
|
88
|
+
const decisions = [];
|
|
89
|
+
for (let offset = 0; offset < queries.length; offset += PERMISSION_BATCH_SIZE) {
|
|
90
|
+
decisions.push(...(await this.#checkBatch(queries.slice(offset, offset + PERMISSION_BATCH_SIZE))));
|
|
91
|
+
}
|
|
92
|
+
return decisions;
|
|
93
|
+
}
|
|
94
|
+
#checkBatch(queries) {
|
|
95
|
+
const uncached = [];
|
|
96
|
+
// Cache misses register synchronously before the batch starts in this microtask.
|
|
97
|
+
const batch = Promise.resolve().then(async () => {
|
|
98
|
+
if (uncached.length === 0)
|
|
99
|
+
return [];
|
|
100
|
+
if (this.#inner.checkMany !== undefined) {
|
|
101
|
+
return this.#inner.checkMany(uncached);
|
|
102
|
+
}
|
|
103
|
+
const decisions = [];
|
|
104
|
+
for (const query of uncached)
|
|
105
|
+
decisions.push(await this.#inner.check(query));
|
|
106
|
+
return decisions;
|
|
107
|
+
});
|
|
108
|
+
const answers = [];
|
|
109
|
+
for (const query of queries) {
|
|
110
|
+
answers.push(this.#checks.answer(checkKey(query), () => {
|
|
111
|
+
const index = uncached.length;
|
|
112
|
+
uncached.push(query);
|
|
113
|
+
return batch.then((decisions) => decisions[index] === true);
|
|
114
|
+
}));
|
|
115
|
+
}
|
|
116
|
+
return Promise.all(answers);
|
|
117
|
+
}
|
|
118
|
+
lookupResources(query) {
|
|
119
|
+
return this.#lookups.answer(lookupKey(query), () => this.#inner.lookupResources(query));
|
|
120
|
+
}
|
|
121
|
+
writeRelationships(writes) {
|
|
122
|
+
return this.#forgettingAround(() => this.#inner.writeRelationships(writes));
|
|
123
|
+
}
|
|
124
|
+
deleteRelationships(filter) {
|
|
125
|
+
return this.#forgettingAround(() => this.#inner.deleteRelationships(filter));
|
|
126
|
+
}
|
|
127
|
+
relationshipExists(filter) {
|
|
128
|
+
return this.#inner.relationshipExists(filter);
|
|
129
|
+
}
|
|
130
|
+
listDirectSubjects(query) {
|
|
131
|
+
return this.#inner.listDirectSubjects(query);
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Forgets before the write and again once it settles, so a read that ran
|
|
135
|
+
* while the write was in flight cannot leave a pre-write answer behind.
|
|
136
|
+
*/
|
|
137
|
+
async #forgettingAround(write) {
|
|
138
|
+
this.#forgetAnswers();
|
|
139
|
+
try {
|
|
140
|
+
return await write();
|
|
141
|
+
}
|
|
142
|
+
finally {
|
|
143
|
+
this.#forgetAnswers();
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
#forgetAnswers() {
|
|
147
|
+
this.#checks.forget();
|
|
148
|
+
this.#lookups.forget();
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
function checkKey(query) {
|
|
152
|
+
return JSON.stringify([
|
|
153
|
+
...permissionQuestionIdentity(query),
|
|
154
|
+
query.consistencyToken ?? null,
|
|
155
|
+
// A fully-consistent ask never takes an earlier, possibly cached, answer.
|
|
156
|
+
query.consistency ?? null,
|
|
157
|
+
]);
|
|
158
|
+
}
|
|
159
|
+
/** Questions that may share one bulk call: the same consistency asked. */
|
|
160
|
+
function consistencyKey(query) {
|
|
161
|
+
return JSON.stringify([
|
|
162
|
+
query.consistencyToken ?? null,
|
|
163
|
+
query.consistency ?? null,
|
|
164
|
+
]);
|
|
165
|
+
}
|
|
166
|
+
function lookupKey(query) {
|
|
167
|
+
return JSON.stringify([
|
|
168
|
+
...lookupQuestionIdentity(query),
|
|
169
|
+
query.consistencyToken ?? null,
|
|
170
|
+
]);
|
|
171
|
+
}
|
|
172
|
+
//# sourceMappingURL=answer-once-authorization.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"answer-once-authorization.js","sourceRoot":"","sources":["../../src/runtime/answer-once-authorization.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EACL,mBAAmB,EACnB,gBAAgB,GACjB,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EACL,aAAa,EACb,YAAY,GASb,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,sBAAsB,EACtB,0BAA0B,GAC3B,MAAM,wBAAwB,CAAC;AAEhC,MAAM,qBAAqB,GAAG,GAAG,CAAC;AAQlC,MAAM,OAAO,uBAAwB,SAAQ,aAAa;IAC/C,MAAM,CAAgB;IACtB,OAAO,GAAG,IAAI,mBAAmB,EAAW,CAAC;IAC7C,QAAQ,GAAG,IAAI,mBAAmB,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AC,cAAc,EAAE,CAAC;QACtB,IAAI,CAAC;YACH,OAAO,MAAM,KAAK,EAAE,CAAC;QACvB,CAAC;gBAAS,CAAC;YACT,IAAI,CAAC,cAAc,EAAE,CAAC;QACxB,CAAC;IACH,CAAC;IAED,cAAc;QACZ,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;QACtB,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC;IACzB,CAAC;CACF;AAED,SAAS,QAAQ,CAAC,KAAsB;IACtC,OAAO,IAAI,CAAC,SAAS,CAAC;QACpB,GAAG,0BAA0B,CAAC,KAAK,CAAC;QACpC,KAAK,CAAC,gBAAgB,IAAI,IAAI;QAC9B,0EAA0E;QAC1E,KAAK,CAAC,WAAW,IAAI,IAAI;KAC1B,CAAC,CAAC;AACL,CAAC;AAED,0EAA0E;AAC1E,SAAS,cAAc,CAAC,KAAsB;IAC5C,OAAO,IAAI,CAAC,SAAS,CAAC;QACpB,KAAK,CAAC,gBAAgB,IAAI,IAAI;QAC9B,KAAK,CAAC,WAAW,IAAI,IAAI;KAC1B,CAAC,CAAC;AACL,CAAC;AAED,SAAS,SAAS,CAAC,KAAqB;IACtC,OAAO,IAAI,CAAC,SAAS,CAAC;QACpB,GAAG,sBAAsB,CAAC,KAAK,CAAC;QAChC,KAAK,CAAC,gBAAgB,IAAI,IAAI;KAC/B,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { AccessChange } from "./access-changes.js";
|
|
2
|
+
/**
|
|
3
|
+
* Project the facts a state change just enqueued, right after its transaction
|
|
4
|
+
* commits.
|
|
5
|
+
*
|
|
6
|
+
* ## Why this exists at all
|
|
7
|
+
*
|
|
8
|
+
* A create writes its row and its authorization facts in ONE transaction,
|
|
9
|
+
* which is the guarantee the outbox was built for. But a fact that is only
|
|
10
|
+
* durable is not yet enforcement: until it reaches SpiceDB, nobody can reach
|
|
11
|
+
* the resource — not the creator, not a platform admin, because
|
|
12
|
+
* `parent_platform` is itself one of the enqueued tuples. The projector's job
|
|
13
|
+
* definition has no recurring schedule yet, so "eventually" would mean "when
|
|
14
|
+
* a human runs a dangerous operation". The request therefore projects its own
|
|
15
|
+
* facts before it answers.
|
|
16
|
+
*
|
|
17
|
+
* ## What this is NOT
|
|
18
|
+
*
|
|
19
|
+
* It is not a second way to write tuples, and it is not a queue drain. It
|
|
20
|
+
* holds no `Authorization` and no store: it delegates to the real projector,
|
|
21
|
+
* which is the only thing that claims and settles. A producer therefore still
|
|
22
|
+
* cannot mark a fact projected, which is the separation
|
|
23
|
+
* `ClaimAccessChanges` was split out to protect.
|
|
24
|
+
*
|
|
25
|
+
* ## Failure is not the caller's problem
|
|
26
|
+
*
|
|
27
|
+
* `dispatch` never throws. By the time it runs, the row and its facts are
|
|
28
|
+
* committed and the operation has already succeeded; the graph being
|
|
29
|
+
* unreachable makes the grant late, not wrong. The outbox row stays PENDING
|
|
30
|
+
* and the projector heals it on replay — which is exactly the property the
|
|
31
|
+
* wave's demo milestone proves by killing this step and running the projector
|
|
32
|
+
* by hand.
|
|
33
|
+
*
|
|
34
|
+
* Faked in testing/.
|
|
35
|
+
*/
|
|
36
|
+
export declare abstract class ApplyAccessChangesAfterCommit {
|
|
37
|
+
abstract dispatch(entries: readonly AccessChange[]): Promise<void>;
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=apply-access-changes-after-commit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apply-access-changes-after-commit.d.ts","sourceRoot":"","sources":["../../src/runtime/apply-access-changes-after-commit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAExD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,8BAAsB,6BAA6B;IACjD,QAAQ,CAAC,QAAQ,CAAC,OAAO,EAAE,SAAS,YAAY,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACpE"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Project the facts a state change just enqueued, right after its transaction
|
|
3
|
+
* commits.
|
|
4
|
+
*
|
|
5
|
+
* ## Why this exists at all
|
|
6
|
+
*
|
|
7
|
+
* A create writes its row and its authorization facts in ONE transaction,
|
|
8
|
+
* which is the guarantee the outbox was built for. But a fact that is only
|
|
9
|
+
* durable is not yet enforcement: until it reaches SpiceDB, nobody can reach
|
|
10
|
+
* the resource — not the creator, not a platform admin, because
|
|
11
|
+
* `parent_platform` is itself one of the enqueued tuples. The projector's job
|
|
12
|
+
* definition has no recurring schedule yet, so "eventually" would mean "when
|
|
13
|
+
* a human runs a dangerous operation". The request therefore projects its own
|
|
14
|
+
* facts before it answers.
|
|
15
|
+
*
|
|
16
|
+
* ## What this is NOT
|
|
17
|
+
*
|
|
18
|
+
* It is not a second way to write tuples, and it is not a queue drain. It
|
|
19
|
+
* holds no `Authorization` and no store: it delegates to the real projector,
|
|
20
|
+
* which is the only thing that claims and settles. A producer therefore still
|
|
21
|
+
* cannot mark a fact projected, which is the separation
|
|
22
|
+
* `ClaimAccessChanges` was split out to protect.
|
|
23
|
+
*
|
|
24
|
+
* ## Failure is not the caller's problem
|
|
25
|
+
*
|
|
26
|
+
* `dispatch` never throws. By the time it runs, the row and its facts are
|
|
27
|
+
* committed and the operation has already succeeded; the graph being
|
|
28
|
+
* unreachable makes the grant late, not wrong. The outbox row stays PENDING
|
|
29
|
+
* and the projector heals it on replay — which is exactly the property the
|
|
30
|
+
* wave's demo milestone proves by killing this step and running the projector
|
|
31
|
+
* by hand.
|
|
32
|
+
*
|
|
33
|
+
* Faked in testing/.
|
|
34
|
+
*/
|
|
35
|
+
export class ApplyAccessChangesAfterCommit {
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=apply-access-changes-after-commit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apply-access-changes-after-commit.js","sourceRoot":"","sources":["../../src/runtime/apply-access-changes-after-commit.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,MAAM,OAAgB,6BAA6B;CAElD"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const AUTHORIZATION_CONSISTENCY_COOKIE = "dads_authz_consistency";
|
|
2
|
+
export declare function authorizationConsistencyTokenFromCookieHeader(cookieHeader: string | readonly string[] | undefined): string | undefined;
|
|
3
|
+
export declare function authorizationConsistencySetCookie(token: string, options?: {
|
|
4
|
+
readonly secure?: boolean;
|
|
5
|
+
}): string;
|
|
6
|
+
export declare function authorizationConsistencyClearCookie(options?: {
|
|
7
|
+
readonly secure?: boolean;
|
|
8
|
+
}): string;
|
|
9
|
+
//# sourceMappingURL=authorization-consistency-cookie.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authorization-consistency-cookie.d.ts","sourceRoot":"","sources":["../../src/runtime/authorization-consistency-cookie.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gCAAgC,2BAA2B,CAAC;AAEzE,wBAAgB,6CAA6C,CAC3D,YAAY,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,GAAG,SAAS,GACnD,MAAM,GAAG,SAAS,CAapB;AAED,wBAAgB,iCAAiC,CAC/C,KAAK,EAAE,MAAM,EACb,OAAO,GAAE;IAAE,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAA;CAAO,GAC1C,MAAM,CAER;AAED,wBAAgB,mCAAmC,CACjD,OAAO,GAAE;IAAE,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAA;CAAO,GAC1C,MAAM,CAER"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export const AUTHORIZATION_CONSISTENCY_COOKIE = "dads_authz_consistency";
|
|
2
|
+
export function authorizationConsistencyTokenFromCookieHeader(cookieHeader) {
|
|
3
|
+
const header = headerText(cookieHeader);
|
|
4
|
+
if (header === "")
|
|
5
|
+
return undefined;
|
|
6
|
+
for (const part of header.split(";")) {
|
|
7
|
+
const separator = part.indexOf("=");
|
|
8
|
+
if (separator < 0)
|
|
9
|
+
continue;
|
|
10
|
+
const name = part.slice(0, separator).trim();
|
|
11
|
+
if (name !== AUTHORIZATION_CONSISTENCY_COOKIE)
|
|
12
|
+
continue;
|
|
13
|
+
const value = part.slice(separator + 1).trim();
|
|
14
|
+
if (value === "")
|
|
15
|
+
return undefined;
|
|
16
|
+
return decodeURIComponent(value);
|
|
17
|
+
}
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
export function authorizationConsistencySetCookie(token, options = {}) {
|
|
21
|
+
return authorizationConsistencyCookie(encodeURIComponent(token), options);
|
|
22
|
+
}
|
|
23
|
+
export function authorizationConsistencyClearCookie(options = {}) {
|
|
24
|
+
return authorizationConsistencyCookie("", options, ["Max-Age=0"]);
|
|
25
|
+
}
|
|
26
|
+
function authorizationConsistencyCookie(value, options, extra = []) {
|
|
27
|
+
const parts = [
|
|
28
|
+
`${AUTHORIZATION_CONSISTENCY_COOKIE}=${value}`,
|
|
29
|
+
"Path=/api",
|
|
30
|
+
"HttpOnly",
|
|
31
|
+
"SameSite=Lax",
|
|
32
|
+
...extra,
|
|
33
|
+
];
|
|
34
|
+
if (options.secure === true) {
|
|
35
|
+
parts.push("Secure");
|
|
36
|
+
}
|
|
37
|
+
return parts.join("; ");
|
|
38
|
+
}
|
|
39
|
+
function headerText(cookieHeader) {
|
|
40
|
+
if (typeof cookieHeader === "string")
|
|
41
|
+
return cookieHeader;
|
|
42
|
+
if (Array.isArray(cookieHeader))
|
|
43
|
+
return cookieHeader.join("; ");
|
|
44
|
+
return "";
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=authorization-consistency-cookie.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authorization-consistency-cookie.js","sourceRoot":"","sources":["../../src/runtime/authorization-consistency-cookie.ts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AAW;QACX,UAAU;QACV,cAAc;QACd,GAAG,KAAK;KACT,CAAC;IACF,IAAI,OAAO,CAAC,MAAM,KAAK,IAAI,EAAE,CAAC;QAC5B,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACvB,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC;AAED,SAAS,UAAU,CACjB,YAAoD;IAEpD,IAAI,OAAO,YAAY,KAAK,QAAQ;QAAE,OAAO,YAAY,CAAC;IAC1D,IAAI,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC;QAAE,OAAO,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAChE,OAAO,EAAE,CAAC;AACZ,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { SpiceDbConsistencyToken } from "./authorization.js";
|
|
2
|
+
export declare function runWithAuthorizationConsistency<T>(inboundToken: SpiceDbConsistencyToken | undefined, work: () => T): T;
|
|
3
|
+
export declare function authorizationConsistencyTokenOnThisRequest(): SpiceDbConsistencyToken | undefined;
|
|
4
|
+
export declare function recordWrittenAuthorizationConsistency(token: SpiceDbConsistencyToken): void;
|
|
5
|
+
export declare function writtenAuthorizationConsistencyOnThisRequest(): SpiceDbConsistencyToken | undefined;
|
|
6
|
+
//# sourceMappingURL=authorization-consistency.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authorization-consistency.d.ts","sourceRoot":"","sources":["../../src/runtime/authorization-consistency.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAWlE,wBAAgB,+BAA+B,CAAC,CAAC,EAC/C,YAAY,EAAE,uBAAuB,GAAG,SAAS,EACjD,IAAI,EAAE,MAAM,CAAC,GACZ,CAAC,CAKH;AAED,wBAAgB,0CAA0C,IACxD,uBAAuB,GAAG,SAAS,CAIpC;AAED,wBAAgB,qCAAqC,CACnD,KAAK,EAAE,uBAAuB,GAC7B,IAAI,CAKN;AAED,wBAAgB,4CAA4C,IAC1D,uBAAuB,GAAG,SAAS,CAIpC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
+
import { presentToken } from "./present-token.js";
|
|
3
|
+
const authorizationConsistencyOnThisRequest = new AsyncLocalStorage();
|
|
4
|
+
export function runWithAuthorizationConsistency(inboundToken, work) {
|
|
5
|
+
return authorizationConsistencyOnThisRequest.run({ inbound: presentToken(inboundToken), written: undefined }, work);
|
|
6
|
+
}
|
|
7
|
+
export function authorizationConsistencyTokenOnThisRequest() {
|
|
8
|
+
const store = authorizationConsistencyOnThisRequest.getStore();
|
|
9
|
+
if (store === undefined)
|
|
10
|
+
return undefined;
|
|
11
|
+
return presentToken(store.written) ?? presentToken(store.inbound);
|
|
12
|
+
}
|
|
13
|
+
export function recordWrittenAuthorizationConsistency(token) {
|
|
14
|
+
const store = authorizationConsistencyOnThisRequest.getStore();
|
|
15
|
+
const written = presentToken(token);
|
|
16
|
+
if (store === undefined || written === undefined)
|
|
17
|
+
return;
|
|
18
|
+
store.written = written;
|
|
19
|
+
}
|
|
20
|
+
export function writtenAuthorizationConsistencyOnThisRequest() {
|
|
21
|
+
return presentToken(authorizationConsistencyOnThisRequest.getStore()?.written);
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=authorization-consistency.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authorization-consistency.js","sourceRoot":"","sources":["../../src/runtime/authorization-consistency.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAErD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAOlD,MAAM,qCAAqC,GACzC,IAAI,iBAAiB,EAAyC,CAAC;AAEjE,MAAM,UAAU,+BAA+B,CAC7C,YAAiD,EACjD,IAAa;IAEb,OAAO,qCAAqC,CAAC,GAAG,CAC9C,EAAE,OAAO,EAAE,YAAY,CAAC,YAAY,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,EAC3D,IAAI,CACL,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,0CAA0C;IAExD,MAAM,KAAK,GAAG,qCAAqC,CAAC,QAAQ,EAAE,CAAC;IAC/D,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IAC1C,OAAO,YAAY,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,YAAY,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;AACpE,CAAC;AAED,MAAM,UAAU,qCAAqC,CACnD,KAA8B;IAE9B,MAAM,KAAK,GAAG,qCAAqC,CAAC,QAAQ,EAAE,CAAC;IAC/D,MAAM,OAAO,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC;IACpC,IAAI,KAAK,KAAK,SAAS,IAAI,OAAO,KAAK,SAAS;QAAE,OAAO;IACzD,KAAK,CAAC,OAAO,GAAG,OAAO,CAAC;AAC1B,CAAC;AAED,MAAM,UAAU,4CAA4C;IAE1D,OAAO,YAAY,CACjB,qCAAqC,CAAC,QAAQ,EAAE,EAAE,OAAO,CAC1D,CAAC;AACJ,CAAC"}
|