@party-stack/ontology-backend 0.0.0-stage → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +148 -2
  3. package/lib/actions.d.ts +47 -0
  4. package/lib/actions.d.ts.map +1 -0
  5. package/lib/actions.js +306 -0
  6. package/lib/actions.js.map +1 -0
  7. package/lib/clients.d.ts +236 -0
  8. package/lib/clients.d.ts.map +1 -0
  9. package/lib/clients.js +211 -0
  10. package/lib/clients.js.map +1 -0
  11. package/lib/delivery.d.ts +746 -0
  12. package/lib/delivery.d.ts.map +1 -0
  13. package/lib/delivery.js +863 -0
  14. package/lib/delivery.js.map +1 -0
  15. package/lib/description.d.ts +29 -0
  16. package/lib/description.d.ts.map +1 -0
  17. package/lib/description.js +28 -0
  18. package/lib/description.js.map +1 -0
  19. package/lib/encrypted.d.ts +41 -0
  20. package/lib/encrypted.d.ts.map +1 -0
  21. package/lib/encrypted.js +111 -0
  22. package/lib/encrypted.js.map +1 -0
  23. package/lib/errors.d.ts +106 -0
  24. package/lib/errors.d.ts.map +1 -0
  25. package/lib/errors.js +275 -0
  26. package/lib/errors.js.map +1 -0
  27. package/lib/fulfillment.d.ts +25 -0
  28. package/lib/fulfillment.d.ts.map +1 -0
  29. package/lib/fulfillment.js +99 -0
  30. package/lib/fulfillment.js.map +1 -0
  31. package/lib/index.d.ts +297 -0
  32. package/lib/index.d.ts.map +1 -0
  33. package/lib/index.js +91 -0
  34. package/lib/index.js.map +1 -0
  35. package/lib/maintenance.d.ts +11 -0
  36. package/lib/maintenance.d.ts.map +1 -0
  37. package/lib/maintenance.js +24 -0
  38. package/lib/maintenance.js.map +1 -0
  39. package/lib/meta.d.ts +26 -0
  40. package/lib/meta.d.ts.map +1 -0
  41. package/lib/meta.js +213 -0
  42. package/lib/meta.js.map +1 -0
  43. package/lib/owned.d.ts +74 -0
  44. package/lib/owned.d.ts.map +1 -0
  45. package/lib/owned.js +593 -0
  46. package/lib/owned.js.map +1 -0
  47. package/lib/policy/indexes.d.ts +12 -0
  48. package/lib/policy/indexes.d.ts.map +1 -0
  49. package/lib/policy/indexes.js +113 -0
  50. package/lib/policy/indexes.js.map +1 -0
  51. package/lib/policy/planner.d.ts +10 -0
  52. package/lib/policy/planner.d.ts.map +1 -0
  53. package/lib/policy/planner.js +118 -0
  54. package/lib/policy/planner.js.map +1 -0
  55. package/lib/policy/view.d.ts +31 -0
  56. package/lib/policy/view.d.ts.map +1 -0
  57. package/lib/policy/view.js +173 -0
  58. package/lib/policy/view.js.map +1 -0
  59. package/lib/policy.d.ts +47 -0
  60. package/lib/policy.d.ts.map +1 -0
  61. package/lib/policy.js +100 -0
  62. package/lib/policy.js.map +1 -0
  63. package/lib/protocol.d.ts +570 -0
  64. package/lib/protocol.d.ts.map +1 -0
  65. package/lib/protocol.js +144 -0
  66. package/lib/protocol.js.map +1 -0
  67. package/lib/query.d.ts +33 -0
  68. package/lib/query.d.ts.map +1 -0
  69. package/lib/query.js +51 -0
  70. package/lib/query.js.map +1 -0
  71. package/lib/references.d.ts +8 -0
  72. package/lib/references.d.ts.map +1 -0
  73. package/lib/references.js +41 -0
  74. package/lib/references.js.map +1 -0
  75. package/lib/storage.d.ts +55 -0
  76. package/lib/storage.d.ts.map +1 -0
  77. package/lib/storage.js +168 -0
  78. package/lib/storage.js.map +1 -0
  79. package/lib/subset.d.ts +19 -0
  80. package/lib/subset.d.ts.map +1 -0
  81. package/lib/subset.js +150 -0
  82. package/lib/subset.js.map +1 -0
  83. package/lib/subsetSchema.d.ts +10 -0
  84. package/lib/subsetSchema.d.ts.map +1 -0
  85. package/lib/subsetSchema.js +20 -0
  86. package/lib/subsetSchema.js.map +1 -0
  87. package/package.json +72 -3
