@lssm/lib.contracts 0.0.0-canary-20251220041653 → 0.0.0-canary-20251221132705

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 (80) hide show
  1. package/README.md +4 -4
  2. package/dist/_virtual/rolldown_runtime.js +37 -0
  3. package/dist/app-config/contracts.d.ts +60 -60
  4. package/dist/app-config/contracts.js +1 -1
  5. package/dist/app-config/events.d.ts +27 -27
  6. package/dist/app-config/lifecycle-contracts.d.ts +90 -90
  7. package/dist/app-config/lifecycle-contracts.js +1 -1
  8. package/dist/data-views.d.ts +11 -0
  9. package/dist/data-views.js +26 -0
  10. package/dist/docs/tech/contracts/README.docblock.js +2 -2
  11. package/dist/docs/tech/contracts/openapi-export.docblock.js +6 -6
  12. package/dist/docs/tech/contracts/ops-to-presentation-linking.docblock.js +2 -2
  13. package/dist/docs/tech/contracts/tests.docblock.js +2 -2
  14. package/dist/experiments/spec-resolver.d.ts +2 -2
  15. package/dist/features.d.ts +16 -5
  16. package/dist/features.js +26 -0
  17. package/dist/forms.d.ts +11 -0
  18. package/dist/forms.js +26 -0
  19. package/dist/index.d.ts +7 -5
  20. package/dist/index.js +10 -4
  21. package/dist/install.d.ts +16 -16
  22. package/dist/integrations/contracts.d.ts +111 -111
  23. package/dist/integrations/contracts.js +1 -1
  24. package/dist/integrations/openbanking/contracts/accounts.d.ts +73 -73
  25. package/dist/integrations/openbanking/contracts/accounts.js +1 -1
  26. package/dist/integrations/openbanking/contracts/balances.d.ts +40 -40
  27. package/dist/integrations/openbanking/contracts/balances.js +1 -1
  28. package/dist/integrations/openbanking/contracts/index.d.ts +2 -2
  29. package/dist/integrations/openbanking/contracts/transactions.d.ts +54 -54
  30. package/dist/integrations/openbanking/contracts/transactions.js +1 -1
  31. package/dist/integrations/openbanking/models.d.ts +55 -55
  32. package/dist/jsonschema.d.ts +5 -5
  33. package/dist/knowledge/contracts.d.ts +75 -75
  34. package/dist/knowledge/contracts.js +1 -1
  35. package/dist/llm/exporters.d.ts +8 -8
  36. package/dist/llm/exporters.js +1 -1
  37. package/dist/llm/prompts.d.ts +7 -7
  38. package/dist/llm/types.d.ts +3 -3
  39. package/dist/markdown.d.ts +3 -3
  40. package/dist/markdown.js +1 -1
  41. package/dist/onboarding-base.d.ts +32 -32
  42. package/dist/onboarding-base.js +1 -1
  43. package/dist/openapi.d.ts +2 -2
  44. package/dist/{spec.d.ts → operation.d.ts} +12 -12
  45. package/dist/{spec.js → operation.js} +1 -1
  46. package/dist/policy/docs/policy.docblock.js +1 -1
  47. package/dist/presentations.d.ts +14 -3
  48. package/dist/presentations.js +25 -0
  49. package/dist/registry-utils.d.ts +107 -0
  50. package/dist/registry-utils.js +122 -0
  51. package/dist/registry.d.ts +46 -14
  52. package/dist/registry.js +61 -5
  53. package/dist/server/graphql-pothos.d.ts +6 -6
  54. package/dist/server/graphql-pothos.js +4 -4
  55. package/dist/server/mcp/createMcpServer.d.ts +3 -3
  56. package/dist/server/mcp/createMcpServer.js +1 -1
  57. package/dist/server/mcp/registerTools.d.ts +2 -2
  58. package/dist/server/rest-elysia.d.ts +2 -2
  59. package/dist/server/rest-express.d.ts +2 -2
  60. package/dist/server/rest-generic.d.ts +3 -3
  61. package/dist/server/rest-generic.js +1 -1
  62. package/dist/server/rest-next-app.d.ts +4 -4
  63. package/dist/server/rest-next-app.js +2 -2
  64. package/dist/server/rest-next-mcp.d.ts +2 -2
  65. package/dist/server/rest-next-pages.d.ts +2 -2
  66. package/dist/telemetry/docs/telemetry.docblock.js +1 -1
  67. package/dist/tests/runner.d.ts +2 -2
  68. package/dist/tests/spec.d.ts +1 -1
  69. package/dist/workflow/spec.d.ts +11 -1
  70. package/dist/workflow/spec.js +26 -0
  71. package/dist/workflow/validation.d.ts +2 -2
  72. package/dist/workspace-config/contractsrc-schema.d.ts +298 -0
  73. package/dist/workspace-config/contractsrc-schema.js +139 -0
  74. package/dist/workspace-config/index.d.ts +2 -0
  75. package/dist/workspace-config/index.js +3 -0
  76. package/package.json +14 -13
  77. package/dist/presentations.backcompat.d.ts +0 -7
  78. package/dist/presentations.backcompat.js +0 -47
  79. package/dist/types/all.d.ts +0 -60
  80. package/dist/types/all.js +0 -0
@@ -1,135 +1,135 @@
1
- import { ContractSpec } from "./spec.js";
2
- import * as _lssm_lib_schema7 from "@lssm/lib.schema";
1
+ import { OperationSpec } from "./operation.js";
2
+ import * as _lssm_lib_schema206 from "@lssm/lib.schema";
3
3
  import { SchemaModel } from "@lssm/lib.schema";
4
4
 
5
5
  //#region src/onboarding-base.d.ts
6
6
  /** Save/update onboarding draft (auto-save during flow) */
7
7
  declare const SaveOnboardingDraftInput: SchemaModel<{
8
8
  data: {
9
- type: _lssm_lib_schema7.FieldType<unknown, unknown>;
9
+ type: _lssm_lib_schema206.FieldType<unknown, unknown>;
10
10
  isOptional: false;
11
11
  };
12
12
  }>;
