@aventara/access 0.0.0-stage → 0.1.0-rc.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.
Files changed (240) hide show
  1. package/CHANGELOG.md +831 -0
  2. package/LICENSE +91 -0
  3. package/LICENSE-ADDITIONAL-PERMISSION.md +9 -0
  4. package/README.md +2439 -2
  5. package/dist/access/access-options.d.ts +66 -0
  6. package/dist/access/access-options.js +5 -0
  7. package/dist/access/access.error.d.ts +35 -0
  8. package/dist/access/access.error.js +11 -0
  9. package/dist/access/access.factory.d.ts +273 -0
  10. package/dist/access/access.factory.js +440 -0
  11. package/dist/access/better-auth.hardening.d.ts +120 -0
  12. package/dist/access/better-auth.hardening.js +420 -0
  13. package/dist/access/better-auth.loader.d.ts +67 -0
  14. package/dist/access/better-auth.loader.js +65 -0
  15. package/dist/access/better-auth.range.d.ts +9 -0
  16. package/dist/access/better-auth.range.js +28 -0
  17. package/dist/access/better-auth.require.d.ts +90 -0
  18. package/dist/access/better-auth.require.js +6 -0
  19. package/dist/access/better-auth.require.node.d.ts +7 -0
  20. package/dist/access/better-auth.require.node.js +52 -0
  21. package/dist/access/claims.mapper.d.ts +79 -0
  22. package/dist/access/claims.mapper.js +152 -0
  23. package/dist/access/key-set.cache.d.ts +10 -0
  24. package/dist/access/key-set.cache.js +63 -0
  25. package/dist/access/policies-block.checker.d.ts +64 -0
  26. package/dist/access/policies-block.checker.js +138 -0
  27. package/dist/access/principal.subject.d.ts +12 -0
  28. package/dist/access/principal.subject.js +60 -0
  29. package/dist/access/profile.policy.d.ts +74 -0
  30. package/dist/access/profile.policy.js +110 -0
  31. package/dist/access/request.state.d.ts +89 -0
  32. package/dist/access/request.state.js +196 -0
  33. package/dist/access/session.hooks.d.ts +114 -0
  34. package/dist/access/session.hooks.js +258 -0
  35. package/dist/access/token.verifier.d.ts +35 -0
  36. package/dist/access/token.verifier.js +69 -0
  37. package/dist/access-schema.d.ts +48 -0
  38. package/dist/access-schema.js +5 -0
  39. package/dist/access-warning.emitter.d.ts +2 -0
  40. package/dist/access-warning.emitter.js +20 -0
  41. package/dist/access.builder.d.ts +299 -0
  42. package/dist/access.builder.js +66 -0
  43. package/dist/access.engine.d.ts +142 -0
  44. package/dist/access.engine.js +470 -0
  45. package/dist/audit/audit-event.d.ts +135 -0
  46. package/dist/audit/audit-event.js +8 -0
  47. package/dist/audit/audit.log.d.ts +122 -0
  48. package/dist/audit/audit.log.js +345 -0
  49. package/dist/audit/audit.schema.d.ts +143 -0
  50. package/dist/audit/audit.schema.js +50 -0
  51. package/dist/auth/index.d.ts +12 -0
  52. package/dist/auth/index.js +2 -0
  53. package/dist/aventara-where.translator.d.ts +19 -0
  54. package/dist/aventara-where.translator.js +87 -0
  55. package/dist/beacon/beacon.check.d.ts +59 -0
  56. package/dist/beacon/beacon.check.js +128 -0
  57. package/dist/beacon/beacon.schema.d.ts +41 -0
  58. package/dist/beacon/beacon.schema.js +48 -0
  59. package/dist/beacon/beacon.store.d.ts +29 -0
  60. package/dist/beacon/beacon.store.js +78 -0
  61. package/dist/better-auth/access.client-plugin.d.ts +75 -0
  62. package/dist/better-auth/access.client-plugin.js +133 -0
  63. package/dist/better-auth/access.plugin.d.ts +164 -0
  64. package/dist/better-auth/access.plugin.js +348 -0
  65. package/dist/better-auth/access.provider.d.ts +78 -0
  66. package/dist/better-auth/access.provider.js +100 -0
  67. package/dist/better-auth/index.d.ts +7 -0
  68. package/dist/better-auth/index.js +4 -0
  69. package/dist/better-auth/organization.bridge.d.ts +66 -0
  70. package/dist/better-auth/organization.bridge.js +144 -0
  71. package/dist/canonical-json.writer.d.ts +12 -0
  72. package/dist/canonical-json.writer.js +30 -0
  73. package/dist/cli/avaccess.bin.d.ts +2 -0
  74. package/dist/cli/avaccess.bin.js +26 -0
  75. package/dist/cli/avaccess.program.d.ts +15 -0
  76. package/dist/cli/avaccess.program.js +166 -0
  77. package/dist/cli/beacon-pins.file.d.ts +14 -0
  78. package/dist/cli/beacon-pins.file.js +62 -0
  79. package/dist/cli/beacon.loader.d.ts +20 -0
  80. package/dist/cli/beacon.loader.js +71 -0
  81. package/dist/cli/cli.context.d.ts +49 -0
  82. package/dist/cli/cli.context.js +66 -0
  83. package/dist/cli/diff.command.d.ts +2 -0
  84. package/dist/cli/diff.command.js +66 -0
  85. package/dist/cli/generate.command.d.ts +2 -0
  86. package/dist/cli/generate.command.js +82 -0
  87. package/dist/cli/keys.command.d.ts +2 -0
  88. package/dist/cli/keys.command.js +96 -0
  89. package/dist/cli/lock.file.d.ts +31 -0
  90. package/dist/cli/lock.file.js +181 -0
  91. package/dist/cli/module.loader.d.ts +13 -0
  92. package/dist/cli/module.loader.js +63 -0
  93. package/dist/cli/policies.diff.d.ts +16 -0
  94. package/dist/cli/policies.diff.js +83 -0
  95. package/dist/cli/pull.command.d.ts +2 -0
  96. package/dist/cli/pull.command.js +234 -0
  97. package/dist/cli/push.command.d.ts +2 -0
  98. package/dist/cli/push.command.js +59 -0
  99. package/dist/cli/registry.client.d.ts +63 -0
  100. package/dist/cli/registry.client.js +287 -0
  101. package/dist/cli/schema.command.d.ts +2 -0
  102. package/dist/cli/schema.command.js +60 -0
  103. package/dist/cli/serve.command.d.ts +6 -0
  104. package/dist/cli/serve.command.js +200 -0
  105. package/dist/cli/status.command.d.ts +2 -0
  106. package/dist/cli/status.command.js +31 -0
  107. package/dist/cli/translator.flag.d.ts +6 -0
  108. package/dist/cli/translator.flag.js +24 -0
  109. package/dist/cli/verify.command.d.ts +2 -0
  110. package/dist/cli/verify.command.js +40 -0
  111. package/dist/client/access-client.factory.d.ts +92 -0
  112. package/dist/client/access-client.factory.js +269 -0
  113. package/dist/client/access-verbs.schema.d.ts +66 -0
  114. package/dist/client/access-verbs.schema.js +159 -0
  115. package/dist/client/verb-rate.limiter.d.ts +116 -0
  116. package/dist/client/verb-rate.limiter.js +358 -0
  117. package/dist/foreign/foreign-facts.d.ts +30 -0
  118. package/dist/foreign/foreign-facts.js +75 -0
  119. package/dist/foreign/foreign.merger.d.ts +10 -0
  120. package/dist/foreign/foreign.merger.js +52 -0
  121. package/dist/foreign-references.check.d.ts +12 -0
  122. package/dist/foreign-references.check.js +134 -0
  123. package/dist/generator/client.emitter.d.ts +28 -0
  124. package/dist/generator/client.emitter.js +411 -0
  125. package/dist/generator/copied-modules.reader.d.ts +14 -0
  126. package/dist/generator/copied-modules.reader.js +80 -0
  127. package/dist/generator/namespace.facts.d.ts +28 -0
  128. package/dist/generator/namespace.facts.js +32 -0
  129. package/dist/generator/orm.translator.d.ts +48 -0
  130. package/dist/generator/orm.translator.js +29 -0
  131. package/dist/generator/prisma7/prisma-schema.reader.d.ts +9 -0
  132. package/dist/generator/prisma7/prisma-schema.reader.js +394 -0
  133. package/dist/generator/prisma7/prisma-where.translator.d.ts +72 -0
  134. package/dist/generator/prisma7/prisma-where.translator.js +136 -0
  135. package/dist/generator/prisma7/prisma7.translator.d.ts +2 -0
  136. package/dist/generator/prisma7/prisma7.translator.js +87 -0
  137. package/dist/generator/schema.emitter.d.ts +14 -0
  138. package/dist/generator/schema.emitter.js +23 -0
  139. package/dist/generator/tsconfig.reader.d.ts +44 -0
  140. package/dist/generator/tsconfig.reader.js +110 -0
  141. package/dist/generator/typescript-literal.writer.d.ts +5 -0
  142. package/dist/generator/typescript-literal.writer.js +42 -0
  143. package/dist/guardrails/guardrails-contract.d.ts +45 -0
  144. package/dist/guardrails/guardrails-contract.js +12 -0
  145. package/dist/guardrails/guardrails.builder.d.ts +48 -0
  146. package/dist/guardrails/guardrails.builder.js +32 -0
  147. package/dist/guardrails/guardrails.compiler.d.ts +10 -0
  148. package/dist/guardrails/guardrails.compiler.js +254 -0
  149. package/dist/guardrails/guardrails.composer.d.ts +7 -0
  150. package/dist/guardrails/guardrails.composer.js +95 -0
  151. package/dist/guardrails/guardrails.hash.d.ts +10 -0
  152. package/dist/guardrails/guardrails.hash.js +38 -0
  153. package/dist/index.d.ts +16 -0
  154. package/dist/index.js +6 -0
  155. package/dist/kiosk/kiosk-verbs.schema.d.ts +19 -0
  156. package/dist/kiosk/kiosk-verbs.schema.js +61 -0
  157. package/dist/kiosk/kiosk.plugin.d.ts +217 -0
  158. package/dist/kiosk/kiosk.plugin.js +877 -0
  159. package/dist/kiosk/kiosk.schema.d.ts +176 -0
  160. package/dist/kiosk/kiosk.schema.js +101 -0
  161. package/dist/kiosk/kiosk.store.d.ts +171 -0
  162. package/dist/kiosk/kiosk.store.js +478 -0
  163. package/dist/kiosk/lan-range.policy.d.ts +31 -0
  164. package/dist/kiosk/lan-range.policy.js +113 -0
  165. package/dist/kiosk/pin.policy.d.ts +9 -0
  166. package/dist/kiosk/pin.policy.js +143 -0
  167. package/dist/kiosk/session-use.marker.d.ts +4 -0
  168. package/dist/kiosk/session-use.marker.js +16 -0
  169. package/dist/lock/lock-contract.d.ts +38 -0
  170. package/dist/lock/lock-contract.js +67 -0
  171. package/dist/lock/lock.verifier.d.ts +27 -0
  172. package/dist/lock/lock.verifier.js +62 -0
  173. package/dist/mcp/agent-scope.gate.d.ts +11 -0
  174. package/dist/mcp/agent-scope.gate.js +75 -0
  175. package/dist/mcp/agent.grant.d.ts +36 -0
  176. package/dist/mcp/agent.grant.js +92 -0
  177. package/dist/mcp/mcp-options.d.ts +60 -0
  178. package/dist/mcp/mcp-options.js +72 -0
  179. package/dist/oauth/access-token.verifier.d.ts +66 -0
  180. package/dist/oauth/access-token.verifier.js +201 -0
  181. package/dist/oauth/oauth-provider.hardening.d.ts +62 -0
  182. package/dist/oauth/oauth-provider.hardening.js +261 -0
  183. package/dist/passwords/argon2id.hasher.d.ts +97 -0
  184. package/dist/passwords/argon2id.hasher.js +256 -0
  185. package/dist/passwords/node-rs-argon2.adapter.d.ts +25 -0
  186. package/dist/passwords/node-rs-argon2.adapter.js +42 -0
  187. package/dist/passwords/passwords.options.d.ts +79 -0
  188. package/dist/passwords/passwords.options.js +212 -0
  189. package/dist/policies-contract.d.ts +192 -0
  190. package/dist/policies-contract.js +8 -0
  191. package/dist/policies.compiler.d.ts +36 -0
  192. package/dist/policies.compiler.js +1358 -0
  193. package/dist/policies.decider.d.ts +103 -0
  194. package/dist/policies.decider.js +382 -0
  195. package/dist/policies.hash.d.ts +10 -0
  196. package/dist/policies.hash.js +53 -0
  197. package/dist/predicate.evaluator.d.ts +62 -0
  198. package/dist/predicate.evaluator.js +378 -0
  199. package/dist/random-secret.generator.d.ts +2 -0
  200. package/dist/random-secret.generator.js +15 -0
  201. package/dist/reference-reads.check.d.ts +12 -0
  202. package/dist/reference-reads.check.js +148 -0
  203. package/dist/registry/access.registry.d.ts +173 -0
  204. package/dist/registry/access.registry.js +865 -0
  205. package/dist/registry/beacon.ledger.d.ts +30 -0
  206. package/dist/registry/beacon.ledger.js +93 -0
  207. package/dist/registry/ownership.check.d.ts +54 -0
  208. package/dist/registry/ownership.check.js +215 -0
  209. package/dist/registry/registry.endpoints.d.ts +50 -0
  210. package/dist/registry/registry.endpoints.js +193 -0
  211. package/dist/registry/registry.key.d.ts +7 -0
  212. package/dist/registry/registry.key.js +13 -0
  213. package/dist/registry/registry.options.d.ts +13 -0
  214. package/dist/registry/registry.options.js +28 -0
  215. package/dist/registry/registry.refusal.d.ts +6 -0
  216. package/dist/registry/registry.refusal.js +11 -0
  217. package/dist/registry/registry.schema.d.ts +238 -0
  218. package/dist/registry/registry.schema.js +127 -0
  219. package/dist/resources/auth-tables.catalog.d.ts +91 -0
  220. package/dist/resources/auth-tables.catalog.js +102 -0
  221. package/dist/resources/auth-tables.guard.d.ts +95 -0
  222. package/dist/resources/auth-tables.guard.js +405 -0
  223. package/dist/scope.resolver.d.ts +138 -0
  224. package/dist/scope.resolver.js +512 -0
  225. package/dist/sha256.digest.d.ts +2 -0
  226. package/dist/sha256.digest.js +81 -0
  227. package/dist/standalone/access.server.d.ts +41 -0
  228. package/dist/standalone/access.server.js +301 -0
  229. package/dist/standalone/index.d.ts +1 -0
  230. package/dist/standalone/index.js +1 -0
  231. package/package.json +101 -3
  232. package/src/aventara-where.translator.ts +116 -0
  233. package/src/beacon/beacon.check.ts +204 -0
  234. package/src/canonical-json.writer.ts +51 -0
  235. package/src/generator/prisma7/prisma-where.translator.ts +241 -0
  236. package/src/policies-contract.ts +184 -0
  237. package/src/policies.decider.ts +650 -0
  238. package/src/predicate.evaluator.ts +574 -0
  239. package/src/scope.resolver.ts +791 -0
  240. package/src/sha256.digest.ts +85 -0