@@ -0,0 +1,173 @@
1
+ import { BackendError } from "../errors.js";
2
+ import "../index.js";
3
+ import { queryExecutor } from "../query.js";
4
+ import { authorizationPlans } from "./planner.js";
5
+ import { resolveQuerySources, selectedProperty, validatePolicy, validateQueryDocument } from "@party-stack/ontology-spec/query";
6
+ import { eq, evaluateQuery, field } from "@party-stack/ontology-storage";
7
+ import { Effect } from "effect";
8
+ //#region src/policy/view.ts
9
+ const denied = (operation) => new BackendError({
10
+ operation,
11
+ kind: "Forbidden",
12
+ message: "This operation is not permitted.",
13
+ retryable: false,
14
+ actionOutcome: "not-committed"
15
+ });
16
+ const keyOf = (type, key) => JSON.stringify([type, key]);
17
+ function policyProperties(ir) {
18
+ const allowed = /* @__PURE__ */ new Map();
19
+ const guaranteed = /* @__PURE__ */ new Map();
20
+ function query(q, parent) {
21
+ if (q.from.source.ontology) return;
22
+ const object = ir.objectTypes.find((t) => t.name === q.from.source.objectType);
23
+ if (!object) return;
24
+ const upper = allowed.get(object.name) ?? /* @__PURE__ */ new Set();
25
+ allowed.set(object.name, upper);
26
+ const scope = new Map([...parent, [q.from.binding, upper]]);
27
+ const always = /* @__PURE__ */ new Set([object.primaryKey]);
28
+ upper.add(object.primaryKey);
29
+ function selections(items, conditional) {
30
+ for (const item of items) if (item.kind === "sub") query(item.value.query, scope);
31
+ else if (item.kind === "selectCase") {
32
+ for (const branch of item.value.branches) selections(branch.select, true);
33
+ selections(item.value.else ?? [], true);
34
+ } else {
35
+ const p = selectedProperty(item.value.expression);
36
+ if (p) {
37
+ scope.get(p.binding)?.add(p.property);
38
+ if (!conditional && p.binding === q.from.binding) always.add(p.property);
39
+ }
40
+ }
41
+ }
42
+ selections(q.select, false);
43
+ const existing = guaranteed.get(object.name);
44
+ guaranteed.set(object.name, existing ? new Set([...existing].filter((p) => always.has(p))) : always);
45
+ }
46
+ function roots(items) {
47
+ for (const item of items) if (item.kind === "sub") query(item.value.query, /* @__PURE__ */ new Map());
48
+ else if (item.kind === "selectCase") {
49
+ item.value.branches.forEach((b) => roots(b.select));
50
+ roots(item.value.else ?? []);
51
+ }
52
+ }
53
+ if (ir.policy) roots(resolveQuerySources(ir, ir.policy.objects).select);
54
+ return {
55
+ allowed,
56
+ guaranteed
57
+ };
58
+ }
59
+ function filterFields(query) {
60
+ const result = /* @__PURE__ */ new Set();
61
+ const visit = (value) => {
62
+ if (!value || typeof value !== "object") return;
63
+ if ("_tag" in value && value._tag === "Field" && "path" in value && Array.isArray(value.path)) {
64
+ result.add(value.path[0]);
65
+ return;
66
+ }
67
+ Object.values(value).forEach((v) => Array.isArray(v) ? v.forEach(visit) : visit(v));
68
+ };
69
+ visit(query.where);
70
+ query.orderBy?.forEach((o) => result.add(o.field.path[0]));
71
+ return result;
72
+ }
73
+ /** Bound to one authenticated context. Underlying reader is trusted and owns transaction lifetime. */
74
+ function evaluatePolicyView(reader, context, options, strategy = "rewrite") {
75
+ const ir = reader.ir;
76
+ const issues = validatePolicy(ir);
77
+ if (issues.length) throw new BackendError({
78
+ operation: "policy",
79
+ kind: "InvalidConfiguration",
80
+ message: "Invalid ontology policy.",
81
+ retryable: false,
82
+ issues
83
+ });
84
+ if (!ir.policy) throw new BackendError({
85
+ operation: "policy",
86
+ kind: "InvalidConfiguration",
87
+ message: "An explicit ontology policy is required.",
88
+ retryable: false
89
+ });
90
+ const documents = [ir.policy.objects, ...options?.additionalObjects ? [options.additionalObjects] : []].map((document) => resolveQuerySources(ir, document));
91
+ const properties = policyProperties(options?.additionalObjects ? {
92
+ ...ir,
93
+ policy: {
94
+ ...ir.policy,
95
+ objects: { select: [...ir.policy.objects.select, ...options.additionalObjects.select] }
96
+ }
97
+ } : ir);
98
+ const readable = /* @__PURE__ */ new WeakMap();
99
+ const loadSubset = Effect.fn("Policy.loadSubset")(function* (objectType, query = {}) {
100
+ const guaranteed = properties.guaranteed.get(objectType);
101
+ if (!guaranteed || [...filterFields(query)].some((f) => !guaranteed.has(f))) return yield* denied("loadSubset");
102
+ const grants = /* @__PURE__ */ new Map();
103
+ for (const document of documents) {
104
+ const proposed = strategy === "eager" ? [document] : authorizationPlans(document, objectType, query);
105
+ const plans = proposed.some((plan) => validateQueryDocument(ir, plan, {
106
+ mode: "entity",
107
+ inputs: options?.inputDefinitions
108
+ }).length) ? [document] : proposed;
109
+ for (const plan of plans) {
110
+ const result = yield* queryExecutor({
111
+ reader,
112
+ context,
113
+ inputs: options?.inputs,
114
+ inputDefinitions: options?.inputDefinitions,
115
+ mode: "entity"
116
+ }).run(plan);
117
+ for (const entity of result.entities) {
118
+ if (entity.source || entity.objectType !== objectType) continue;
119
+ const key = keyOf(entity.objectType, entity.key);
120
+ const grant = grants.get(key) ?? {
121
+ value: entity.value,
122
+ key: entity.key,
123
+ fields: /* @__PURE__ */ new Set()
124
+ };
125
+ entity.properties.forEach((property) => grant.fields.add(property));
126
+ grants.set(key, grant);
127
+ }
128
+ }
129
+ }
130
+ const rows = [];
131
+ for (const grant of grants.values()) {
132
+ const value = Object.fromEntries(Object.entries(grant.value).filter(([property]) => grant.fields.has(property)));
133
+ readable.set(value, grant.fields);
134
+ rows.push({
135
+ key: grant.key,
136
+ value
137
+ });
138
+ }
139
+ return yield* Effect.try({
140
+ try: () => evaluateQuery(rows, query),
141
+ catch: () => new BackendError({
142
+ operation: "loadSubset",
143
+ kind: "InvalidRequest",
144
+ message: "Invalid authorized subset query.",
145
+ retryable: false
146
+ })
147
+ });
148
+ });
149
+ const tx = {
150
+ loadSubset,
151
+ get: Effect.fnUntraced(function* (objectType, key) {
152
+ const object = ir.objectTypes.find((t) => t.name === objectType);
153
+ if (!object) return yield* denied("get");
154
+ return (yield* loadSubset(objectType, {
155
+ where: eq(field(object.primaryKey), key),
156
+ limit: 1
157
+ }))[0]?.value;
158
+ })
159
+ };
160
+ return {
161
+ ...properties,
162
+ reader: {
163
+ ir,
164
+ loadSubset
165
+ },
166
+ tx,
167
+ canReadProperty: (entity, property) => readable.get(entity.value)?.has(property) ?? false
168
+ };
169
+ }
170
+ //#endregion
171
+ export { denied, evaluatePolicyView, policyProperties };
172
+
173
+ //# sourceMappingURL=view.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"view.js","names":["ref"],"sources":["../../src/policy/view.ts"],"sourcesContent":["import {\n resolveQuerySources,\n validatePolicy,\n selectedProperty,\n validateQueryDocument,\n} from \"@party-stack/ontology-spec/query\";\nimport { field as ref, eq, evaluateQuery } from \"@party-stack/ontology-storage\";\nimport { Effect } from \"effect\";\nimport { BackendError } from \"../index.js\";\nimport { queryExecutor } from \"../query.js\";\nimport { authorizationPlans } from \"./planner.js\";\nimport type { OwnedReadTransaction } from \"../owned.js\";\nimport type { QueryEntity, QueryReader } from \"../query.js\";\nimport type { OntologyIR, Query, QueryDocument, QuerySelection } from \"@party-stack/ontology-spec\";\nimport type { Query as Scan, Key, Row } from \"@party-stack/ontology-storage\";\n\nexport const denied = (operation: string) =>\n new BackendError({\n operation,\n kind: \"Forbidden\",\n message: \"This operation is not permitted.\",\n retryable: false,\n actionOutcome: \"not-committed\",\n });\nconst keyOf = (type: string, key: Key) => JSON.stringify([type, key]);\n\nexport function policyProperties(ir: OntologyIR) {\n const allowed = new Map<string, Set<string>>();\n const guaranteed = new Map<string, Set<string>>();\n type Scope = ReadonlyMap<string, Set<string>>;\n function query(q: Query, parent: Scope) {\n if (q.from.source.ontology) return;\n const object = ir.objectTypes.find((t) => t.name === q.from.source.objectType);\n if (!object) return;\n const upper = allowed.get(object.name) ?? new Set<string>();\n // Publish before descending: another binding of this type must extend\n // the same set, rather than have its grants overwritten on return.\n allowed.set(object.name, upper);\n const scope = new Map([...parent, [q.from.binding, upper]]);\n const always = new Set([object.primaryKey]);\n upper.add(object.primaryKey);\n function selections(items: readonly QuerySelection[], conditional: boolean) {\n for (const item of items) {\n if (item.kind === \"sub\") query(item.value.query, scope);\n else if (item.kind === \"selectCase\") {\n for (const branch of item.value.branches) selections(branch.select, true);\n selections(item.value.else ?? [], true);\n } else {\n const p = selectedProperty(item.value.expression);\n if (p) {\n scope.get(p.binding)?.add(p.property);\n // An ancestor field selected inside a child query is\n // conditional on that child having a matching row.\n if (!conditional && p.binding === q.from.binding) always.add(p.property);\n }\n }\n }\n }\n selections(q.select, false);\n const existing = guaranteed.get(object.name);\n guaranteed.set(object.name, existing ? new Set([...existing].filter((p) => always.has(p))) : always);\n }\n function roots(items: readonly QuerySelection[]) {\n for (const item of items) {\n if (item.kind === \"sub\") query(item.value.query, new Map());\n else if (item.kind === \"selectCase\") {\n item.value.branches.forEach((b) => roots(b.select));\n roots(item.value.else ?? []);\n }\n }\n }\n if (ir.policy) roots(resolveQuerySources(ir, ir.policy.objects).select);\n return { allowed, guaranteed };\n}\nfunction filterFields(query: Scan): Set<string> {\n const result = new Set<string>();\n const visit = (value: unknown): void => {\n if (!value || typeof value !== \"object\") return;\n if (\"_tag\" in value && value._tag === \"Field\" && \"path\" in value && Array.isArray(value.path)) {\n result.add(value.path[0]);\n return;\n }\n Object.values(value).forEach((v) => (Array.isArray(v) ? v.forEach(visit) : visit(v)));\n };\n visit(query.where);\n query.orderBy?.forEach((o) => result.add(o.field.path[0]!));\n return result;\n}\nexport interface PolicyViewOptions {\n readonly additionalObjects?: QueryDocument;\n readonly inputs?: Record<string, unknown>;\n readonly inputDefinitions?: readonly import(\"@party-stack/ontology-spec\").FieldDef[];\n}\n\n/** Bound to one authenticated context. Underlying reader is trusted and owns transaction lifetime. */\nexport function evaluatePolicyView(\n reader: QueryReader,\n context: Record<string, unknown>,\n options?: PolicyViewOptions,\n strategy: \"rewrite\" | \"eager\" = \"rewrite\"\n) {\n const ir = reader.ir;\n const issues = validatePolicy(ir);\n if (issues.length)\n throw new BackendError({\n operation: \"policy\",\n kind: \"InvalidConfiguration\",\n message: \"Invalid ontology policy.\",\n retryable: false,\n issues,\n });\n if (!ir.policy)\n throw new BackendError({\n operation: \"policy\",\n kind: \"InvalidConfiguration\",\n message: \"An explicit ontology policy is required.\",\n retryable: false,\n });\n const documents = [\n ir.policy.objects,\n ...(options?.additionalObjects ? [options.additionalObjects] : []),\n ].map((document) => resolveQuerySources(ir, document));\n const properties = policyProperties(\n options?.additionalObjects\n ? {\n ...ir,\n policy: {\n ...ir.policy,\n objects: { select: [...ir.policy.objects.select, ...options.additionalObjects.select] },\n },\n }\n : ir\n );\n const readable = new WeakMap<object, Set<string>>();\n const loadSubset = Effect.fn(\"Policy.loadSubset\")(function* (objectType: string, query: Scan = {}) {\n const guaranteed = properties.guaranteed.get(objectType);\n if (!guaranteed || [...filterFields(query)].some((f) => !guaranteed.has(f)))\n return yield* denied(\"loadSubset\");\n const grants = new Map<string, { value: Record<string, unknown>; fields: Set<string>; key: Key }>();\n for (const document of documents) {\n const proposed =\n strategy === \"eager\" ? [document] : authorizationPlans(document, objectType, query);\n // A physical caller predicate may use semantics the logical IR cannot\n // express yet. Keep the original plan rather than changing behavior.\n const plans = proposed.some(\n (plan) =>\n validateQueryDocument(ir, plan, { mode: \"entity\", inputs: options?.inputDefinitions })\n .length\n )\n ? [document]\n : proposed;\n for (const plan of plans) {\n const result = yield* queryExecutor({\n reader,\n context,\n inputs: options?.inputs,\n inputDefinitions: options?.inputDefinitions,\n mode: \"entity\",\n }).run(plan);\n for (const entity of result.entities) {\n if (entity.source || entity.objectType !== objectType) continue;\n const key = keyOf(entity.objectType, entity.key);\n const grant = grants.get(key) ?? {\n value: entity.value,\n key: entity.key,\n fields: new Set<string>(),\n };\n entity.properties.forEach((property) => grant.fields.add(property));\n grants.set(key, grant);\n }\n }\n }\n const rows: Row<Record<string, unknown>>[] = [];\n for (const grant of grants.values()) {\n const value = Object.fromEntries(\n Object.entries(grant.value).filter(([property]) => grant.fields.has(property))\n );\n readable.set(value, grant.fields);\n rows.push({ key: grant.key, value });\n }\n return yield* Effect.try({\n try: () => evaluateQuery(rows, query),\n catch: () =>\n new BackendError({\n operation: \"loadSubset\",\n kind: \"InvalidRequest\",\n message: \"Invalid authorized subset query.\",\n retryable: false,\n }),\n });\n });\n const tx: OwnedReadTransaction = {\n loadSubset,\n get: Effect.fnUntraced(function* (objectType, key) {\n const object = ir.objectTypes.find((t) => t.name === objectType);\n if (!object) return yield* denied(\"get\");\n const rows = yield* loadSubset(objectType, { where: eq(ref(object.primaryKey), key), limit: 1 });\n return rows[0]?.value;\n }),\n };\n return {\n ...properties,\n reader: { ir, loadSubset } satisfies QueryReader,\n tx,\n canReadProperty: (entity: QueryEntity, property: string) =>\n readable.get(entity.value)?.has(property) ?? false,\n };\n}\n"],"mappings":";;;;;;;;AAgBA,MAAa,UAAU,cACnB,IAAI,aAAa;CACb;CACA,MAAM;CACN,SAAS;CACT,WAAW;CACX,eAAe;AACnB,CAAC;AACL,MAAM,SAAS,MAAc,QAAa,KAAK,UAAU,CAAC,MAAM,GAAG,CAAC;AAEpE,SAAgB,iBAAiB,IAAgB;CAC7C,MAAM,0BAAU,IAAI,IAAyB;CAC7C,MAAM,6BAAa,IAAI,IAAyB;CAEhD,SAAS,MAAM,GAAU,QAAe;EACpC,IAAI,EAAE,KAAK,OAAO,UAAU;EAC5B,MAAM,SAAS,GAAG,YAAY,MAAM,MAAM,EAAE,SAAS,EAAE,KAAK,OAAO,UAAU;EAC7E,IAAI,CAAC,QAAQ;EACb,MAAM,QAAQ,QAAQ,IAAI,OAAO,IAAI,qBAAK,IAAI,IAAY;EAG1D,QAAQ,IAAI,OAAO,MAAM,KAAK;EAC9B,MAAM,QAAQ,IAAI,IAAI,CAAC,GAAG,QAAQ,CAAC,EAAE,KAAK,SAAS,KAAK,CAAC,CAAC;EAC1D,MAAM,yBAAS,IAAI,IAAI,CAAC,OAAO,UAAU,CAAC;EAC1C,MAAM,IAAI,OAAO,UAAU;EAC3B,SAAS,WAAW,OAAkC,aAAsB;GACxE,KAAK,MAAM,QAAQ,OACf,IAAI,KAAK,SAAS,OAAO,MAAM,KAAK,MAAM,OAAO,KAAK;QACjD,IAAI,KAAK,SAAS,cAAc;IACjC,KAAK,MAAM,UAAU,KAAK,MAAM,UAAU,WAAW,OAAO,QAAQ,IAAI;IACxE,WAAW,KAAK,MAAM,QAAQ,CAAC,GAAG,IAAI;GAC1C,OAAO;IACH,MAAM,IAAI,iBAAiB,KAAK,MAAM,UAAU;IAChD,IAAI,GAAG;KAC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AO;GAAE,CAAC,EAAA,CACnF,EAAE,EAAE;EACpB,CAAC;CACL;CACA,OAAO;EACH,GAAG;EACH,QAAQ;GAAE;GAAI;EAAW;EACzB;EACA,kBAAkB,QAAqB,aACnC,SAAS,IAAI,OAAO,KAAK,CAAC,EAAE,IAAI,QAAQ,KAAK;CACrD;AACJ"}
@@ -0,0 +1,47 @@
1
+ import { BackendError } from "./errors.js";
2
+ import { QueryEntity, QueryReader } from "./query.js";
3
+ import { ActionRequest } from "./index.js";
4
+ import { OwnedReadTransaction } from "./owned.js";
5
+ import { PolicyViewOptions, policyProperties } from "./policy/view.js";
6
+ import { policyIndexes } from "./policy/indexes.js";
7
+ import { actionReferenceIssues } from "./references.js";
8
+ import { Uncertain } from "@party-stack/ontology-spec/utils";
9
+ import { Context, Effect, Schema } from "effect";
10
+ //#region src/policy.d.ts
11
+ export interface ActionAuthorization {
12
+ /** Stable authenticated partition, not a caller-supplied idempotency namespace. */
13
+ readonly scope: string;
14
+ /** Public input contracts exclude server-bound parameters. */
15
+ readonly parameterSchemas: Readonly<Record<string, Schema.Codec<Record<string, unknown>>>>;
16
+ readonly apply: (tx: OwnedReadTransaction, action: ActionRequest) => Effect.Effect<{
17
+ readonly parameters: Record<string, unknown>;
18
+ readonly read: OwnedReadTransaction;
19
+ }, BackendError>;
20
+ }
21
+ /** Trusted invocation context for native application implementations. */
22
+ export declare const CurrentExecutionContext: Context.Reference<Record<string, unknown> | undefined>;
23
+ /** Trusted server composition only; never accepted through RPC data. */
24
+ export declare const CurrentActionAuthorization: Context.Reference<ActionAuthorization | undefined>;
25
+ export declare const CurrentQueryAuthorization: Context.Reference<((tx: OwnedReadTransaction, name: string, parameters: Record<string, unknown>) => Effect.Effect<OwnedReadTransaction, BackendError>) | undefined>;
26
+ /** One production path; the eager evaluator is retained privately for oracle tests. */
27
+ export declare function policyView(reader: QueryReader, context: Record<string, unknown>, options?: PolicyViewOptions): Effect.Effect<{
28
+ allowed: Map<string, Set<string>>;
29
+ guaranteed: Map<string, Set<string>>;
30
+ reader: {
31
+ ir: import("@party-stack/ontology-spec").OntologyIR;
32
+ loadSubset: (objectType: string, query?: import("@party-stack/ontology-storage").Query | undefined) => Effect.Effect<import("@party-stack/ontology-storage").Row<Record<string, unknown>>[], BackendError<"Conflict" | "Forbidden" | "HistoryExpired" | "Internal" | "InvalidConfiguration" | "InvalidRequest" | "InvalidResponse" | "NotFound" | "NotImplemented" | "RateLimited" | "ResultExpired" | "SchemaMismatch" | "SessionExpired" | "SessionReplaced" | "SourceMismatch" | "Unauthenticated" | "Unavailable" | "ValidationFailed" | "ViewReplaced">, never>;
33
+ };
34
+ tx: OwnedReadTransaction;
35
+ canReadProperty: (entity: QueryEntity, property: string) => boolean;
36
+ }, BackendError<any>, never>;
37
+ export declare const authorizeAction: (reader: QueryReader, context: Record<string, unknown>, name: string, supplied: Record<string, unknown>, known?: ReadonlySet<string> | undefined) => Effect.Effect<{
38
+ parameters: {
39
+ [x: string]: unknown;
40
+ };
41
+ knownInputs: Set<string>;
42
+ check: Uncertain<boolean>;
43
+ read: OwnedReadTransaction;
44
+ }, BackendError<any>, never>;
45
+ //#endregion
46
+ export { type PolicyViewOptions, actionReferenceIssues, policyIndexes, policyProperties };
47
+ //# sourceMappingURL=policy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"policy.d.ts","names":["_$__query_js0.QueryEntity"],"sources":["../src/policy.ts"],"mappings":";;;;;;;;;;iBAYiB;;WAEJ;;WAEA,kBAAkB,SAAS,eAAe,OAAO,MAAM;WACvD,QACL,IAAI,sBACJ,QAAQ,kBACP,OAAO;aAEK,YAAY;aACZ,MAAM;KAEnB;;;qBAIK,yBAAuB,QAAA,UAAA;;qBAKvB,4BAA0B,QAAA,UAAA;qBAI1B,2BAAyB,QAAA,YAAA,IAExB,sBAAoB,cACZ,YACA,4BACX,OAAO,OAAO,sBAAsB;;wBAS/B,WACZ,QAAQ,aACR,SAAS,yBACT,UAAU,oBAAiB,OAAA;;;;;;;;;GAe9B;qBAiBY,kBAAe,QAAA,aAAA,SAAA,yBAAA,cAAA,UAAA,yBAAA,QAAA,oCAAA,OAAA;;;;;EA0DJ,OAAA;;GAOtB"}
package/lib/policy.js ADDED
@@ -0,0 +1,100 @@
1
+ import { BackendError } from "./errors.js";
2
+ import "./index.js";
3
+ import { queryExecutor } from "./query.js";
4
+ import { denied, evaluatePolicyView, policyProperties } from "./policy/view.js";
5
+ import { policyIndexes } from "./policy/indexes.js";
6
+ import { actionReferenceIssues } from "./references.js";
7
+ import { Context, Effect } from "effect";
8
+ //#region src/policy.ts
9
+ /** Trusted invocation context for native application implementations. */
10
+ const CurrentExecutionContext = Context.Reference("@party-stack/ontology-backend/CurrentExecutionContext", { defaultValue: () => void 0 });
11
+ /** Trusted server composition only; never accepted through RPC data. */
12
+ const CurrentActionAuthorization = Context.Reference("@party-stack/ontology-backend/CurrentActionAuthorization", { defaultValue: () => void 0 });
13
+ const CurrentQueryAuthorization = Context.Reference("@party-stack/ontology-backend/CurrentQueryAuthorization", { defaultValue: () => void 0 });
14
+ /** One production path; the eager evaluator is retained privately for oracle tests. */
15
+ function policyView(reader, context, options) {
16
+ return Effect.try({
17
+ try: () => evaluatePolicyView(reader, context, options),
18
+ catch: (cause) => cause instanceof BackendError ? cause : new BackendError({
19
+ operation: "policy",
20
+ kind: "InvalidConfiguration",
21
+ retryable: false,
22
+ message: "Invalid ontology policy.",
23
+ cause
24
+ })
25
+ });
26
+ }
27
+ function parameterDependencies(expression) {
28
+ if (expression.kind === "literal") return /* @__PURE__ */ new Set();
29
+ const result = /* @__PURE__ */ new Set();
30
+ const visit = (value) => {
31
+ if (!value || typeof value !== "object") return;
32
+ if ("kind" in value && value.kind === "literal") return;
33
+ if ("kind" in value && value.kind === "inputReference" && "value" in value) {
34
+ result.add(value.value.name);
35
+ return;
36
+ }
37
+ Object.values(value).forEach((v) => Array.isArray(v) ? v.forEach(visit) : visit(v));
38
+ };
39
+ visit(expression);
40
+ return result;
41
+ }
42
+ const authorizeAction = Effect.fn("Policy.authorizeAction")(function* (reader, context, name, supplied, known) {
43
+ const rule = reader.ir.policy?.actions?.find((a) => a.actionType === name);
44
+ const action = reader.ir.actionTypes.find((a) => a.name === name);
45
+ if (!rule || !action) return yield* denied("applyAction");
46
+ const parameters = { ...supplied }, knownInputs = new Set(known ?? action.parameters.map((p) => p.name));
47
+ const bindings = new Map(rule.bind?.map((b) => [b.parameter, b.expression]));
48
+ const done = /* @__PURE__ */ new Set(), visiting = /* @__PURE__ */ new Set();
49
+ const evaluator = queryExecutor({
50
+ reader,
51
+ context,
52
+ inputs: parameters,
53
+ inputDefinitions: action.parameters,
54
+ knownInputs
55
+ });
56
+ const bind = Effect.fnUntraced(function* (parameter) {
57
+ if (done.has(parameter)) return;
58
+ if (visiting.has(parameter)) return yield* new BackendError({
59
+ operation: "policy.bind",
60
+ kind: "InvalidConfiguration",
61
+ message: "Cyclic action parameter bindings.",
62
+ retryable: false
63
+ });
64
+ visiting.add(parameter);
65
+ const expr = bindings.get(parameter);
66
+ for (const dependency of parameterDependencies(expr)) if (bindings.has(dependency)) yield* bind(dependency);
67
+ const value = yield* evaluator.evaluate(expr);
68
+ if (value.certain) {
69
+ parameters[parameter] = value.value;
70
+ knownInputs.add(parameter);
71
+ } else {
72
+ delete parameters[parameter];
73
+ knownInputs.delete(parameter);
74
+ }
75
+ visiting.delete(parameter);
76
+ done.add(parameter);
77
+ });
78
+ for (const parameter of bindings.keys()) yield* bind(parameter);
79
+ const check = yield* evaluator.evaluate(rule.check);
80
+ if (check.certain && typeof check.value !== "boolean") return yield* new BackendError({
81
+ operation: "policy.check",
82
+ kind: "InvalidConfiguration",
83
+ message: "Policy check must return a boolean.",
84
+ retryable: false
85
+ });
86
+ return {
87
+ parameters,
88
+ knownInputs,
89
+ check,
90
+ read: (yield* policyView(reader, context, {
91
+ additionalObjects: rule.additionalObjects,
92
+ inputs: parameters,
93
+ inputDefinitions: action.parameters
94
+ })).tx
95
+ };
96
+ });
97
+ //#endregion
98
+ export { CurrentActionAuthorization, CurrentExecutionContext, CurrentQueryAuthorization, actionReferenceIssues, authorizeAction, policyIndexes, policyProperties, policyView };
99
+
100
+ //# sourceMappingURL=policy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"policy.js","names":[],"sources":["../src/policy.ts"],"sourcesContent":["import { Context, Effect } from \"effect\";\nimport { denied, evaluatePolicyView } from \"./policy/view.js\";\nimport { queryExecutor } from \"./query.js\";\nimport { BackendError } from \"./index.js\";\nimport type { ActionRequest } from \"./index.js\";\nimport type { OwnedReadTransaction } from \"./owned.js\";\nimport type { PolicyViewOptions } from \"./policy/view.js\";\nimport type { QueryReader } from \"./query.js\";\nimport type { Expression } from \"@party-stack/ontology-spec\";\nimport type { Uncertain } from \"@party-stack/ontology-spec/utils\";\nimport type { Schema } from \"effect\";\n\nexport interface ActionAuthorization {\n /** Stable authenticated partition, not a caller-supplied idempotency namespace. */\n readonly scope: string;\n /** Public input contracts exclude server-bound parameters. */\n readonly parameterSchemas: Readonly<Record<string, Schema.Codec<Record<string, unknown>>>>;\n readonly apply: (\n tx: OwnedReadTransaction,\n action: ActionRequest\n ) => Effect.Effect<\n {\n readonly parameters: Record<string, unknown>;\n readonly read: OwnedReadTransaction;\n },\n BackendError\n >;\n}\n/** Trusted invocation context for native application implementations. */\nexport const CurrentExecutionContext = Context.Reference<Record<string, unknown> | undefined>(\n \"@party-stack/ontology-backend/CurrentExecutionContext\",\n { defaultValue: () => undefined }\n);\n/** Trusted server composition only; never accepted through RPC data. */\nexport const CurrentActionAuthorization = Context.Reference<ActionAuthorization | undefined>(\n \"@party-stack/ontology-backend/CurrentActionAuthorization\",\n { defaultValue: () => undefined }\n);\nexport const CurrentQueryAuthorization = Context.Reference<\n | ((\n tx: OwnedReadTransaction,\n name: string,\n parameters: Record<string, unknown>\n ) => Effect.Effect<OwnedReadTransaction, BackendError>)\n | undefined\n>(\"@party-stack/ontology-backend/CurrentQueryAuthorization\", { defaultValue: () => undefined });\nexport { policyProperties } from \"./policy/view.js\";\nexport { policyIndexes } from \"./policy/indexes.js\";\nexport { actionReferenceIssues } from \"./references.js\";\nexport type { PolicyViewOptions } from \"./policy/view.js\";\n\n/** One production path; the eager evaluator is retained privately for oracle tests. */\nexport function policyView(\n reader: QueryReader,\n context: Record<string, unknown>,\n options?: PolicyViewOptions\n) {\n return Effect.try({\n try: () => evaluatePolicyView(reader, context, options),\n catch: (cause) =>\n cause instanceof BackendError\n ? cause\n : new BackendError({\n operation: \"policy\",\n kind: \"InvalidConfiguration\",\n retryable: false,\n message: \"Invalid ontology policy.\",\n cause,\n }),\n });\n}\n\nfunction parameterDependencies(expression: Expression): Set<string> {\n if (expression.kind === \"literal\") return new Set();\n const result = new Set<string>();\n const visit = (value: unknown): void => {\n if (!value || typeof value !== \"object\") return;\n if (\"kind\" in value && value.kind === \"literal\") return;\n if (\"kind\" in value && value.kind === \"inputReference\" && \"value\" in value) {\n result.add((value.value as { name: string }).name);\n return;\n }\n Object.values(value).forEach((v) => (Array.isArray(v) ? v.forEach(visit) : visit(v)));\n };\n visit(expression);\n return result;\n}\nexport const authorizeAction = Effect.fn(\"Policy.authorizeAction\")(function* (\n reader: QueryReader,\n context: Record<string, unknown>,\n name: string,\n supplied: Record<string, unknown>,\n known?: ReadonlySet<string>\n) {\n const rule = reader.ir.policy?.actions?.find((a) => a.actionType === name);\n const action = reader.ir.actionTypes.find((a) => a.name === name);\n if (!rule || !action) return yield* denied(\"applyAction\");\n const parameters = { ...supplied },\n knownInputs = new Set(known ?? action.parameters.map((p) => p.name));\n const bindings = new Map(rule.bind?.map((b) => [b.parameter, b.expression]));\n const done = new Set<string>(),\n visiting = new Set<string>();\n const evaluator = queryExecutor({\n reader,\n context,\n inputs: parameters,\n inputDefinitions: action.parameters,\n knownInputs,\n });\n const bind = Effect.fnUntraced(function* (parameter: string): Effect.fn.Return<void, BackendError> {\n if (done.has(parameter)) return;\n if (visiting.has(parameter))\n return yield* new BackendError({\n operation: \"policy.bind\",\n kind: \"InvalidConfiguration\",\n message: \"Cyclic action parameter bindings.\",\n retryable: false,\n });\n visiting.add(parameter);\n const expr = bindings.get(parameter)!;\n for (const dependency of parameterDependencies(expr))\n if (bindings.has(dependency)) yield* bind(dependency);\n const value = yield* evaluator.evaluate(expr);\n if (value.certain) {\n parameters[parameter] = value.value;\n knownInputs.add(parameter);\n } else {\n delete parameters[parameter];\n knownInputs.delete(parameter);\n }\n visiting.delete(parameter);\n done.add(parameter);\n });\n for (const parameter of bindings.keys()) yield* bind(parameter);\n const check = yield* evaluator.evaluate(rule.check);\n if (check.certain && typeof check.value !== \"boolean\")\n return yield* new BackendError({\n operation: \"policy.check\",\n kind: \"InvalidConfiguration\",\n message: \"Policy check must return a boolean.\",\n retryable: false,\n });\n return {\n parameters,\n knownInputs,\n check: check as Uncertain<boolean>,\n read: (yield* policyView(reader, context, {\n additionalObjects: rule.additionalObjects,\n inputs: parameters,\n inputDefinitions: action.parameters,\n })).tx,\n };\n});\n"],"mappings":";;;;;;;;;AA6BA,MAAa,0BAA0B,QAAQ,UAC3C,yDACA,EAAE,oBAAoB,KAAA,EAAU,CACpC;;AAEA,MAAa,6BAA6B,QAAQ,UAC9C,4DACA,EAAE,oBAAoB,KAAA,EAAU,CACpC;AACA,MAAa,4BAA4B,QAAQ,UAO/C,2DAA2D,EAAE,oBAAoB,KAAA,EAAU,CAAC;;AAO9F,SAAgB,WACZ,QACA,SACA,SACF;CACE,OAAO,OAAO,IAAI;EACd,WAAW,mBAAmB,QAAQ,SAAS,OAAO;EACtD,QAAQ,UACJ,iBAAiB,eACX,QACA,IAAI,aAAa;GACb,WAAW;GACX,MAAM;GACN,WAAW;GACX,SAAS;GACT;EACJ,CAAC;CACf,CAAC;AACL;AAEA,SAAS,sBAAsB,YAAqC;CAChE,IAAI,WAAW,SAAS,WAAW,uBAAO,IAAI,IAAI;CAClD,MAAM,yBAAS,IAAI,IAAY;CAC/B,MAAM,SAAS,UAAyB;EACpC,IAAI,CAAC,SAA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