13
13
  declare const SaveOnboardingDraftOutput: SchemaModel<{
14
14
  id: {
15
- type: _lssm_lib_schema7.FieldType<string, string>;
15
+ type: _lssm_lib_schema206.FieldType<string, string>;
16
16
  isOptional: false;
17
17
  };
18
18
  organizationId: {
19
- type: _lssm_lib_schema7.FieldType<string, string>;
19
+ type: _lssm_lib_schema206.FieldType<string, string>;
20
20
  isOptional: false;
21
21
  };
22
22
  }>;
23
- declare const SaveOnboardingDraftBaseSpec: ContractSpec<SchemaModel<{
23
+ declare const SaveOnboardingDraftBaseSpec: OperationSpec<SchemaModel<{
24
24
  data: {
25
- type: _lssm_lib_schema7.FieldType<unknown, unknown>;
25
+ type: _lssm_lib_schema206.FieldType<unknown, unknown>;
26
26
  isOptional: false;
27
27
  };
28
28
  }>, SchemaModel<{
29
29
  id: {
30
- type: _lssm_lib_schema7.FieldType<string, string>;
30
+ type: _lssm_lib_schema206.FieldType<string, string>;
31
31
  isOptional: false;
32
32
  };
33
33
  organizationId: {
34
- type: _lssm_lib_schema7.FieldType<string, string>;
34
+ type: _lssm_lib_schema206.FieldType<string, string>;
35
35
  isOptional: false;
36
36
  };
37
37
  }>, undefined>;
38
38
  /** Get current onboarding draft (on mount/restore) */
39
39
  declare const GetOnboardingDraftOutput: SchemaModel<{
40
40
  id: {
41
- type: _lssm_lib_schema7.FieldType<string, string>;
41
+ type: _lssm_lib_schema206.FieldType<string, string>;
42
42
  isOptional: true;
43
43
  };
44
44
  organizationId: {
45
- type: _lssm_lib_schema7.FieldType<string, string>;
45
+ type: _lssm_lib_schema206.FieldType<string, string>;
46
46
  isOptional: true;
47
47
  };
48
48
  data: {
49
- type: _lssm_lib_schema7.FieldType<unknown, unknown>;
49
+ type: _lssm_lib_schema206.FieldType<unknown, unknown>;
50
50
  isOptional: true;
51
51
  };
52
52
  createdAt: {
53
- type: _lssm_lib_schema7.FieldType<Date, string>;
53
+ type: _lssm_lib_schema206.FieldType<Date, string>;
54
54
  isOptional: true;
55
55
  };
56
56
  updatedAt: {
57
- type: _lssm_lib_schema7.FieldType<Date, string>;
57
+ type: _lssm_lib_schema206.FieldType<Date, string>;
58
58
  isOptional: true;
59
59
  };
60
60
  }>;
61
- declare const GetOnboardingDraftBaseSpec: ContractSpec<_lssm_lib_schema7.AnySchemaModel, SchemaModel<{
61
+ declare const GetOnboardingDraftBaseSpec: OperationSpec<_lssm_lib_schema206.AnySchemaModel, SchemaModel<{
62
62
  id: {
63
- type: _lssm_lib_schema7.FieldType<string, string>;
63
+ type: _lssm_lib_schema206.FieldType<string, string>;
64
64
  isOptional: true;
65
65
  };
66
66
  organizationId: {
67
- type: _lssm_lib_schema7.FieldType<string, string>;
67
+ type: _lssm_lib_schema206.FieldType<string, string>;
68
68
  isOptional: true;
69
69
  };
70
70
  data: {
71
- type: _lssm_lib_schema7.FieldType<unknown, unknown>;
71
+ type: _lssm_lib_schema206.FieldType<unknown, unknown>;
72
72
  isOptional: true;
73
73
  };
74
74
  createdAt: {
75
- type: _lssm_lib_schema7.FieldType<Date, string>;
75
+ type: _lssm_lib_schema206.FieldType<Date, string>;
76
76
  isOptional: true;
77
77
  };
78
78
  updatedAt: {
79
- type: _lssm_lib_schema7.FieldType<Date, string>;
79
+ type: _lssm_lib_schema206.FieldType<Date, string>;
80
80
  isOptional: true;
81
81
  };
82
82
  }>, undefined>;
83
83
  /** Delete onboarding draft (cleanup after completion or cancel) */
84
84
  declare const DeleteOnboardingDraftOutput: SchemaModel<{
85
85
  ok: {
86
- type: _lssm_lib_schema7.FieldType<boolean, boolean>;
86
+ type: _lssm_lib_schema206.FieldType<boolean, boolean>;
87
87
  isOptional: false;
88
88
  };
89
89
  }>;
90
- declare const DeleteOnboardingDraftBaseSpec: ContractSpec<_lssm_lib_schema7.AnySchemaModel, SchemaModel<{
90
+ declare const DeleteOnboardingDraftBaseSpec: OperationSpec<_lssm_lib_schema206.AnySchemaModel, SchemaModel<{
91
91
  ok: {
92
- type: _lssm_lib_schema7.FieldType<boolean, boolean>;
92
+ type: _lssm_lib_schema206.FieldType<boolean, boolean>;
93
93
  isOptional: false;
94
94
  };
95
95
  }>, undefined>;
96
96
  /** Complete onboarding (final submit, creates entities) */
97
97
  declare const CompleteOnboardingBaseInput: SchemaModel<{
98
98
  data: {
99
- type: _lssm_lib_schema7.FieldType<unknown, unknown>;
99
+ type: _lssm_lib_schema206.FieldType<unknown, unknown>;
100
100
  isOptional: false;
101
101
  };
102
102
  }>;
103
103
  declare const CompleteOnboardingBaseOutput: SchemaModel<{
104
104
  success: {
105
- type: _lssm_lib_schema7.FieldType<boolean, boolean>;
105
+ type: _lssm_lib_schema206.FieldType<boolean, boolean>;
106
106
  isOptional: false;
107
107
  };
108
108
  userId: {
109
- type: _lssm_lib_schema7.FieldType<string, string>;
109
+ type: _lssm_lib_schema206.FieldType<string, string>;
110
110
  isOptional: true;
111
111
  };
112
112
  organizationId: {
113
- type: _lssm_lib_schema7.FieldType<string, string>;
113
+ type: _lssm_lib_schema206.FieldType<string, string>;
114
114
  isOptional: true;
115
115
  };
116
116
  }>;
117
- declare const CompleteOnboardingBaseSpec: ContractSpec<SchemaModel<{
117
+ declare const CompleteOnboardingBaseSpec: OperationSpec<SchemaModel<{
118
118
  data: {
119
- type: _lssm_lib_schema7.FieldType<unknown, unknown>;
119
+ type: _lssm_lib_schema206.FieldType<unknown, unknown>;
120
120
  isOptional: false;
121
121
  };
122
122
  }>, SchemaModel<{
123
123
  success: {
124
- type: _lssm_lib_schema7.FieldType<boolean, boolean>;
124
+ type: _lssm_lib_schema206.FieldType<boolean, boolean>;
125
125
  isOptional: false;
126
126
  };
127
127
  userId: {
128
- type: _lssm_lib_schema7.FieldType<string, string>;
128
+ type: _lssm_lib_schema206.FieldType<string, string>;
129
129
  isOptional: true;
130
130
  };
131
131
  organizationId: {
132
- type: _lssm_lib_schema7.FieldType<string, string>;
132
+ type: _lssm_lib_schema206.FieldType<string, string>;
133
133
  isOptional: true;
134
134
  };
135
135
  }>, undefined>;
@@ -1,5 +1,5 @@
1
1
  import { E5, x8 } from "./schema/dist/index.js";
2
- import { defineCommand, defineQuery } from "./spec.js";
2
+ import { defineCommand, defineQuery } from "./operation.js";
3
3
  import { OwnersEnum, StabilityEnum } from "./ownership.js";
4
4
 
5
5
  //#region src/onboarding-base.ts
package/dist/openapi.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { SpecRegistry } from "./registry.js";
1
+ import { OperationSpecRegistry } from "./registry.js";
2
2
 
3
3
  //#region src/openapi.d.ts
4
4
 
@@ -26,6 +26,6 @@ interface OpenApiDocument {
26
26
  schemas: Record<string, OpenApiSchemaObject>;
27
27
  };
28
28
  }
29
- declare function openApiForRegistry(registry: SpecRegistry, options?: OpenApiExportOptions): OpenApiDocument;
29
+ declare function openApiForRegistry(registry: OperationSpecRegistry, options?: OpenApiExportOptions): OpenApiDocument;
30
30
  //#endregion
31
31
  export { OpenApiDocument, OpenApiExportOptions, OpenApiServer, openApiForRegistry };
@@ -6,7 +6,7 @@ import { PolicyRef } from "./policy/spec.js";
6
6
  import { TestSpecRef } from "./tests/spec.js";
7
7
  import { AnySchemaModel } from "@lssm/lib.schema";
8
8
 
9
- //#region src/spec.d.ts
9
+ //#region src/operation.d.ts
10
10
 
11
11
  /**
12
12
  * Distinguishes between state-changing operations (command) and read-only operations (query).
@@ -62,7 +62,7 @@ interface TelemetryTrigger {
62
62
  * @template Output - The Zod-backed schema model for the output payload, or a resource reference.
63
63
  * @template Events - Tuple of events that this operation may emit.
64
64
  */
65
- interface ContractSpec<Input extends AnySchemaModel, Output extends AnySchemaModel | ResourceRefDescriptor<boolean>, Events extends readonly EmitDecl[] | undefined = readonly EmitDecl[] | undefined> {
65
+ interface OperationSpec<Input extends AnySchemaModel, Output extends AnySchemaModel | ResourceRefDescriptor<boolean>, Events extends readonly EmitDecl[] | undefined = readonly EmitDecl[] | undefined> {
66
66
  meta: {
67
67
  /** Fully-qualified op name (e.g., "sigil.beginSignup") */
68
68
  name: string;
@@ -174,22 +174,22 @@ interface ContractSpec<Input extends AnySchemaModel, Output extends AnySchemaMod
174
174
  */
175
175
  implementations?: ImplementationRef[];
176
176
  }
177
- type AnyContractSpec = ContractSpec<AnySchemaModel, AnySchemaModel | ResourceRefDescriptor<boolean>>;
177
+ type AnyOperationSpec = OperationSpec<AnySchemaModel, AnySchemaModel | ResourceRefDescriptor<boolean>>;
178
178
  /**
179
179
  * Helper to define a Command (write operation).
180
180
  * Sets `kind: 'command'` and defaults `idempotent: false`.
181
181
  */
182
- declare const defineCommand: <I extends AnySchemaModel, O extends AnySchemaModel | ResourceRefDescriptor<boolean>, E extends readonly EmitDecl[] | undefined = undefined>(spec: Omit<ContractSpec<I, O, E>, "meta" | "policy"> & {
183
- meta: Omit<ContractSpec<I, O, E>["meta"], "kind">;
184
- policy: Omit<ContractSpec<I, O, E>["policy"], "idempotent">;
185
- }) => ContractSpec<I, O, E>;
182
+ declare const defineCommand: <I extends AnySchemaModel, O extends AnySchemaModel | ResourceRefDescriptor<boolean>, E extends readonly EmitDecl[] | undefined = undefined>(spec: Omit<OperationSpec<I, O, E>, "meta" | "policy"> & {
183
+ meta: Omit<OperationSpec<I, O, E>["meta"], "kind">;
184
+ policy: Omit<OperationSpec<I, O, E>["policy"], "idempotent">;
185
+ }) => OperationSpec<I, O, E>;
186
186
  /**
187
187
  * Helper to define a Query (read-only operation).
188
188
  * Sets `kind: 'query'` and forces `idempotent: true`.
189
189
  */
190
- declare const defineQuery: <I extends AnySchemaModel, O extends AnySchemaModel | ResourceRefDescriptor<boolean>, E extends readonly EmitDecl[] | undefined = undefined>(spec: Omit<ContractSpec<I, O, E>, "meta" | "policy"> & {
191
- meta: Omit<ContractSpec<I, O, E>["meta"], "kind">;
192
- policy: Omit<ContractSpec<I, O, E>["policy"], "idempotent">;
193
- }) => ContractSpec<I, O, E>;
190
+ declare const defineQuery: <I extends AnySchemaModel, O extends AnySchemaModel | ResourceRefDescriptor<boolean>, E extends readonly EmitDecl[] | undefined = undefined>(spec: Omit<OperationSpec<I, O, E>, "meta" | "policy"> & {
191
+ meta: Omit<OperationSpec<I, O, E>["meta"], "kind">;
192
+ policy: Omit<OperationSpec<I, O, E>["policy"], "idempotent">;
193
+ }) => OperationSpec<I, O, E>;
194
194
  //#endregion
195
- export { AnyContractSpec, ContractSpec, EmitDecl, EmitDeclInline, EmitDeclRef, ImplementationRef, ImplementationType, OpKind, TelemetryTrigger, defineCommand, defineQuery, isEmitDeclRef };
195
+ export { AnyOperationSpec, EmitDecl, EmitDeclInline, EmitDeclRef, ImplementationRef, ImplementationType, OpKind, OperationSpec, TelemetryTrigger, defineCommand, defineQuery, isEmitDeclRef };
@@ -1,4 +1,4 @@
1
- //#region src/spec.ts
1
+ //#region src/operation.ts
2
2
  const isEmitDeclRef = (e) => "ref" in e;
3
3
  /**
4
4
  * Helper to define a Command (write operation).
@@ -14,7 +14,7 @@ const tech_contracts_policy_DocBlocks = [{
14
14
  "contracts",
15
15
  "policy"
16
16
  ],
17
- body: "# PolicySpec & PolicyEngine\n\n## Purpose\n\n`PolicySpec` gives a declarative, typed home for access-control logic covering:\n- **Who** can perform an action (ABAC/ReBAC style rules)\n- **What** they can access (resources + optional field-level overrides)\n- **When** special conditions apply (contextual expressions)\n- **How** PII should be handled (consent/retention hints)\n\n`PolicyEngine` evaluates one or more policies and returns an `allow`/`deny` decision, field-level outcomes, and PII metadata suitable for downstream enforcement (`SpecRegistry` → `ctx.decide`).\n\n## Location\n\n- Types & registry: `packages/libs/contracts/src/policy/spec.ts`\n- Runtime evaluation: `packages/libs/contracts/src/policy/engine.ts`\n- Tests: `packages/.../policy/engine.test.ts`\n\n## `PolicySpec`\n\n```ts\nexport interface PolicySpec {\n meta: PolicyMeta; // ownership metadata + { name, version, scope? }\n rules: PolicyRule[]; // allow/deny rules for actions\n fieldPolicies?: FieldPolicyRule[];\n pii?: { fields: string[]; consentRequired?: boolean; retentionDays?: number };\n relationships?: RelationshipDefinition[];\n consents?: ConsentDefinition[];\n rateLimits?: RateLimitDefinition[];\n opa?: { package: string; decision?: string };\n}\n```\n\n- `PolicyRule`\n - `effect`: `'allow' | 'deny'`\n - `actions`: e.g., `['read', 'write', 'delete']` (string namespace is flexible)\n - `subject`: `{ roles?: string[]; attributes?: { attr: matcher } }`\n - `resource`: `{ type: string; fields?: string[]; attributes?: {...} }`\n - `relationships`: `{ relation, objectId?, objectType? }[]` → ReBAC checks (use `objectId: '$resource'` to target the current resource)\n - `requiresConsent`: `['consent_id']` → references spec-level consent definitions\n - `flags`: feature flags that must be enabled (`DecisionContext.flags`)\n - `rateLimit`: string reference to `rateLimits` entry or inline object `{ rpm, key?, windowSeconds?, burst? }`\n - `escalate`: `'human_review' | null` to indicate manual approval\n - `conditions`: optional expression snippets evaluated against `{ subject, resource, context }`\n- `FieldPolicyRule`\n - `field`: dot-path string (e.g., `contact.email`)\n - `actions`: subset of `['read', 'write']`\n - Same `subject` / `resource` / `conditions` shape\n - Useful for redacting specific fields, even when the global action is allowed\n- `RelationshipDefinition`\n - Canonical tuples for relationship graph (`subjectType`, `relation`, `objectType`, `transitive?`)\n- `ConsentDefinition`\n - `{ id, scope, purpose, lawfulBasis?, expiresInDays?, required? }`\n- `RateLimitDefinition`\n - `{ id, rpm, key?, windowSeconds?, burst? }`\n- `PolicyRef`\n - `{ name: string; version: number }` → attach to contract specs / workflows\n\n## Registry\n\n```ts\nconst registry = new PolicyRegistry();\nregistry.register(CorePolicySpec);\nconst spec = registry.get('core.default', 1);\n```\n\nGuarantees uniqueness per `(name, version)` and exposes helpers to resolve highest versions.\n\n## Engine\n\n```ts\nconst engine = new PolicyEngine(policyRegistry);\n\nconst decision = engine.decide({\n action: 'read',\n subject: { roles: ['admin'] },\n resource: { type: 'resident', fields: ['contact.email'] },\n policies: [{ name: 'core.default', version: 1 }],\n});\n/*\n{\n effect: 'allow',\n reason: 'core.default',\n fieldDecisions: [{ field: 'contact.email', effect: 'allow' }],\n pii: { fields: ['contact.email'], consentRequired: true }\n}\n*/\n```\n\n- First matching **deny** wins; otherwise the first **allow** is returned.\n- Field policies are aggregated across referenced policies:\n - Later denies override earlier allows for a given field.\n - Returned as `fieldDecisions` to simplify downstream masking.\n- PII metadata is surfaced when defined to help adapt logging/telemetry.\n\n### Expression Support\n\nConditions accept small JS snippets (e.g., `subject.attributes.orgId === context.orgId`). The engine runs them in a constrained scope (`subject`, `resource`, `context`) without access to global state.\n\n### ReBAC & Relationships\n\n- Provide relationship tuples via `PolicySpec.relationships` for documentation/validation.\n- Reference them inside rules with `relationships: [{ relation: 'manager_of', objectType: 'resident', objectId: '$resource' }]`.\n- The execution context must populate `subject.relationships` (`[{ relation, object, objectType }]`) for the engine to evaluate ReBAC guards.\n\n### Consent & Rate Limits\n\n- Declare reusable consent definitions under `consents`. Rules list the IDs they require; if a user session lacks the consent (`DecisionContext.consents`), the engine returns `effect: 'deny'` with `reason: 'consent_required'` and enumerates missing consents.\n- Attach rate limits either inline or via `rateLimits` references. When a rule matches, the engine surfaces `{ rpm, key, windowSeconds?, burst? }` so callers can feed it to shared limiters.\n\n### OPA Adapter\n\n- `OPAPolicyAdapter` bridges engine decisions to Open Policy Agent (OPA). It forwards the evaluation context + policies to OPA and merges any override result (`effect`, `reason`, `fieldDecisions`, `requiredConsents`).\n- Use when migrating to OPA policies or running defense-in-depth: call `engine.decide()`, then pass the preliminary decision to `adapter.evaluate(...)`. The adapter marks merged decisions with `evaluatedBy: 'opa'`.\n- OPA inputs include meta, rules, relationships, rate limits, and consent catalogs to simplify policy authoring on the OPA side.\n\n## Contract Integration\n\n`ContractSpec.policy` now supports:\n\n```ts\npolicy: {\n auth: 'anonymous' | 'user' | 'admin';\n ...\n policies?: PolicyRef[]; // policies evaluated before execution\n fieldPolicies?: { // field hints (read/write) per policy\n field: string;\n actions: ('read' | 'write')[];\n policy?: PolicyRef;\n }[];\n}\n```\n\nAdapters can resolve refs through a shared `PolicyEngine` and populate `ctx.decide` so `SpecRegistry.execute` benefits from centralized enforcement.\n\n## Authoring Guidelines\n\n1. Prefer **allow-by-default** policies but explicitly deny sensitive flows (defense-in-depth).\n2. Keep rule scopes narrow (per feature/operation) and compose multiple `PolicyRef`s when necessary.\n3. Store PII field lists here to avoid duplication across logs/telemetry.\n4. Use explicit rule reasons for auditability and better developer feedback.\n5. Treat versioning seriously; bump `meta.version` whenever behavior changes.\n\n## Future Enhancements\n\n- Richer expression language (composable predicates, time-based conditions).\n- Multi-tenant relationship graph services (store/resolve relationships at scale).\n- Tooling that auto-generates docs/tests for policies referenced in specs.\n\n"
17
+ body: "# PolicySpec & PolicyEngine\n\n## Purpose\n\n`PolicySpec` gives a declarative, typed home for access-control logic covering:\n- **Who** can perform an action (ABAC/ReBAC style rules)\n- **What** they can access (resources + optional field-level overrides)\n- **When** special conditions apply (contextual expressions)\n- **How** PII should be handled (consent/retention hints)\n\n`PolicyEngine` evaluates one or more policies and returns an `allow`/`deny` decision, field-level outcomes, and PII metadata suitable for downstream enforcement (`OperationSpecRegistry` → `ctx.decide`).\n\n## Location\n\n- Types & registry: `packages/libs/contracts/src/policy/spec.ts`\n- Runtime evaluation: `packages/libs/contracts/src/policy/engine.ts`\n- Tests: `packages/.../policy/engine.test.ts`\n\n## `PolicySpec`\n\n```ts\nexport interface PolicySpec {\n meta: PolicyMeta; // ownership metadata + { name, version, scope? }\n rules: PolicyRule[]; // allow/deny rules for actions\n fieldPolicies?: FieldPolicyRule[];\n pii?: { fields: string[]; consentRequired?: boolean; retentionDays?: number };\n relationships?: RelationshipDefinition[];\n consents?: ConsentDefinition[];\n rateLimits?: RateLimitDefinition[];\n opa?: { package: string; decision?: string };\n}\n```\n\n- `PolicyRule`\n - `effect`: `'allow' | 'deny'`\n - `actions`: e.g., `['read', 'write', 'delete']` (string namespace is flexible)\n - `subject`: `{ roles?: string[]; attributes?: { attr: matcher } }`\n - `resource`: `{ type: string; fields?: string[]; attributes?: {...} }`\n - `relationships`: `{ relation, objectId?, objectType? }[]` → ReBAC checks (use `objectId: '$resource'` to target the current resource)\n - `requiresConsent`: `['consent_id']` → references spec-level consent definitions\n - `flags`: feature flags that must be enabled (`DecisionContext.flags`)\n - `rateLimit`: string reference to `rateLimits` entry or inline object `{ rpm, key?, windowSeconds?, burst? }`\n - `escalate`: `'human_review' | null` to indicate manual approval\n - `conditions`: optional expression snippets evaluated against `{ subject, resource, context }`\n- `FieldPolicyRule`\n - `field`: dot-path string (e.g., `contact.email`)\n - `actions`: subset of `['read', 'write']`\n - Same `subject` / `resource` / `conditions` shape\n - Useful for redacting specific fields, even when the global action is allowed\n- `RelationshipDefinition`\n - Canonical tuples for relationship graph (`subjectType`, `relation`, `objectType`, `transitive?`)\n- `ConsentDefinition`\n - `{ id, scope, purpose, lawfulBasis?, expiresInDays?, required? }`\n- `RateLimitDefinition`\n - `{ id, rpm, key?, windowSeconds?, burst? }`\n- `PolicyRef`\n - `{ name: string; version: number }` → attach to contract specs / workflows\n\n## Registry\n\n```ts\nconst registry = new PolicyRegistry();\nregistry.register(CorePolicySpec);\nconst spec = registry.get('core.default', 1);\n```\n\nGuarantees uniqueness per `(name, version)` and exposes helpers to resolve highest versions.\n\n## Engine\n\n```ts\nconst engine = new PolicyEngine(policyRegistry);\n\nconst decision = engine.decide({\n action: 'read',\n subject: { roles: ['admin'] },\n resource: { type: 'resident', fields: ['contact.email'] },\n policies: [{ name: 'core.default', version: 1 }],\n});\n/*\n{\n effect: 'allow',\n reason: 'core.default',\n fieldDecisions: [{ field: 'contact.email', effect: 'allow' }],\n pii: { fields: ['contact.email'], consentRequired: true }\n}\n*/\n```\n\n- First matching **deny** wins; otherwise the first **allow** is returned.\n- Field policies are aggregated across referenced policies:\n - Later denies override earlier allows for a given field.\n - Returned as `fieldDecisions` to simplify downstream masking.\n- PII metadata is surfaced when defined to help adapt logging/telemetry.\n\n### Expression Support\n\nConditions accept small JS snippets (e.g., `subject.attributes.orgId === context.orgId`). The engine runs them in a constrained scope (`subject`, `resource`, `context`) without access to global state.\n\n### ReBAC & Relationships\n\n- Provide relationship tuples via `PolicySpec.relationships` for documentation/validation.\n- Reference them inside rules with `relationships: [{ relation: 'manager_of', objectType: 'resident', objectId: '$resource' }]`.\n- The execution context must populate `subject.relationships` (`[{ relation, object, objectType }]`) for the engine to evaluate ReBAC guards.\n\n### Consent & Rate Limits\n\n- Declare reusable consent definitions under `consents`. Rules list the IDs they require; if a user session lacks the consent (`DecisionContext.consents`), the engine returns `effect: 'deny'` with `reason: 'consent_required'` and enumerates missing consents.\n- Attach rate limits either inline or via `rateLimits` references. When a rule matches, the engine surfaces `{ rpm, key, windowSeconds?, burst? }` so callers can feed it to shared limiters.\n\n### OPA Adapter\n\n- `OPAPolicyAdapter` bridges engine decisions to Open Policy Agent (OPA). It forwards the evaluation context + policies to OPA and merges any override result (`effect`, `reason`, `fieldDecisions`, `requiredConsents`).\n- Use when migrating to OPA policies or running defense-in-depth: call `engine.decide()`, then pass the preliminary decision to `adapter.evaluate(...)`. The adapter marks merged decisions with `evaluatedBy: 'opa'`.\n- OPA inputs include meta, rules, relationships, rate limits, and consent catalogs to simplify policy authoring on the OPA side.\n\n## Contract Integration\n\n`ContractSpec.policy` now supports:\n\n```ts\npolicy: {\n auth: 'anonymous' | 'user' | 'admin';\n ...\n policies?: PolicyRef[]; // policies evaluated before execution\n fieldPolicies?: { // field hints (read/write) per policy\n field: string;\n actions: ('read' | 'write')[];\n policy?: PolicyRef;\n }[];\n}\n```\n\nAdapters can resolve refs through a shared `PolicyEngine` and populate `ctx.decide` so `OperationSpecRegistry.execute` benefits from centralized enforcement.\n\n## Authoring Guidelines\n\n1. Prefer **allow-by-default** policies but explicitly deny sensitive flows (defense-in-depth).\n2. Keep rule scopes narrow (per feature/operation) and compose multiple `PolicyRef`s when necessary.\n3. Store PII field lists here to avoid duplication across logs/telemetry.\n4. Use explicit rule reasons for auditability and better developer feedback.\n5. Treat versioning seriously; bump `meta.version` whenever behavior changes.\n\n## Future Enhancements\n\n- Richer expression language (composable predicates, time-based conditions).\n- Multi-tenant relationship graph services (store/resolve relationships at scale).\n- Tooling that auto-generates docs/tests for policies referenced in specs.\n\n"
18
18
  }];
19
19
  registerDocBlocks(tech_contracts_policy_DocBlocks);
20
20
 
@@ -1,6 +1,7 @@
1
1
  import { Stability } from "./ownership.js";
2
+ import { GroupKeyFn, RegistryFilter } from "./registry-utils.js";
2
3
  import z from "zod";
3
- import * as _lssm_lib_schema89 from "@lssm/lib.schema";
4
+ import * as _lssm_lib_schema234 from "@lssm/lib.schema";
4
5
  import { AnySchemaModel } from "@lssm/lib.schema";
5
6
 
6
7
  //#region src/presentations.d.ts
@@ -58,11 +59,21 @@ declare class PresentationRegistry {
58
59
  register(p: PresentationSpec): this;
59
60
  list(): PresentationSpec[];
60
61
  get(name: string, version?: number): PresentationSpec | undefined;
62
+ /** Filter presentations by criteria. */
63
+ filter(criteria: RegistryFilter): PresentationSpec[];
64
+ /** List presentations with specific tag. */
65
+ listByTag(tag: string): PresentationSpec[];
66
+ /** List presentations by owner. */
67
+ listByOwner(owner: string): PresentationSpec[];
68
+ /** Group presentations by key function. */
69
+ groupBy(keyFn: GroupKeyFn<PresentationSpec>): Map<string, PresentationSpec[]>;
70
+ /** Get unique tags from all presentations. */
71
+ getUniqueTags(): string[];
61
72
  }
62
73
  declare function jsonSchemaForPresentation(p: PresentationSpec): {
63
74
  framework: "react";
64
75
  componentKey: string;
65
- props: z.core.ZodStandardJSONSchemaPayload<_lssm_lib_schema89.TopLevelZodFromModel<_lssm_lib_schema89.SchemaModelFieldsAnyConfig<AnySchemaModel | _lssm_lib_schema89.AnyFieldType | _lssm_lib_schema89.AnyEnumType>>>;
76
+ props: z.core.ZodStandardJSONSchemaPayload<_lssm_lib_schema234.TopLevelZodFromModel<_lssm_lib_schema234.SchemaModelFieldsAnyConfig<_lssm_lib_schema234.AnyFieldType | _lssm_lib_schema234.AnyEnumType | AnySchemaModel>>>;
66
77
  meta: {
67
78
  readonly name: string;
68
79
  readonly version: number;
@@ -84,7 +95,7 @@ declare function jsonSchemaForPresentation(p: PresentationSpec): {
84
95
  kind: PresentationKind;
85
96
  } | {
86
97
  mimeType: string;
87
- model: z.core.ZodStandardJSONSchemaPayload<_lssm_lib_schema89.TopLevelZodFromModel<_lssm_lib_schema89.SchemaModelFieldsAnyConfig<AnySchemaModel | _lssm_lib_schema89.AnyFieldType | _lssm_lib_schema89.AnyEnumType>>>;
98
+ model: z.core.ZodStandardJSONSchemaPayload<_lssm_lib_schema234.TopLevelZodFromModel<_lssm_lib_schema234.SchemaModelFieldsAnyConfig<_lssm_lib_schema234.AnyFieldType | _lssm_lib_schema234.AnyEnumType | AnySchemaModel>>>;
88
99
  meta: {
89
100
  readonly name: string;
90
101
  readonly version: number;
@@ -1,3 +1,5 @@
1
+ import { __toCommonJS } from "./_virtual/rolldown_runtime.js";
2
+ import { init_registry_utils, registry_utils_exports } from "./registry-utils.js";
1
3
  import z from "zod";
2
4
 
3
5
  //#region src/presentations.ts
@@ -32,6 +34,29 @@ var PresentationRegistry = class {
32
34
  }
33
35
  return candidate;
34
36
  }
37
+ /** Filter presentations by criteria. */
38
+ filter(criteria) {
39
+ const { filterBy } = (init_registry_utils(), __toCommonJS(registry_utils_exports));
40
+ return filterBy(this.list(), criteria);
41
+ }
42
+ /** List presentations with specific tag. */
43
+ listByTag(tag) {
44
+ return this.list().filter((p) => p.meta.tags?.includes(tag));
45
+ }
46
+ /** List presentations by owner. */
47
+ listByOwner(owner) {
48
+ return this.list().filter((p) => p.meta.owners?.includes(owner));
49
+ }
50
+ /** Group presentations by key function. */
51
+ groupBy(keyFn) {
52
+ const { groupBy } = (init_registry_utils(), __toCommonJS(registry_utils_exports));
53
+ return groupBy(this.list(), keyFn);
54
+ }
55
+ /** Get unique tags from all presentations. */
56
+ getUniqueTags() {
57
+ const { getUniqueTags } = (init_registry_utils(), __toCommonJS(registry_utils_exports));
58
+ return getUniqueTags(this.list());
59
+ }
35
60
  };
36
61
  function jsonSchemaForPresentation(p) {
37
62
  const base = {
@@ -0,0 +1,107 @@
1
+ import { Stability } from "./ownership.js";
2
+
3
+ //#region src/registry-utils.d.ts
4
+
5
+ /**
6
+ * Filter criteria for registry items.
7
+ * All criteria are optional and combined with AND logic.
8
+ */
9
+ interface RegistryFilter {
10
+ /** Filter by tags (item must have at least one matching tag) */
11
+ tags?: string[];
12
+ /** Filter by owners (item must have at least one matching owner) */
13
+ owners?: string[];
14
+ /** Filter by stability levels */
15
+ stability?: Stability[];
16
+ /** Filter by domain (first segment of name) */
17
+ domain?: string;
18
+ /** Filter by name pattern (glob or regex) */
19
+ namePattern?: string;
20
+ }
21
+ /**
22
+ * Item with standard metadata for filtering.
23
+ */
24
+ interface FilterableItem {
25
+ meta: {
26
+ name?: string;
27
+ key?: string;
28
+ tags?: string[];
29
+ owners?: string[];
30
+ stability?: Stability;
31
+ domain?: string;
32
+ };
33
+ }
34
+ /**
35
+ * Grouping key function type.
36
+ */
37
+ type GroupKeyFn<T> = (item: T) => string;
38
+ /**
39
+ * Grouped items result.
40
+ */
41
+ interface GroupedItems<T> {
42
+ key: string;
43
+ items: T[];
44
+ }
45
+ /**
46
+ * Pre-built grouping strategies for common use cases.
47
+ */
48
+ declare const GroupingStrategies: {
49
+ /**
50
+ * Group by first tag.
51
+ */
52
+ byTag: <T extends FilterableItem>(item: T) => string;
53
+ /**
54
+ * Group by all tags (item appears in multiple groups).
55
+ */
56
+ byAllTags: <T extends FilterableItem>(item: T) => string[];
57
+ /**
58
+ * Group by first owner.
59
+ */
60
+ byOwner: <T extends FilterableItem>(item: T) => string;
61
+ /**
62
+ * Group by domain (first segment of name).
63
+ */
64
+ byDomain: <T extends FilterableItem>(item: T) => string;
65
+ /**
66
+ * Group by stability level.
67
+ */
68
+ byStability: <T extends FilterableItem>(item: T) => string;
69
+ /**
70
+ * Create URL path grouping strategy with configurable depth.
71
+ */
72
+ byUrlPath: (level: number) => (item: {
73
+ path?: string;
74
+ }) => string;
75
+ };
76
+ /**
77
+ * Filter items by criteria.
78
+ * All criteria are combined with AND logic.
79
+ */
80
+ declare function filterBy<T extends FilterableItem>(items: T[], filter: RegistryFilter): T[];
81
+ /**
82
+ * Group items by key function.
83
+ */
84
+ declare function groupBy<T>(items: T[], keyFn: GroupKeyFn<T>): Map<string, T[]>;
85
+ /**
86
+ * Group items by key function, returning array format.
87
+ */
88
+ declare function groupByToArray<T>(items: T[], keyFn: GroupKeyFn<T>): GroupedItems<T>[];
89
+ /**
90
+ * Group items where one item can belong to multiple groups.
91
+ * Useful for byAllTags grouping.
92
+ */
93
+ declare function groupByMultiple<T>(items: T[], keysFn: (item: T) => string[]): Map<string, T[]>;
94
+ /**
95
+ * Get unique tags from a collection of items.
96
+ */
97
+ declare function getUniqueTags<T extends FilterableItem>(items: T[]): string[];
98
+ /**
99
+ * Get unique owners from a collection of items.
100
+ */
101
+ declare function getUniqueOwners<T extends FilterableItem>(items: T[]): string[];
102
+ /**
103
+ * Get unique domains from a collection of items.
104
+ */
105
+ declare function getUniqueDomains<T extends FilterableItem>(items: T[]): string[];
106
+ //#endregion
107
+ export { FilterableItem, GroupKeyFn, GroupedItems, GroupingStrategies, RegistryFilter, filterBy, getUniqueDomains, getUniqueOwners, getUniqueTags, groupBy, groupByMultiple, groupByToArray };
@@ -0,0 +1,122 @@
1
+ import { __esmMin, __export } from "./_virtual/rolldown_runtime.js";
2
+
3
+ //#region src/registry-utils.ts
4
+ var registry_utils_exports = /* @__PURE__ */ __export({
5
+ GroupingStrategies: () => GroupingStrategies,
6
+ filterBy: () => filterBy,
7
+ getUniqueDomains: () => getUniqueDomains,
8
+ getUniqueOwners: () => getUniqueOwners,
9
+ getUniqueTags: () => getUniqueTags,
10
+ groupBy: () => groupBy,
11
+ groupByMultiple: () => groupByMultiple,
12
+ groupByToArray: () => groupByToArray
13
+ });
14
+ /**
15
+ * Filter items by criteria.
16
+ * All criteria are combined with AND logic.
17
+ */
18
+ function filterBy(items, filter) {
19
+ return items.filter((item) => {
20
+ if (filter.tags?.length) {
21
+ if (!filter.tags.some((tag) => item.meta.tags?.includes(tag))) return false;
22
+ }
23
+ if (filter.owners?.length) {
24
+ if (!filter.owners.some((owner) => item.meta.owners?.includes(owner))) return false;
25
+ }
26
+ if (filter.stability?.length) {
27
+ if (!filter.stability.includes(item.meta.stability ?? "stable")) return false;
28
+ }
29
+ if (filter.domain) {
30
+ if (GroupingStrategies.byDomain(item) !== filter.domain) return false;
31
+ }
32
+ if (filter.namePattern) {
33
+ const name = item.meta.name ?? item.meta.key ?? "";
34
+ const pattern = filter.namePattern.replace(/\*/g, ".*").replace(/\?/g, ".");
35
+ if (!new RegExp(`^${pattern}$`, "i").test(name)) return false;
36
+ }
37
+ return true;
38
+ });
39
+ }
40
+ /**
41
+ * Group items by key function.
42
+ */
43
+ function groupBy(items, keyFn) {
44
+ const groups = /* @__PURE__ */ new Map();
45
+ for (const item of items) {
46
+ const key = keyFn(item);
47
+ const existing = groups.get(key);
48
+ if (existing) existing.push(item);
49
+ else groups.set(key, [item]);
50
+ }
51
+ return groups;
52
+ }
53
+ /**
54
+ * Group items by key function, returning array format.
55
+ */
56
+ function groupByToArray(items, keyFn) {
57
+ const map = groupBy(items, keyFn);
58
+ return Array.from(map.entries()).map(([key, items$1]) => ({
59
+ key,
60
+ items: items$1
61
+ }));
62
+ }
63
+ /**
64
+ * Group items where one item can belong to multiple groups.
65
+ * Useful for byAllTags grouping.
66
+ */
67
+ function groupByMultiple(items, keysFn) {
68
+ const groups = /* @__PURE__ */ new Map();
69
+ for (const item of items) {
70
+ const keys = keysFn(item);
71
+ for (const key of keys) {
72
+ const existing = groups.get(key);
73
+ if (existing) existing.push(item);
74
+ else groups.set(key, [item]);
75
+ }
76
+ }
77
+ return groups;
78
+ }
79
+ /**
80
+ * Get unique tags from a collection of items.
81
+ */
82
+ function getUniqueTags(items) {
83
+ const tags = /* @__PURE__ */ new Set();
84
+ for (const item of items) for (const tag of item.meta.tags ?? []) tags.add(tag);
85
+ return Array.from(tags).sort();
86
+ }
87
+ /**
88
+ * Get unique owners from a collection of items.
89
+ */
90
+ function getUniqueOwners(items) {
91
+ const owners = /* @__PURE__ */ new Set();
92
+ for (const item of items) for (const owner of item.meta.owners ?? []) owners.add(owner);
93
+ return Array.from(owners).sort();
94
+ }
95
+ /**
96
+ * Get unique domains from a collection of items.
97
+ */
98
+ function getUniqueDomains(items) {
99
+ const domains = /* @__PURE__ */ new Set();
100
+ for (const item of items) domains.add(GroupingStrategies.byDomain(item));
101
+ return Array.from(domains).sort();
102
+ }
103
+ var GroupingStrategies;
104
+ var init_registry_utils = __esmMin(() => {
105
+ GroupingStrategies = {
106
+ byTag: (item) => item.meta.tags?.[0] ?? "untagged",
107
+ byAllTags: (item) => item.meta.tags?.length ? item.meta.tags : ["untagged"],
108
+ byOwner: (item) => item.meta.owners?.[0] ?? "unowned",
109
+ byDomain: (item) => {
110
+ return (item.meta.name ?? item.meta.key ?? "").split(".")[0] ?? "default";
111
+ },
112
+ byStability: (item) => item.meta.stability ?? "stable",
113
+ byUrlPath: (level) => (item) => {
114
+ if (!item.path) return "root";
115
+ return item.path.split("/").filter(Boolean).slice(0, level).join("/") || "root";
116
+ }
117
+ };
118
+ });
119
+
120
+ //#endregion
121
+ init_registry_utils();
122
+ export { GroupingStrategies, filterBy, getUniqueDomains, getUniqueOwners, getUniqueTags, groupBy, groupByMultiple, groupByToArray, init_registry_utils, registry_utils_exports };