@@ -0,0 +1,173 @@
1
+ import type { AccessGuardrails } from "../guardrails/guardrails-contract.js";
2
+ import type { AccessPolicies, AccessSchemaResourceFacts } from "../policies-contract.js";
3
+ import { type OwnershipMode } from "./ownership.check.js";
4
+ import { type AccessKeyKind } from "./registry.key.js";
5
+ export { AccessRegistryRefusal } from "./registry.refusal.js";
6
+ /** A condition on one field, in Better Auth's adapter form: equal to `value`, or `in` its list. */
7
+ type Where = {
8
+ readonly field: string;
9
+ readonly value: string;
10
+ } | {
11
+ readonly field: string;
12
+ readonly operator: "in";
13
+ readonly value: string[];
14
+ };
15
+ /**
16
+ * The part of Better Auth's database adapter the registry uses: each call goes
17
+ * through whatever adapter the app gave Better Auth.
18
+ */
19
+ export type RegistryAdapter = {
20
+ create<T>(input: {
21
+ model: string;
22
+ data: {
23
+ readonly [field: string]: unknown;
24
+ };
25
+ }): Promise<T>;
26
+ findOne<T>(input: {
27
+ model: string;
28
+ where: Where[];
29
+ }): Promise<T | null>;
30
+ findMany<T>(input: {
31
+ model: string;
32
+ where?: Where[];
33
+ limit?: number;
34
+ sortBy?: {
35
+ field: string;
36
+ direction: "asc" | "desc";
37
+ };
38
+ }): Promise<T[]>;
39
+ update<T>(input: {
40
+ model: string;
41
+ where: Where[];
42
+ update: {
43
+ readonly [field: string]: unknown;
44
+ };
45
+ }): Promise<T | null>;
46
+ delete(input: {
47
+ model: string;
48
+ where: Where[];
49
+ }): Promise<void>;
50
+ transaction<R>(run: (adapter: RegistryAdapter) => Promise<R>): Promise<R>;
51
+ };
52
+ /** The largest policies file a push stores, in bytes of its JSON text: 1 MiB. */
53
+ export declare const MAX_POLICIES_BYTES = 1048576;
54
+ /** A namespace's two keys, as the call that issues them answers: the only time they are seen. */
55
+ export type AccessNamespaceKeys = {
56
+ readonly namespace: string;
57
+ readonly push: string;
58
+ readonly pull: string;
59
+ };
60
+ /** What a push answers: the file's hash, and whether this push stored it (`false`: the registry had it). */
61
+ export type AccessPushResult = {
62
+ readonly hash: string;
63
+ readonly created: boolean;
64
+ };
65
+ /** A stored revision, as a read answers it: a namespace's policies file, or the org's guardrails file. */
66
+ type AccessRevision<File = AccessPolicies> = {
67
+ readonly hash: string;
68
+ readonly format: string;
69
+ readonly createdAt: Date;
70
+ readonly file: File;
71
+ };
72
+ /**
73
+ * What a namespace reads of another one it reads as foreign: the hash of the
74
+ * beacon the owner pushed (`null`: none yet), and the owner's schema entry of each
75
+ * Resource asked for, from its current file.
76
+ */
77
+ type AccessForeignRead = {
78
+ readonly owner: string;
79
+ readonly beacon: string | null;
80
+ readonly resources: {
81
+ readonly [resource: string]: AccessSchemaResourceFacts;
82
+ };
83
+ };
84
+ /** A namespace, as a read answers it: its name and its current revision's hash. */
85
+ type AccessNamespaceInfo = {
86
+ readonly name: string;
87
+ readonly createdAt: Date;
88
+ readonly head: string | null;
89
+ /** The hash of the namespace's current beacon; `null` when it has pushed none. */
90
+ readonly beacon: string | null;
91
+ };
92
+ /**
93
+ * The operator's side of the registry, on an instance built with
94
+ * `registry: { enabled: true }`. It runs in the server's own process and takes no
95
+ * key: whoever holds the instance is the operator.
96
+ */
97
+ export type AccessRegistry = {
98
+ /**
99
+ * Adds a namespace and issues its push key and its read-only pull key. The keys
100
+ * are in this answer only; the registry keeps their hashes.
101
+ */
102
+ createNamespace(name: string): Promise<AccessNamespaceKeys>;
103
+ /** Issues a new key of `kind`; from now on the namespace's previous one is refused. */
104
+ rotateKey(namespace: string, kind: AccessKeyKind): Promise<string>;
105
+ /** Refuses the namespace's key of `kind` from now on, until `rotateKey` issues another. */
106
+ revokeKey(namespace: string, kind: AccessKeyKind): Promise<void>;
107
+ /**
108
+ * Pushes the org's guardrails file (`defineGuardrails(...).contract()`, format
109
+ * `aventara-access/guardrails@1`), which every namespace's key then reads. Each
110
+ * namespace it names a Resource list for must be one the registry has.
111
+ */
112
+ pushGuardrails(file: AccessGuardrails): Promise<AccessPushResult>;
113
+ /**
114
+ * Gives `resource` to `namespace`: from now on only that namespace's file names
115
+ * it as its own, and another namespace's push that does is refused, whoever named
116
+ * it first. With `ownership: "assigned"` this is the only way a Resource gets an
117
+ * owner. A namespace whose current file names the Resource as its own keeps that
118
+ * revision; its next push is checked.
119
+ */
120
+ assignResource(resource: string, namespace: string): Promise<void>;
121
+ /**
122
+ * Takes `resource` from its owner: with `ownership: "first-push"` the next push
123
+ * that names it as its own claims it; with `"assigned"` no push may until it is
124
+ * assigned again.
125
+ */
126
+ releaseResource(resource: string): Promise<void>;
127
+ };
128
+ /** How the registry decides who owns a Resource (the `registry` block's `ownership`). */
129
+ export type RegistrySettings = {
130
+ readonly ownership: OwnershipMode;
131
+ };
132
+ /** The registry over the adapter `adapterOf` resolves (Better Auth's, once it is built). */
133
+ export declare const createRegistry: (adapterOf: () => Promise<RegistryAdapter>, settings?: RegistrySettings) => {
134
+ operator: AccessRegistry;
135
+ /**
136
+ * The namespace a key belongs to, and its kind: what `avaccess pull` reads when
137
+ * the project has no lock yet. A key that is not one of this registry's, or was
138
+ * revoked, is refused as a read with it would be.
139
+ */
140
+ keyOwner: (key: string | undefined) => Promise<{
141
+ readonly namespace: string;
142
+ readonly kind: AccessKeyKind;
143
+ }>;
144
+ /**
145
+ * Whether `key` is `namespace`'s push key: the refusal a push would get
146
+ * (`ACCESS_KEY_REFUSED`, logged as a push's), or nothing. The routes' mounts ask
147
+ * it before a push's body is read.
148
+ */
149
+ admitPush: (namespace: string, key: string | undefined) => Promise<void>;
150
+ /** Pushes `body` as `namespace`'s file, with that namespace's push key. */
151
+ push: (namespace: string, key: string | undefined, body: unknown) => Promise<AccessPushResult>;
152
+ namespace: (namespace: string, key: string | undefined) => Promise<AccessNamespaceInfo>;
153
+ revisions: (namespace: string, key: string | undefined) => Promise<{
154
+ hash: string;
155
+ format: string;
156
+ createdAt: Date;
157
+ }[]>;
158
+ revision: (namespace: string, key: string | undefined, hash: string) => Promise<AccessRevision<AccessPolicies> | null>;
159
+ head: (namespace: string, key: string | undefined) => Promise<AccessRevision<AccessPolicies> | null>;
160
+ /**
161
+ * What the namespace reads of `owner`: of the Resources its current file reads
162
+ * as `owner`'s (`{ "foreign": "<owner>" }`), `owner`'s schema entry of each one
163
+ * `resources` names, and the hash of the beacon `owner` pushed. Anything else
164
+ * (an owner the file does not read, a Resource it does not read as that
165
+ * owner's, an owner that does not own it or has no file describing it) gets one
166
+ * and the same refusal, which tells nothing of who owns what. Every read is
167
+ * logged with its key.
168
+ */
169
+ foreign: (namespace: string, key: string | undefined, owner: string, resources: readonly string[]) => Promise<AccessForeignRead>;
170
+ guardrails: (namespace: string, key: string | undefined) => Promise<AccessRevision<AccessGuardrails> | null>;
171
+ };
172
+ /** The registry `createRegistry` builds. */
173
+ export type Registry = ReturnType<typeof createRegistry>;