@eloxiv/cli 0.0.0-stage → 0.1.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.
- package/LICENSE +21 -0
- package/README.md +12 -2
- package/dist/AgentSkills.d.ts +51 -0
- package/dist/AgentSkills.d.ts.map +1 -0
- package/dist/AgentSkills.js +264 -0
- package/dist/AgentSkills.js.map +1 -0
- package/dist/AgentWeb.d.ts +83 -0
- package/dist/AgentWeb.d.ts.map +1 -0
- package/dist/AgentWeb.js +436 -0
- package/dist/AgentWeb.js.map +1 -0
- package/dist/App.d.ts +213 -0
- package/dist/App.d.ts.map +1 -0
- package/dist/App.js +357 -0
- package/dist/App.js.map +1 -0
- package/dist/Blueprint.d.ts +47 -0
- package/dist/Blueprint.d.ts.map +1 -0
- package/dist/Blueprint.js +241 -0
- package/dist/Blueprint.js.map +1 -0
- package/dist/Brand.d.ts +42 -0
- package/dist/Brand.d.ts.map +1 -0
- package/dist/Brand.js +370 -0
- package/dist/Brand.js.map +1 -0
- package/dist/Changelog.d.ts +22 -0
- package/dist/Changelog.d.ts.map +1 -0
- package/dist/Changelog.js +117 -0
- package/dist/Changelog.js.map +1 -0
- package/dist/Cli.d.ts +17 -0
- package/dist/Cli.d.ts.map +1 -0
- package/dist/Cli.js +810 -0
- package/dist/Cli.js.map +1 -0
- package/dist/DbAdmin.d.ts +18 -0
- package/dist/DbAdmin.d.ts.map +1 -0
- package/dist/DbAdmin.js +91 -0
- package/dist/DbAdmin.js.map +1 -0
- package/dist/Dependencies.d.ts +53 -0
- package/dist/Dependencies.d.ts.map +1 -0
- package/dist/Dependencies.js +132 -0
- package/dist/Dependencies.js.map +1 -0
- package/dist/Deploy.d.ts +39 -0
- package/dist/Deploy.d.ts.map +1 -0
- package/dist/Deploy.js +458 -0
- package/dist/Deploy.js.map +1 -0
- package/dist/Docs.d.ts +71 -0
- package/dist/Docs.d.ts.map +1 -0
- package/dist/Docs.js +240 -0
- package/dist/Docs.js.map +1 -0
- package/dist/Doctor.d.ts +56 -0
- package/dist/Doctor.d.ts.map +1 -0
- package/dist/Doctor.js +368 -0
- package/dist/Doctor.js.map +1 -0
- package/dist/Dossier.d.ts +23 -0
- package/dist/Dossier.d.ts.map +1 -0
- package/dist/Dossier.js +92 -0
- package/dist/Dossier.js.map +1 -0
- package/dist/Emit.d.ts +26 -0
- package/dist/Emit.d.ts.map +1 -0
- package/dist/Emit.js +51 -0
- package/dist/Emit.js.map +1 -0
- package/dist/Errors.d.ts +26 -0
- package/dist/Errors.d.ts.map +1 -0
- package/dist/Errors.js +17 -0
- package/dist/Errors.js.map +1 -0
- package/dist/Evals.d.ts +52 -0
- package/dist/Evals.d.ts.map +1 -0
- package/dist/Evals.js +126 -0
- package/dist/Evals.js.map +1 -0
- package/dist/Files.d.ts +47 -0
- package/dist/Files.d.ts.map +1 -0
- package/dist/Files.js +145 -0
- package/dist/Files.js.map +1 -0
- package/dist/Generate.d.ts +80 -0
- package/dist/Generate.d.ts.map +1 -0
- package/dist/Generate.js +310 -0
- package/dist/Generate.js.map +1 -0
- package/dist/Guards.d.ts +45 -0
- package/dist/Guards.d.ts.map +1 -0
- package/dist/Guards.js +530 -0
- package/dist/Guards.js.map +1 -0
- package/dist/Inspect.d.ts +125 -0
- package/dist/Inspect.d.ts.map +1 -0
- package/dist/Inspect.js +270 -0
- package/dist/Inspect.js.map +1 -0
- package/dist/Keychain.d.ts +57 -0
- package/dist/Keychain.d.ts.map +1 -0
- package/dist/Keychain.js +73 -0
- package/dist/Keychain.js.map +1 -0
- package/dist/Lock.d.ts +13 -0
- package/dist/Lock.d.ts.map +1 -0
- package/dist/Lock.js +145 -0
- package/dist/Lock.js.map +1 -0
- package/dist/Mcp.d.ts +91 -0
- package/dist/Mcp.d.ts.map +1 -0
- package/dist/Mcp.js +128 -0
- package/dist/Mcp.js.map +1 -0
- package/dist/Merge.d.ts +18 -0
- package/dist/Merge.d.ts.map +1 -0
- package/dist/Merge.js +43 -0
- package/dist/Merge.js.map +1 -0
- package/dist/Migrate.d.ts +78 -0
- package/dist/Migrate.d.ts.map +1 -0
- package/dist/Migrate.js +288 -0
- package/dist/Migrate.js.map +1 -0
- package/dist/Plugins.d.ts +36 -0
- package/dist/Plugins.d.ts.map +1 -0
- package/dist/Plugins.js +304 -0
- package/dist/Plugins.js.map +1 -0
- package/dist/Postgres.d.ts +73 -0
- package/dist/Postgres.d.ts.map +1 -0
- package/dist/Postgres.js +294 -0
- package/dist/Postgres.js.map +1 -0
- package/dist/Publish.d.ts +23 -0
- package/dist/Publish.d.ts.map +1 -0
- package/dist/Publish.js +59 -0
- package/dist/Publish.js.map +1 -0
- package/dist/Registry.d.ts +539 -0
- package/dist/Registry.d.ts.map +1 -0
- package/dist/Registry.js +340 -0
- package/dist/Registry.js.map +1 -0
- package/dist/Remote.d.ts +90 -0
- package/dist/Remote.d.ts.map +1 -0
- package/dist/Remote.js +1006 -0
- package/dist/Remote.js.map +1 -0
- package/dist/Run.d.ts +120 -0
- package/dist/Run.d.ts.map +1 -0
- package/dist/Run.js +477 -0
- package/dist/Run.js.map +1 -0
- package/dist/SyncGen.d.ts +118 -0
- package/dist/SyncGen.d.ts.map +1 -0
- package/dist/SyncGen.js +392 -0
- package/dist/SyncGen.js.map +1 -0
- package/dist/Update.d.ts +301 -0
- package/dist/Update.d.ts.map +1 -0
- package/dist/Update.js +627 -0
- package/dist/Update.js.map +1 -0
- package/dist/bin.d.ts +3 -0
- package/dist/bin.d.ts.map +1 -0
- package/dist/bin.js +42 -0
- package/dist/bin.js.map +1 -0
- package/dist/docs/backlog.md +56 -0
- package/dist/docs/ci.md +277 -0
- package/dist/docs/cli.md +696 -0
- package/dist/docs/connectors/google.md +115 -0
- package/dist/docs/connectors/http-openapi.md +7 -0
- package/dist/docs/connectors/mcp.md +8 -0
- package/dist/docs/connectors/microsoft-graph.md +75 -0
- package/dist/docs/connectors/openai.md +25 -0
- package/dist/docs/connectors/slack.md +162 -0
- package/dist/docs/connectors/workos.md +39 -0
- package/dist/docs/contracts/README.md +173 -0
- package/dist/docs/contracts/action-consent.md +92 -0
- package/dist/docs/contracts/action-registry.md +85 -0
- package/dist/docs/contracts/actor.md +100 -0
- package/dist/docs/contracts/agent-resources.md +90 -0
- package/dist/docs/contracts/agent-runtime.md +257 -0
- package/dist/docs/contracts/approvals.md +126 -0
- package/dist/docs/contracts/audit.md +75 -0
- package/dist/docs/contracts/auth-provider.md +74 -0
- package/dist/docs/contracts/calendar-provider.md +46 -0
- package/dist/docs/contracts/client-sdk.md +245 -0
- package/dist/docs/contracts/collab-document.md +151 -0
- package/dist/docs/contracts/command.md +44 -0
- package/dist/docs/contracts/connections.md +235 -0
- package/dist/docs/contracts/context-accounting.md +50 -0
- package/dist/docs/contracts/daemon.md +243 -0
- package/dist/docs/contracts/db-tx.md +53 -0
- package/dist/docs/contracts/delegation.md +68 -0
- package/dist/docs/contracts/device-control.md +103 -0
- package/dist/docs/contracts/directory-provider.md +36 -0
- package/dist/docs/contracts/directory.md +161 -0
- package/dist/docs/contracts/document-source.md +33 -0
- package/dist/docs/contracts/files.md +115 -0
- package/dist/docs/contracts/flags.md +83 -0
- package/dist/docs/contracts/host.md +68 -0
- package/dist/docs/contracts/http-api.md +43 -0
- package/dist/docs/contracts/ingestion.md +130 -0
- package/dist/docs/contracts/ingress.md +141 -0
- package/dist/docs/contracts/invocation.md +260 -0
- package/dist/docs/contracts/local-client.md +110 -0
- package/dist/docs/contracts/locale.md +56 -0
- package/dist/docs/contracts/machine-identity.md +117 -0
- package/dist/docs/contracts/mail-provider.md +49 -0
- package/dist/docs/contracts/memory.md +53 -0
- package/dist/docs/contracts/messaging.md +40 -0
- package/dist/docs/contracts/metering.md +139 -0
- package/dist/docs/contracts/model-provider.md +84 -0
- package/dist/docs/contracts/module-manifest.md +213 -0
- package/dist/docs/contracts/notification-channel.md +90 -0
- package/dist/docs/contracts/notifications.md +123 -0
- package/dist/docs/contracts/outbox.md +80 -0
- package/dist/docs/contracts/privacy.md +110 -0
- package/dist/docs/contracts/progress.md +52 -0
- package/dist/docs/contracts/query-surface.md +108 -0
- package/dist/docs/contracts/readiness.md +63 -0
- package/dist/docs/contracts/release.md +142 -0
- package/dist/docs/contracts/result-rendering.md +61 -0
- package/dist/docs/contracts/sandbox.md +186 -0
- package/dist/docs/contracts/scheduler.md +148 -0
- package/dist/docs/contracts/screen-context.md +81 -0
- package/dist/docs/contracts/search.md +120 -0
- package/dist/docs/contracts/secrets.md +74 -0
- package/dist/docs/contracts/settings.md +109 -0
- package/dist/docs/contracts/sharing.md +77 -0
- package/dist/docs/contracts/slot.md +48 -0
- package/dist/docs/contracts/space.md +67 -0
- package/dist/docs/contracts/storage-adapter.md +45 -0
- package/dist/docs/contracts/storage-backend.md +56 -0
- package/dist/docs/contracts/sync.md +213 -0
- package/dist/docs/contracts/telemetry.md +80 -0
- package/dist/docs/contracts/theme-tokens.md +50 -0
- package/dist/docs/contracts/tool-source.md +58 -0
- package/dist/docs/contracts/versioning.md +99 -0
- package/dist/docs/contracts/view.md +65 -0
- package/dist/docs/contracts/work-items.md +99 -0
- package/dist/docs/contracts/workflow.md +82 -0
- package/dist/docs/decisions.md +163 -0
- package/dist/docs/example-app.md +192 -0
- package/dist/docs/getting-started.md +927 -0
- package/dist/docs/goal.md +54 -0
- package/dist/docs/parity.md +29 -0
- package/dist/docs/performance.md +129 -0
- package/dist/docs/registry/README.md +74 -0
- package/dist/docs/registry/app.md +38 -0
- package/dist/docs/registry/approvals-ui-foldkit.md +28 -0
- package/dist/docs/registry/calendar-ui-foldkit.md +27 -0
- package/dist/docs/registry/calendar.md +35 -0
- package/dist/docs/registry/chat-ui-foldkit.md +30 -0
- package/dist/docs/registry/desktop-rune.md +50 -0
- package/dist/docs/registry/desktop.md +32 -0
- package/dist/docs/registry/eloxiv-action.md +25 -0
- package/dist/docs/registry/eloxiv-connector.md +25 -0
- package/dist/docs/registry/eloxiv-module.md +25 -0
- package/dist/docs/registry/eloxiv-policy.md +25 -0
- package/dist/docs/registry/eloxiv-view.md +25 -0
- package/dist/docs/registry/hello-ui-foldkit.md +29 -0
- package/dist/docs/registry/hello.md +39 -0
- package/dist/docs/registry/home-ui-foldkit.md +27 -0
- package/dist/docs/registry/home.md +29 -0
- package/dist/docs/registry/inbox-ui-foldkit.md +27 -0
- package/dist/docs/registry/mail-ui-foldkit.md +27 -0
- package/dist/docs/registry/mail.md +34 -0
- package/dist/docs/registry/meeting-prep.md +26 -0
- package/dist/docs/registry/members-ui-foldkit.md +28 -0
- package/dist/docs/registry/mobile.md +37 -0
- package/dist/docs/registry/notes-ui-foldkit.md +27 -0
- package/dist/docs/registry/notes.md +26 -0
- package/dist/docs/registry/people-ui-foldkit.md +28 -0
- package/dist/docs/registry/people.md +38 -0
- package/dist/docs/registry/shell-foldkit.md +35 -0
- package/dist/docs/registry/theme.md +25 -0
- package/dist/docs/registry/ui-conformance.md +30 -0
- package/dist/docs/release.md +100 -0
- package/dist/docs/scaffold.md +826 -0
- package/dist/docs/security/threat-model.md +299 -0
- package/dist/docs/upstream/zero-cache-socket-handoff.md +105 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/package.json +48 -3
- package/src/AgentSkills.ts +329 -0
- package/src/AgentWeb.ts +507 -0
- package/src/App.ts +435 -0
- package/src/Blueprint.ts +276 -0
- package/src/Brand.ts +415 -0
- package/src/Changelog.ts +136 -0
- package/src/Cli.ts +1458 -0
- package/src/DbAdmin.ts +115 -0
- package/src/Dependencies.ts +170 -0
- package/src/Deploy.ts +563 -0
- package/src/Docs.ts +309 -0
- package/src/Doctor.ts +424 -0
- package/src/Dossier.ts +148 -0
- package/src/Emit.ts +68 -0
- package/src/Errors.ts +18 -0
- package/src/Evals.ts +153 -0
- package/src/Files.ts +152 -0
- package/src/Generate.ts +402 -0
- package/src/Guards.ts +541 -0
- package/src/Inspect.ts +358 -0
- package/src/Keychain.ts +107 -0
- package/src/Lock.ts +174 -0
- package/src/Mcp.ts +159 -0
- package/src/Merge.ts +70 -0
- package/src/Migrate.ts +331 -0
- package/src/Plugins.ts +347 -0
- package/src/Postgres.ts +353 -0
- package/src/Publish.ts +64 -0
- package/src/Registry.ts +405 -0
- package/src/Remote.ts +1158 -0
- package/src/Run.ts +541 -0
- package/src/SyncGen.ts +570 -0
- package/src/Update.ts +873 -0
- package/src/bin.ts +46 -0
- package/src/index.ts +7 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# DirectoryProvider
|
|
2
|
+
|
|
3
|
+
An organisation's people and groups at a provider (Entra ID through Microsoft Graph, the Google Workspace Admin SDK), over a kernel [Connection](connections.md). Read-only: the kernel's own [Directory](directory.md) is the source of memberships and roles; a registry People module can sync from a DirectoryProvider.
|
|
4
|
+
|
|
5
|
+
- Kind: capability. Version 1.0.0.
|
|
6
|
+
- Schema: [`packages/contracts/schema/contracts/DirectoryProvider.json`](../../packages/contracts/schema/contracts/DirectoryProvider.json) (source [`DirectoryProvider.ts`](../../packages/contracts/src/contracts/DirectoryProvider.ts)).
|
|
7
|
+
- Implementations: the [`microsoft-graph`](../connectors/microsoft-graph.md) and [`google`](../connectors/google.md) connectors.
|
|
8
|
+
- Kit: `@eloxiv/testing/conformance/DirectoryProvider` ([source](../../packages/testing/src/conformance/DirectoryProvider.ts)), run by the connector tests in [`registry/test`](../../registry/test).
|
|
9
|
+
|
|
10
|
+
Shared parts: [Capability contracts](README.md#capability-contracts).
|
|
11
|
+
|
|
12
|
+
## Records
|
|
13
|
+
|
|
14
|
+
- `DirectoryUser`: `id`, `email`, `displayName`, `givenName`, `familyName`, `jobTitle`, `department`, `enabled` (false when disabled or suspended).
|
|
15
|
+
- `DirectoryGroup`: `id`, `name`, `email`, `description`.
|
|
16
|
+
- `DirectoryFlags`: `groups`, `nativeDelta` (false when the connector emulates delta), `pushNotifications`.
|
|
17
|
+
|
|
18
|
+
## Operations
|
|
19
|
+
|
|
20
|
+
| Operation | Scopes | What |
|
|
21
|
+
| --- | --- | --- |
|
|
22
|
+
| `listUsers` | `directory.read` | Users, paged |
|
|
23
|
+
| `getUser` | `directory.read` | One user |
|
|
24
|
+
| `listGroups` | `directory.read` | Groups, paged (flag `groups`) |
|
|
25
|
+
| `delta` | `directory.read` | Changes to users since `cursor`: upserts for created and changed users, deletes for deleted ones |
|
|
26
|
+
|
|
27
|
+
An emulated delta (Google: the Admin SDK has no delta query) carries a snapshot of each user's version in its cursor, never expires, and reports changes in id order; its cursor grows with the directory.
|
|
28
|
+
|
|
29
|
+
## How an implementation is checked
|
|
30
|
+
|
|
31
|
+
`directoryProviderConformance(harness)` registers: users listed page by page (two per page) including a seeded one, read by id and enabled; groups when claimed; NotFound for an unknown id; the shared delta checks (the InvalidCursor check is skipped where the protocol has no cursor to expire) and Connection checks (probe `listUsers`, merged scopes with Mail).
|
|
32
|
+
|
|
33
|
+
## Not yet guaranteed
|
|
34
|
+
|
|
35
|
+
- Managers, group memberships, photos and custom attributes.
|
|
36
|
+
- Proven against protocol fakes, not the real services.
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
# Directory
|
|
2
|
+
|
|
3
|
+
Kind: kernel service. Version 1.5.0 (1.5.0: enterprise sign-in and provisioning through WorkOS, `getEnterpriseAuth` and `setEnterpriseAuth`; 1.4.0: an organisation's sign-in methods, and teams; 1.2.0, made on two branches at once: `addMemberByEmail` and the member routes over HTTP (build/example-app); invitations, claimed domains with self-service joining, permission explanations, group metadata and atomic group edits, and every operation served over HTTP (build/identity); 1.3.0: both together). Schema: [`packages/contracts/schema/contracts/Directory.json`](../../packages/contracts/schema/contracts/Directory.json). Source: [`packages/contracts/src/contracts/Directory.ts`](../../packages/contracts/src/contracts/Directory.ts); kernel implementation in [`packages/kernel/src/Directory.ts`](../../packages/kernel/src/Directory.ts), tables in kernel migrations `0008_directory` and `0085_directory_administration` (invitations, domains, group metadata) ([`packages/kernel/src/db/KernelSchema.ts`](../../packages/kernel/src/db/KernelSchema.ts)).
|
|
4
|
+
|
|
5
|
+
## Purpose
|
|
6
|
+
|
|
7
|
+
Decision 1: the kernel owns actors, organisations, groups, memberships and roles. Employees, positions, reporting lines and companies belong to a registry People module.
|
|
8
|
+
|
|
9
|
+
- An **organisation** has **members** (users).
|
|
10
|
+
- A **role** belongs to an organisation and grants **permissions** from the permission vocabulary: the kernel's own (`eloxiv.directory.manage`, and `eloxiv.outbox.manage` for the [outbox](outbox.md)'s dead letters) and every installed module's (declared in its [manifest](module-manifest.md) under `permissions`). A membership holds any number of roles.
|
|
11
|
+
- A **group** belongs to an organisation and holds members of it. Groups are flat.
|
|
12
|
+
- Every new organisation has two built-in roles: `admin` (grants every kernel permission) and `member` (grants nothing).
|
|
13
|
+
|
|
14
|
+
Policies read the actor's roles, groups and permissions (see [Actor](actor.md)).
|
|
15
|
+
|
|
16
|
+
## Operations
|
|
17
|
+
|
|
18
|
+
`createOrganization` is for trusted setup code (seeds, tests, provisioning). Every other operation is a **management operation**: it is called with the caller's request credentials, acts in the organisation the caller acts in, and authenticates the caller afresh on every call. In the kernel they are `Directory.as(headers).<operation>(input)`.
|
|
19
|
+
|
|
20
|
+
Writes need the `eloxiv.directory.manage` permission in that organisation, checked against the live directory inside the write's transaction. Lists need membership only.
|
|
21
|
+
|
|
22
|
+
**`eloxiv.directory.manage` is the organisation's superuser permission.** A holder can create any role with any permissions of the vocabulary, assign any role to any member, themselves included, and so grant anyone, themselves included, every permission the organisation can grant, including `eloxiv.directory.manage`. There is no narrower grant ceiling: a member who holds some permissions but not `eloxiv.directory.manage` cannot assign or change any role, even one granting only permissions they hold. By default only the built-in `admin` role grants it. Give it only to people who may administer the organisation; every grant is audited with its before and after state (see Guarantees).
|
|
23
|
+
|
|
24
|
+
| Operation | Input | Effect |
|
|
25
|
+
| --- | --- | --- |
|
|
26
|
+
| `createOrganization` | `{ id, name, admin? }` | Create the organisation with the built-in roles and, if given, its first administrator. Creating an existing organisation changes nothing. Audited without an actor. |
|
|
27
|
+
| `listMembers` | `{}` | Members with their roles and groups. |
|
|
28
|
+
| `addMember` | `{ userId, roles? }` | Add an existing user with the given roles (default `member`). |
|
|
29
|
+
| `addMemberByEmail` | `{ email, roles? }` | Add the existing user with this address (compared without case) with the given roles (default `member`). Only an account that has **verified** the address is added: anyone can sign up with an address they do not receive mail at, so an unverified account is `InvalidInput`, pointing the administrator to an invitation (`createInvitation`, which admits the address once it is verified). An address with no account, or one already a member, is `InvalidInput` too, told only to a caller who holds `eloxiv.directory.manage`: everyone else is refused first (`Forbidden`) and learns nothing about which addresses have accounts. |
|
|
30
|
+
| `removeMember` | `{ userId }` | Remove a member, with their roles and group memberships. |
|
|
31
|
+
| `createGroup` | `{ id, name }` | Create a group. |
|
|
32
|
+
| `deleteGroup` | `{ id }` | Delete a group and its memberships. |
|
|
33
|
+
| `addToGroup` | `{ groupId, userId }` | Add a member to a group. |
|
|
34
|
+
| `removeFromGroup` | `{ groupId, userId }` | Remove a user from a group. |
|
|
35
|
+
| `listGroups` | `{}` | Groups with their members. |
|
|
36
|
+
| `createRole` | `{ id, name, permissions }` | Create a role granting vocabulary permissions. |
|
|
37
|
+
| `deleteRole` | `{ id }` | Delete a role; memberships lose it. |
|
|
38
|
+
| `setRolePermissions` | `{ id, permissions }` | Replace what a role grants. |
|
|
39
|
+
| `assignRole` | `{ userId, roleId }` | Give a member a role. |
|
|
40
|
+
| `unassignRole` | `{ userId, roleId }` | Take a role from a member. |
|
|
41
|
+
| `listRoles` | `{}` | Roles with the permissions they grant. |
|
|
42
|
+
| `listPermissions` | `{}` | The permission vocabulary: id, declaring module (`eloxiv` for the kernel), description, actions. |
|
|
43
|
+
| `explainPermission` | `{ permission, userId? }` | Why a member (default: the caller) holds a permission, or not: `{ userId, permission, held, grantedBy: [{ roleId, name }] }`, exactly the roles of theirs that grant it. Any member may ask. |
|
|
44
|
+
| `upsertGroup` | `{ id, name, metadata? }` | Create a group, or rename it and replace its metadata (kept when omitted). |
|
|
45
|
+
| `setGroupMembers` | `{ groupId, members }` | Replace a group's members with exactly these members of the organisation. |
|
|
46
|
+
| `editGroups` | `{ edits }` | Up to 500 changes (`{ op: "upsert", id, name, metadata? }`, `{ op: "delete", id }`, `{ op: "add" \| "remove", groupId, userId }`) applied in order in one transaction: all, or none when any is refused (the refusal names the change). |
|
|
47
|
+
| `createInvitation` | `{ email, roles?, expiresInDays?, acceptUrl? }` | Invite an address with roles (default `member`) for 1 to 30 days (default 7), replacing its pending invitation. Answers `{ id, token, expiresAt, mailed }`; the token is returned only here (stored hashed). With `acceptUrl`, which must be on the kernel's own or a trusted origin, and system email, mails `acceptUrl?invitation=<token>` to the address (template `account.invitation`). |
|
|
48
|
+
| `listInvitations` | `{}` | The organisation's invitations with their state (`pending`, `accepted`, `revoked`, `expired`), newest first. Needs `eloxiv.directory.manage`. |
|
|
49
|
+
| `revokeInvitation` | `{ id }` | Revoke a pending invitation. |
|
|
50
|
+
| `addDomain` | `{ domain }` | Claim a domain: answers its `record`, a TXT record (`_eloxiv-challenge.<domain>` holding `eloxiv-domain-verification=<token>`) that proves the claim. |
|
|
51
|
+
| `verifyDomain` | `{ domain }` | Read the TXT records now; the claim is verified once they hold its value. A domain another organisation verified is refused: a domain is verified by one organisation at most. |
|
|
52
|
+
| `setDomainJoin` | `{ domain, autoJoin, roles? }` | Whether people whose verified address is at the domain may join on their own, with which roles (default `member`). |
|
|
53
|
+
| `removeDomain` | `{ domain }` | Withdraw a claim. |
|
|
54
|
+
| `listDomains` | `{}` | The organisation's domains and their records. Needs `eloxiv.directory.manage`. |
|
|
55
|
+
| `getSignInMethods` | `{}` | The sign-in methods the organisation admits (`methods`, null: every one) and the deployment's (`available`: the auth provider's own, for Better Auth `password`, `magic-link` where offered and `oauth:<provider>` per configured provider; `sso` where the deployment has WorkOS). Any member may ask. |
|
|
56
|
+
| `getEnterpriseAuth` | `{}` | The organisation's enterprise sign-in: whether the deployment offers it (`available`), the WorkOS organisation it is linked to (`workosOrganizationId`, null: none), and whether its members sign in by SSO (`sso`) and are provisioned by Directory Sync (`directorySync`). Needs `eloxiv.directory.manage`. |
|
|
57
|
+
| `setEnterpriseAuth` | `{ workosOrganizationId, sso, directorySync }` | Link the organisation to a WorkOS organisation and opt in to SSO and Directory Sync, or unlink it (`null`). Every domain WorkOS has verified for that organisation must be one this organisation verified (`InvalidInput` otherwise, read from WorkOS's Organizations API), so no organisation links another's. Refused where the deployment has no WorkOS, and when it would turn SSO off while the organisation admits only `sso`. See [Enterprise sign-in and provisioning](#enterprise-sign-in-and-provisioning). |
|
|
58
|
+
| `setTeam` | `{ groupId, leads }` | Make a group a **team** (an opt-in enriched group), or change its leads: members of the group, kept in the team's lead group (`<id>--leads`, `TEAM_LEADS_SUFFIX`) that the Directory alone maintains (no one creates, edits or deletes a lead group as a group). A team's leads write its agent context ([AgentResources](agent-resources.md), [Memory](memory.md)); a lead removed from the team loses that at once (writes need both the team and the lead group). Kernel migration `0141_teams`. |
|
|
59
|
+
| `unsetTeam` | `{ groupId }` | A plain group again: its lead group goes, and no one's active team is it. |
|
|
60
|
+
| `listTeams` | `{}` | The teams, with members and leads (those still in the team). Any member may list. |
|
|
61
|
+
| `setActiveTeam` | `{ groupId }` | The caller's own choice of the team they work in (`null`: none): its agent context joins theirs (personal > team > organisation > app). Only a team they are in; it counts only while they are (`getActiveTeam` answers `null` otherwise). No directory permission needed. |
|
|
62
|
+
| `getActiveTeam` | `{}` | The caller's active team, or `null`. |
|
|
63
|
+
| `setSignInMethods` | `{ methods }` | Admit only these methods (or every one, `null`); `sso` admits every SSO connection's sessions (`sso:<connection>`). A member's session signed in otherwise is refused in the organisation from its next call (`Forbidden`), its connected replicas there stop at once (the session's sync facts are withdrawn in the change's transaction), OAuth consent and device approval for the organisation refuse it, a desktop session too (it carries the method of the session that approved it); a sign-in by a method none of a person's organisations admits is refused (`403`): the session Better Auth made is ended before any credential leaves. Refused (`InvalidInput`) when it would exclude the caller's own session, or names a method the deployment does not offer. Kernel migration `0140_sign_in_methods`; proven in [`sign-in-methods.test.ts`](../../packages/testing/test/sign-in-methods.test.ts). |
|
|
64
|
+
| `acceptInvitation` | `{ token }` | A person's own (no organisation named): join the invitation's organisation with its roles (those that still exist; `member` if none does). The invitation must be pending and unexpired, and the caller's address verified and the invited one (compared case-insensitively). Answers `{ orgId }`. |
|
|
65
|
+
| `joinableOrganizations` | `{}` | A person's own: the organisations whose verified, joinable domain is the caller's verified address's domain (exactly; not its parent), and that they are not in. |
|
|
66
|
+
| `joinOrganization` | `{ orgId }` | A person's own: join such an organisation with the domain's roles. |
|
|
67
|
+
| `listMyOrganizations` | `{}` | The signed-in caller's own organisations, oldest membership first (the first is where a call that names no organisation acts), each with its `orgId`, `name` and the caller's `roles`. Needs a session only (no membership of a named organisation); never lists another user's. Served over HTTP at `GET /api/me/organizations` (401 without a session) and in the client SDK as `listOrganizations(baseUrl, token)`; the shell's organisation switcher reads it. |
|
|
68
|
+
|
|
69
|
+
`listMembers` is served over HTTP at `GET /api/org/members` (`ORG_MEMBERS_PATH`), in the organisation `x-eloxiv-org` names, to a person's own signed-in session only: an API token (scoped or not), an OAuth grant, an agent session or a device is refused (403). It reads on the person's behalf, so like the agent's routes it runs under their chain, asserted (`Authority.within`: a removed membership is refused), and the read is made in the assertion's own transaction with the membership's row locked (`Directory.membersFor(asserted)`, which takes the capability and is a defect anywhere else): a removal either waits for the read or commits first and is seen. 401 without a credential, 403 for a caller who is not a member or not a session. The client SDK reads it as `listMembers(baseUrl, token, orgId)`; the shell's settings frame shows it. Proven in [`packages/testing/test/members-route.test.ts`](../../packages/testing/test/members-route.test.ts) and the shell's browser suite.
|
|
70
|
+
|
|
71
|
+
**Member administration over HTTP** (for a members screen), with the same caller rule (a person's own signed-in session only, in the organisation `x-eloxiv-org` names):
|
|
72
|
+
|
|
73
|
+
| Route | Operation |
|
|
74
|
+
| --- | --- |
|
|
75
|
+
| `POST /api/org/members` `{ email, roles? }` | `addMemberByEmail` |
|
|
76
|
+
| `DELETE /api/org/members/<userId>` | `removeMember` |
|
|
77
|
+
| `POST /api/org/members/<userId>/roles` `{ roleId }` | `assignRole` |
|
|
78
|
+
| `DELETE /api/org/members/<userId>/roles/<roleId>` | `unassignRole` |
|
|
79
|
+
| `GET /api/org/roles` (`ORG_ROLES_PATH`) | `listRoles` (any member) |
|
|
80
|
+
|
|
81
|
+
Each acts on the person's behalf: `Directory.asserting(request)` asserts the person's chain (their membership among it) in the operation's own transaction, before the directory's lock and before any row (Authority's lock order), so a session revoked or a membership removed meanwhile refuses it (401 or 403), and a removal of the caller either waits for the write or commits first. A deadlock with another directory write runs the operation again. Writes need `eloxiv.directory.manage`, keep the organisation's last member who holds it (its last administrator can be neither removed nor demoted: `InvalidInput`, "The change would leave the organisation with no member who can manage it"), and are audited as below, with surface `http`. Errors answer with the kernel's typed error as JSON: 401 `Unauthenticated`, 403 `Forbidden`, 400 `InvalidInput`; 404 for a path that names no operation. The client SDK calls them as `addMember`, `removeMember`, `assignRole`, `unassignRole` and `listRoles` (`baseUrl, token, orgId, ...`), which reject with `MemberAdminError` (`tag`, `message`, `status`). Proven in [`packages/testing/test/member-admin-routes.test.ts`](../../packages/testing/test/member-admin-routes.test.ts): an administrator adding by email, giving and taking a role, removing; a member without the permission refused (and audited `denied`) whatever the address; an administrator's API token, OAuth grant, agent session and device refused; administering one organisation granting nothing in another (a caller who is only a member there); a plain member demoting no one; the last administrator kept, also when the last two demote or remove each other at once (one lands, the other is refused); a write by an administrator whose removal is in progress waiting for it, then refused.
|
|
82
|
+
|
|
83
|
+
Every operation is served over HTTP at `POST /kernel/directory/<operation>` (`DIRECTORY_OPERATIONS_PATH`) with a JSON body, to a person's own signed-in session only (API tokens, OAuth grants, agent sessions and devices are refused), in the organisation `x-eloxiv-org` names (the person's own operations need none). Errors answer 401, 403 or 400 with the error's `_tag` and `message`. The client SDK calls them as `directoryClient({ baseUrl, token, orgId }).call(operation, input)`, typed from this contract.
|
|
84
|
+
|
|
85
|
+
A domain's TXT records are read through `DomainRecords` (default: the system resolver); `KernelOptions.domainRecords` replaces it (split DNS, tests).
|
|
86
|
+
|
|
87
|
+
Ids of organisations, groups and roles match `^[a-z0-9][a-z0-9_-]{0,62}$`.
|
|
88
|
+
|
|
89
|
+
The kernel also keeps two system helpers outside the contract for seeds and tests: `addMember({ orgId, userId, role? | roles? })` (audited without an actor) and `ensureUser({ email, password, name })`.
|
|
90
|
+
|
|
91
|
+
## Enterprise sign-in and provisioning
|
|
92
|
+
|
|
93
|
+
Where the deployment has WorkOS (`ELOXIV_WORKOS_API_KEY`, `ELOXIV_WORKOS_CLIENT_ID`, `ELOXIV_WORKOS_WEBHOOK_SECRET`, optionally `ELOXIV_WORKOS_API_URL`), an organisation opts in with `setEnterpriseAuth`. Kernel migration `0245_enterprise_auth`; [`packages/kernel/src/enterprise/`](../../packages/kernel/src/enterprise).
|
|
94
|
+
|
|
95
|
+
**SSO (federation).** `POST /api/sso/start { email, returnTo? }` answers `{ url }`, WorkOS's authorization URL for the organisation whose verified domain the address is at and which has SSO on (`403` for every other domain: unclaimed, unverified, or SSO off), and a cookie binding the flow to the browser. WorkOS sends the browser to `GET /api/sso/callback?code&state`, which needs that cookie and the state (256 bits, stored hashed, single use, ten minutes), exchanges the code for WorkOS's profile and requires it to be of the same WorkOS organisation and at a domain the organisation verified. The person is the account with that address (created verified when there is none; an account that holds it unverified is claimed as a magic link claims it: its credentials change, its password and provider links go, its sessions end), joins the organisation as a member if not yet one (audited, `eloxiv.directory.provision`), and gets a session issued by the auth provider under the credential fence, admitted with method `sso:<connection>`, only when the organisation's sign-in methods admit it. SSO being on, the linked WorkOS organisation, the verified domain and the methods are read again under the organisation's directory lock before the person joins (exclusive) and again before the session is admitted (shared, held until it is, as every issuer of a credential holds it): a change waits for the sign-in or refuses it; the browser goes to `returnTo` (a path of the app's) with the provider's session cookie. An organisation can then admit only `sso` (`setSignInMethods`), and a password sign-in of a person whose organisations admit only it is refused.
|
|
96
|
+
|
|
97
|
+
**Directory Sync (provisioning).** WorkOS posts the directory's events to `POST /api/workos/webhook`. Each is refused (`401`) unless its `WorkOS-Signature` is WorkOS's HMAC-SHA256 of the raw body under the webhook secret, made within three minutes; each is applied once (`eloxiv.directory_event`, the event and its changes in one transaction under the organisation's directory lock; a delivery seen before answers `replayed` and changes nothing), and never over a newer change: each user, group and membership keeps the version last applied (its `updated_at`, a membership's the event's `created_at`) and a tombstone once deleted, and an older event about it answers `stale` and changes nothing (WorkOS may deliver out of order); to the one organisation linked to its WorkOS organisation with Directory Sync on (`ignored` otherwise):
|
|
98
|
+
|
|
99
|
+
| Event | Effect |
|
|
100
|
+
| --- | --- |
|
|
101
|
+
| `dsync.user.created`, `dsync.user.updated` (`state: active`) | The person (by their primary address, which must be at a domain the organisation verified; claimed as for SSO) becomes a member. The directory user is one account: a changed address follows the account it maps to, or, where another account already holds the new address, the mapping moves to that account and the previous one leaves (its sessions revoked), in the same transaction. |
|
|
102
|
+
| `dsync.user.updated` (any other state), `dsync.user.deleted` | They leave the organisation, and every session of theirs is revoked (their live connections told, their synced session facts withdrawn), in the event's transaction and in the directory's lock order: the organisation's directory lock exclusively, then the person's, then each session's. The organisation's last manager is not removed (the event is recorded, and a warning logged). |
|
|
103
|
+
| `dsync.group.created`, `dsync.group.updated` | The group `dsync-<id>` is created, or renamed. |
|
|
104
|
+
| `dsync.group.deleted` | The group goes. |
|
|
105
|
+
| `dsync.group.user_added`, `dsync.group.user_removed` | The member joins or leaves the group. |
|
|
106
|
+
| `dsync.deleted` | The whole directory: its people leave (their sessions end) and its groups go. |
|
|
107
|
+
|
|
108
|
+
Proven against a WorkOS protocol fake ([`WorkOsFake.ts`](../../packages/testing/src/fakes/WorkOsFake.ts)) in [`enterprise-auth.test.ts`](../../packages/testing/test/enterprise-auth.test.ts), not against WorkOS: the live lane ([`workos-live.test.ts`](../../packages/testing/test/workos-live.test.ts)) runs when a WorkOS environment's credentials are set, and lists what it needs.
|
|
109
|
+
|
|
110
|
+
## Records
|
|
111
|
+
|
|
112
|
+
`Member { userId, email, roles, groups }`, `Group { id, name, members, metadata }` (metadata: a JSON object of at most 4 KiB, `{}` when none, for an app's own use such as a connection grant's label), `GroupEdit`, `Role { id, name, permissions }`, `PermissionEntry { id, module, description, actions }`, `PermissionExplanation { userId, permission, held, grantedBy }`, `Invitation { id, email, roles, invitedBy, createdAt, expiresAt, state }`, `Domain { domain, verified, autoJoin, roles, record }`, `JoinableOrganization { orgId, name, domain }`.
|
|
113
|
+
|
|
114
|
+
## Errors
|
|
115
|
+
|
|
116
|
+
Every management operation may fail with:
|
|
117
|
+
|
|
118
|
+
- `Unauthenticated`: no valid session;
|
|
119
|
+
- `Forbidden`: the caller is not a member of the organisation, or a write without `eloxiv.directory.manage`;
|
|
120
|
+
- `Forbidden` also for an invitation accepted by another address or an unverified one, and a join whose address is unverified or not at a joinable domain;
|
|
121
|
+
- `InvalidInput`: input that does not decode, a permission outside the vocabulary, an unknown user, group or role, a duplicate id, a user who is not a member, or a change that would leave the organisation with no member who can manage it.
|
|
122
|
+
|
|
123
|
+
## Guarantees
|
|
124
|
+
|
|
125
|
+
- **Authorised:** a write by a caller without `eloxiv.directory.manage` in the organisation changes nothing.
|
|
126
|
+
- **Audited:** every write records one audit row (`eloxiv.audit_log`, action `eloxiv.directory.<operation>`, surface `internal`, or `http` from the member routes): `succeeded` in the change's transaction, or, after the rollback, `denied` (Forbidden, Unauthenticated) or `failed` (InvalidInput, and every failure the directory does not define, such as a database error or a defect, recorded with error tag `SqlError` or `Defect` before it propagates). Only interruption (for example shutdown mid-write) leaves no record, as on the invocation path. The system helpers (`createOrganization`, `addMember`) are audited the same way, without an actor.
|
|
127
|
+
- **Grants are recorded before and after:** a successful write's audit row carries `detail`: `{ subject: { kind, id }, before, after }`, the subject's state read in the change's transaction just before and just after it: a member's roles, groups and permissions (`addMember`, `addMemberByEmail`, `removeMember`, `addToGroup`, `removeFromGroup`, `assignRole`, `unassignRole`), a role's permissions and holders (`createRole`, `deleteRole`, `setRolePermissions`), or a group's members (`createGroup`, `deleteGroup`). A state is `null` when the subject does not exist.
|
|
128
|
+
- **No lock-out:** an organisation always keeps at least one member who can manage it; writes in one organisation are serialised so two administrators cannot both step down at once.
|
|
129
|
+
- **One lock order:** a write on a person's behalf (the member routes) takes its authority links first (the caller's chain, their membership among it, asserted in the write's own transaction: [Invocation](invocation.md#authority)), then the organisation's directory lock, then the rows it reads or changes (the target member's membership and roles); a write in process (`as(headers)`, the system helpers) asserts no chain and starts at the directory lock. A deadlock or serialisation failure the database still reports (two administrators removing each other, each holding their own membership's link) aborts the transaction, which is run again from the start, so each operation lands once or is refused, never half applied.
|
|
130
|
+
- **Serialised per organisation, whoever writes:** management calls, the system helpers and service-principal writes take the organisation's directory lock (`eloxiv.lock_directory`, a transaction-level advisory lock) before any row they read or change, and the triggers that keep the sync facts take it too, so a write through no API is serialised with them as well. Directory changes run at READ COMMITTED: a change in a REPEATABLE READ or SERIALIZABLE transaction is refused (`feature_not_supported`), whoever makes it, because its snapshot would not move once it holds the lock and it could record a stale sync fact. This includes the kernel's own directory writes when an operator sets `default_transaction_isolation` to `repeatable read` or `serializable` for the database or the kernel role: every directory write then fails, so leave the default at `read committed`. `TRUNCATE` of a directory table (`organization`, `membership`, `membership_role`, `role`, `role_permission`, `org_group`, `group_member`) is refused too: it skips the row triggers that keep the sync facts; delete the rows instead.
|
|
131
|
+
- **Immediate:** removing a member, a group membership, a role or a permission applies to the affected user's next call: authentication, pre-handler checks and row-level security all read the current directory. Connected sync replicas follow the change as soon as zero-cache replicates it, without a new query transform (see [Sync](sync.md), guarantee 6).
|
|
132
|
+
- **Organisation-scoped:** nothing in one organisation's directory counts while acting in another.
|
|
133
|
+
- **An invitation admits only its own address, proven:** a pending, unexpired invitation is accepted once, by a signed-in person whose verified address is the invited one; another address, an unverified one, a second use, a revoked or an expired invitation changes nothing. Its link is mailed only to an origin the kernel trusts.
|
|
134
|
+
- **A domain admits only proven addresses, for one organisation:** a claim is verified only when its TXT record holds the claim's value, by at most one organisation; a person joins through it only with a verified address at exactly that domain, while the organisation allows it.
|
|
135
|
+
- **A verified claim is checked again, and lapses once lost:** every kernel process looks up each verified claim's record again a day after its last good check (kernel migration `0202_domain_checks`). A claim whose record is gone (DNS answered without the claim's value, or that the name has none) lapses at once; a lookup DNS does not answer (a timeout, a server failure) is tried again an hour later, and a claim DNS has not answered for three days lapses too. A lapsed claim is no longer verified: nobody joins by it until an administrator verifies it again, and the lapse is audited (`eloxiv.directory.domainLapsed`, its reason `record gone` or `unanswered`). Proven in [`directory-admin.test.ts`](../../packages/testing/test/directory-admin.test.ts).
|
|
136
|
+
- **Group edits are atomic:** `editGroups` applies every change or none.
|
|
137
|
+
- The person's own writes (`acceptInvitation`, `joinOrganization`) take the joined organisation's directory lock and are audited there like management writes (with the caller as actor).
|
|
138
|
+
|
|
139
|
+
Proven in [`packages/testing/test/directory-admin.test.ts`](../../packages/testing/test/directory-admin.test.ts) through the client SDK and the HTTP route.
|
|
140
|
+
|
|
141
|
+
Limits: an invitation's mail is sent inside its write's transaction (a mail that cannot be sent leaves no invitation), so the organisation's directory lock is held up to the SMTP timeout (15 s); a removed TXT record is noticed at the claim's next check (up to a day later), not at once; invitations and domain joins grant roles that exist when they are used.
|
|
142
|
+
|
|
143
|
+
## Implementing it
|
|
144
|
+
|
|
145
|
+
Store organisations, memberships, roles (with their permissions), membership roles, groups and group members, scoped by organisation, removing a membership's roles and group memberships with it. Check the manage permission inside each write's transaction, validate permissions against the vocabulary, and audit as above.
|
|
146
|
+
|
|
147
|
+
## Running the conformance kit
|
|
148
|
+
|
|
149
|
+
```ts
|
|
150
|
+
import { directoryConformance } from "@eloxiv/testing/conformance/Directory"
|
|
151
|
+
|
|
152
|
+
directoryConformance(() => ({
|
|
153
|
+
newUser: async (label) => ({ userId, headers: (orgId) => /* credentials, with x-eloxiv-org */ }),
|
|
154
|
+
createOrganization: async ({ id, name, admin }) => { /* trusted bootstrap */ },
|
|
155
|
+
call: async (headers, operation, input) => /* { ok: true, value } or { ok: false, tag } */,
|
|
156
|
+
audit: async (orgId) => /* directory audit rows of the organisation, oldest first */,
|
|
157
|
+
modulePermission: "team.edit", // a permission an installed module declares
|
|
158
|
+
}))
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
Each test works in organisations with random ids, so the kit can share a database with other tests. The kernel runs it in [`packages/testing/test/conformance-directory.test.ts`](../../packages/testing/test/conformance-directory.test.ts).
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# DocumentSource
|
|
2
|
+
|
|
3
|
+
Files and folders at a provider (OneDrive through Microsoft Graph, Google Drive), over a kernel [Connection](connections.md): a source to read and index, not a store to write (Files and StorageBackend are the app's own storage).
|
|
4
|
+
|
|
5
|
+
- Kind: capability. Version 1.0.0.
|
|
6
|
+
- Schema: [`packages/contracts/schema/contracts/DocumentSource.json`](../../packages/contracts/schema/contracts/DocumentSource.json) (source [`DocumentSource.ts`](../../packages/contracts/src/contracts/DocumentSource.ts)).
|
|
7
|
+
- Implementations: the [`microsoft-graph`](../connectors/microsoft-graph.md) and [`google`](../connectors/google.md) connectors.
|
|
8
|
+
- Kit: `@eloxiv/testing/conformance/DocumentSource` ([source](../../packages/testing/src/conformance/DocumentSource.ts)), run by the connector tests in [`registry/test`](../../registry/test).
|
|
9
|
+
|
|
10
|
+
Shared parts: [Capability contracts](README.md#capability-contracts).
|
|
11
|
+
|
|
12
|
+
## Records
|
|
13
|
+
|
|
14
|
+
- `DocumentItem`: `id`, `name`, `kind` (`file`, `folder`), `parentId`, `mimeType`, `size`, `modifiedAt`, `webUrl`.
|
|
15
|
+
- `DocumentFlags`: `folders`, `content` (`getContent` returns bytes), `pushNotifications`.
|
|
16
|
+
|
|
17
|
+
## Operations
|
|
18
|
+
|
|
19
|
+
| Operation | Scopes | What |
|
|
20
|
+
| --- | --- | --- |
|
|
21
|
+
| `listItems` | `documents.read` | Items in a folder (default the root), paged |
|
|
22
|
+
| `getItem` | `documents.read` | One item's metadata |
|
|
23
|
+
| `getContent` | `documents.read` | A file's content, base64 (Google's native documents exported as text, sheets as CSV) |
|
|
24
|
+
| `delta` | `documents.read` | Changes to the whole drive since `cursor`: upserts for created, changed and moved items, deletes for deleted or trashed ones (the root itself is not reported) |
|
|
25
|
+
|
|
26
|
+
## How an implementation is checked
|
|
27
|
+
|
|
28
|
+
`documentSourceConformance(harness)` registers: a seeded file in the root listing, its metadata (a file) and content when claimed; NotFound for an unknown id; the shared delta and Connection checks (probe `listItems`, merged scopes with Mail).
|
|
29
|
+
|
|
30
|
+
## Not yet guaranteed
|
|
31
|
+
|
|
32
|
+
- Shared drives and items shared with the account, permissions (who may read an item, which an index must respect: ledger C-118), and writes.
|
|
33
|
+
- Proven against protocol fakes, not the real services.
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
# Files
|
|
2
|
+
|
|
3
|
+
File records owned by modules and attached to their records by reference (decisions.md "Kernel contracts"; ledger A-045, A-046, A-047, B-031, C-055; T964's A22). The bytes are in the deployment's [StorageBackend](storage-backend.md); the metadata, attachment, lifecycle and every authorisation are the kernel's.
|
|
4
|
+
|
|
5
|
+
- Kind: kernel service. Version 1.1.0 (1.1.0: storage per organisation and per person, `files.setStorage`, `files.clearStorage`, `files.storage`).
|
|
6
|
+
- Schema: [`packages/contracts/schema/contracts/Files.json`](../../packages/contracts/schema/contracts/Files.json) (source [`Files.ts`](../../packages/contracts/src/contracts/Files.ts)).
|
|
7
|
+
- Implementation: the `Files` service and the finalizing workflow in [`packages/kernel/src/files/Files.ts`](../../packages/kernel/src/files/Files.ts), its byte routes in [`Http.ts`](../../packages/kernel/src/files/Http.ts), content sniffing in [`Sniff.ts`](../../packages/kernel/src/files/Sniff.ts), the kernel module `filesModule` ([`module.ts`](../../packages/kernel/src/files/module.ts)), the client's sync table in [`@eloxiv/client/sync`](../../packages/client/src/FileSync.ts).
|
|
8
|
+
- Kit: `@eloxiv/testing/conformance/Files` ([source](../../packages/testing/src/conformance/Files.ts)).
|
|
9
|
+
|
|
10
|
+
## Declaring that an entity accepts files
|
|
11
|
+
|
|
12
|
+
```ts
|
|
13
|
+
import { defineEntity } from "@eloxiv/contracts/drizzle"
|
|
14
|
+
|
|
15
|
+
export const doc = defineEntity(tables.doc, {
|
|
16
|
+
// name, cedarType, policyAttributes ...
|
|
17
|
+
files: {
|
|
18
|
+
maxBytes: 2 * 1024 * 1024, // never above the deployment's limit (files.maxBytes, 100 MiB by default)
|
|
19
|
+
types: ["text/*", "application/pdf", "image/*"], // default: any but executables
|
|
20
|
+
ingest: true, // extract and index attached files for Search (the Ingestion contract)
|
|
21
|
+
},
|
|
22
|
+
})
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
The entity needs exactly one organisation attribute. Who may attach, replace and delete its files is its Cedar policy for the kernel's action **`attach`**; who may read them, its **`read`** policy:
|
|
26
|
+
|
|
27
|
+
```cedar
|
|
28
|
+
permit (principal, action == Archive::Action::"attach", resource is Archive::Doc)
|
|
29
|
+
when { resource.org == principal.org && (resource.owner == principal || resource.editors.contains(principal)) };
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
An entity without an `attach` policy accepts no attachments (fail closed). Startup refuses an `attach` policy that is not tied to the actor, as it refuses a `read` policy that is not. Executables and anything a browser would run (HTML, XHTML, SVG, any `*/xml` or `*+xml`, JavaScript) are accepted only when the entity names the exact type, and even then served only as an attachment of `application/octet-stream`. Markup is recognised from the bytes (any document opening with a tag, a comment, a doctype or an XML declaration; SVG anywhere in the first 8 KiB, prefixed or not), and bytes that are not text never keep a declared active type. Text declared as a text type no browser runs keeps it (see the lifecycle below).
|
|
33
|
+
|
|
34
|
+
## Operations
|
|
35
|
+
|
|
36
|
+
Every operation but `scan` is an action of the kernel module `files` (on every surface: typed client, HTTP `POST /api/actions/files.<name>`, MCP tools `files_<name>`, agent tools, the CLI), audited, with the standard errors (`Unauthenticated`, `Forbidden`, `InvalidInput`).
|
|
37
|
+
|
|
38
|
+
| Operation (action) | What it does |
|
|
39
|
+
| --- | --- |
|
|
40
|
+
| `beginUpload` (`files.beginUpload`) | Name, declared type, exact size, and optionally `attachTo: { entity, id }`. Checks the size and declared type against the limits (the entity's when attaching), the record's `attach` policy, and reserves the size in the organisation's quota under its lock; returns a signed URL per part (`files.partBytes`, 5 MiB by default) |
|
|
41
|
+
| `resumeUpload` (`files.resumeUpload`) | Fresh URLs for the parts not received yet, and those received: how an interrupted upload resumes. The uploader only |
|
|
42
|
+
| `completeUpload` (`files.completeUpload`) | Once every part arrived at its size: the backend assembles them, the file becomes `processing`, recorded with the call's authority (`bindDeferred(ctx.authority, "once")`), and `files.uploaded` (same transaction) starts the finalizing workflow |
|
|
43
|
+
| `abortUpload` (`files.abortUpload`) | Abandon an upload; its quota is released at once, its parts purged by the sweep |
|
|
44
|
+
| `attach` (`files.attachTo`) | Attach a staged file the caller uploaded to a record they may `attach` to, within that entity's limits; a file is attached once and never moved |
|
|
45
|
+
| `get` (`files.get`) | Metadata, if the caller may read the file |
|
|
46
|
+
| `list` (`files.list`) | The files of a record the caller may read |
|
|
47
|
+
| `download` (`files.download`) | A short-lived URL (`files.downloadUrlTtlS`, 5 minutes) for an available file the caller may read |
|
|
48
|
+
| `read` (`files.readText`) | A page (up to 20,000 characters) of the file's extracted text ([Ingestion](ingestion.md)), for agents; small text files read as they are |
|
|
49
|
+
| `delete` (`files.delete`) | Delete: a staged file by its uploader, an attached one by whoever may `attach` to its record; refused under a retention hold; destructive, so an agent needs its person's consent |
|
|
50
|
+
| `retain` (`files.retain`) | Set or lift a retention hold (`eloxiv.files.manage`), on a file the administrator may also read |
|
|
51
|
+
| `usage` (`files.usage`) | The organisation's stored bytes and quota |
|
|
52
|
+
| `setQuota` (`files.setQuota`) | Set the organisation's quota, or null for the deployment's default (`eloxiv.files.manage`). The quota is Metering's storage part ([Metering](metering.md)) |
|
|
53
|
+
| `scan` (in process) | The virus-scan hook: `KernelOptions.fileScanner` answers `clean`, `infected` or `error` for each completed upload. With `files.requireScan`, the kernel refuses to start without one |
|
|
54
|
+
|
|
55
|
+
`attach` and `read` are named `files.attachTo` and `files.readText` as actions because `attach` and `read` are the kernel's own Cedar actions on entities.
|
|
56
|
+
|
|
57
|
+
## Uploading and downloading bytes
|
|
58
|
+
|
|
59
|
+
The byte routes take no session: each URL is signed by the kernel for one part or one file, after its policy checks, and expires.
|
|
60
|
+
|
|
61
|
+
- `PUT /files/upload?token=…` with exactly the part's `Content-Length` (counted as it arrives; one byte more and it is refused). **Each part URL works once**: its nonce is claimed, while the upload is open, before a byte is read; the same URL again is `409` (a client whose answer was lost calls `files.resumeUpload`, which lists the part as received or issues a fresh URL). A single part is stored under a key of its own attempt and a part of several goes into the multipart upload, so a part never writes the file's object; it is recorded only while the upload is still open (under the file's lock), and a part that arrives after the upload completed, was abandoned or purged is refused and its bytes deleted. A part may be sent again over another URL (one from a resumed plan): the later one replaces it, atomically in the store, and completing a multipart upload uses the parts the store holds (each at its exact size), so two sends of one part racing never leave the record and the store disagreeing. The claims are deleted with the upload's parts once it completes, is abandoned or expires (a claim is refused for an upload that is not open).
|
|
62
|
+
- **The object a file is from is written once**, by `completeUpload` under the file's lock, and never again. Finalize records its etag; the download route serves only that object (same etag and size), or nothing.
|
|
63
|
+
- `GET /files/download?token=…` serves the file with the type finalizing decided (markup as `application/octet-stream`), `X-Content-Type-Options: nosniff`, `Content-Security-Policy: default-src 'none'; sandbox`, `Content-Disposition: attachment` (or `inline` for types safe to render: images but SVG, PDF, plain text) with the UTF-8 file name, and `Cache-Control: private, no-store`. Active types (HTML, XHTML, SVG, any `*/xml` or `*+xml`, JavaScript) are always served as `application/octet-stream`, as an attachment. A download URL names the person it was issued to and the credential they used (a session, an agent session, an API token, an OAuth grant, a device): when it is used, the route checks again that the credential is not signed out, revoked or expired and its scope (an agent's or a token's, narrower than the person's) still covers `files.download`, that they are a member, and that they may read the file (the record's read policy, now), so signing out, revoking the credential or the access, or deleting the file ends it at once. The credential is checked again after the stored object is opened (a remote store may make that wait), before the first byte is sent. What is guaranteed once sign-out returns: no download of that session's URLs starts; one whose first byte was already sent may finish (it was authorised when it opened, and it is bounded by the file's size). Downloads always go through this route, never a store's presigned URL.
|
|
64
|
+
|
|
65
|
+
## Where files are stored
|
|
66
|
+
|
|
67
|
+
By default every file's bytes are in the deployment's [storage backend](storage-backend.md). An organisation's administrators (`eloxiv.files.manage`) can keep the organisation's new files in an S3-compatible store of its own, and any member can keep their own staged files in a store of theirs (ledger A-045; [`Providers.ts`](../../packages/kernel/src/files/Providers.ts)):
|
|
68
|
+
|
|
69
|
+
| Action | Who | What |
|
|
70
|
+
| --- | --- | --- |
|
|
71
|
+
| `files.setStorage` | administrators (`scope: "org"`), any member (`"personal"`) | `endpoint`, `region`, `bucket`, optional `prefix` and `forcePathStyle`, `accessKeyId`, and `secret`: the **name** of the Secret holding the secret access key, the organisation's or the caller's own, put first through the [Secrets](secrets.md) contract. Naming a Secret has the kernel sign with it, so it takes what managing it takes: an organisation's store needs `eloxiv.secrets.manage` as well as `eloxiv.files.manage` (`Forbidden` otherwise, before the store is asked anything), and a personal store names only the caller's own Secrets. The store must answer a listing with those credentials, or nothing is saved (`InvalidInput`, saying nothing of what the store answered) |
|
|
72
|
+
| `files.clearStorage` | the same | `scope`: new files go to the next store (the organisation's, then the deployment's) |
|
|
73
|
+
| `files.storage` | any member | `org`, `personal` (each the store or null) and `current`: where the caller's new files go now |
|
|
74
|
+
|
|
75
|
+
- **No action input carries a key.** A store names its Secret; the key is in the Secret alone (envelope-encrypted, never returned), so no proposal, approval request, audit record or receipt of `files.setStorage` ever holds it.
|
|
76
|
+
- **Choice, and read routing.** A new upload goes to the uploader's own store, else their organisation's, else the deployment's, and its storage key records which, once: a store's file is `providers/<store id>/<the file's key>`. Every read, write and deletion of a file goes to the store its key names, so changing or clearing a store never strands a file: a store is never changed (setting another retires it), and a retired store is still read from for the files it holds.
|
|
77
|
+
- **The organisation's records never depend on one person's store.** An upload for a record (`attachTo`) goes to the organisation's store, or the deployment's, never the uploader's own; a file staged in the uploader's store is copied to the organisation's (or the deployment's) when it is attached, and read from there (the uploader's store keeps its own copy). Only the bytes finalizing verified are copied: at most the file's size is read, and its exact size and SHA-256 must be the ones finalizing recorded, or the attach is refused (`InvalidInput`) and the file left as it was, since the uploader may have replaced the object in their store since. So a record keeps its files when the person who uploaded them is erased.
|
|
78
|
+
- **Custody.** The kernel reads a store's key from its Secret on every use, never caching it: a Secret deleted (by its owner, or with its person's erasure) stops the store at once, in every process.
|
|
79
|
+
- **Destinations.** A store's endpoint is chosen by an organisation or a person, so every request to it (the check before it is saved included) goes only where the [outbound destination policy](connections.md) allows: `https:` to a public address, each name resolved and every address checked on every request, unless the deployment allows the host (`ELOXIV_OUTBOUND_ALLOW`, which a store on a loopback or private address needs).
|
|
80
|
+
- **Isolation.** A store holds its organisation's files only: the kernel's router refuses a key that names a store for another organisation's file, and another organisation's uploads never go to it.
|
|
81
|
+
- **Limit, stated.** A person's own store is read with their Secret: their erasure ends access to the staged files in it (theirs alone; files of records are not there). Downloads are the kernel's own route (the bytes pass through the kernel) whatever the store.
|
|
82
|
+
|
|
83
|
+
Tested in [`storage-providers.test.ts`](../../packages/testing/test/storage-providers.test.ts).
|
|
84
|
+
|
|
85
|
+
## Lifecycle
|
|
86
|
+
|
|
87
|
+
`uploading` → `processing` → `available`, or `rejected` (a limit broken: the size, a declared type the bytes are not, a type the entity does not accept, a scan error) or `quarantined` (the scanner found something). The finalizing workflow (`eloxiv.file-finalize`, durable, keyed by the file) reads the bytes once: exact size, SHA-256 and the type from the first bytes (PDF, PNG, JPEG, GIF, WebP, ZIP and the Office formats, gzip, executables, HTML, SVG, XML, plain text). A declared type with a signature must match the bytes; text keeps a declared text type that no browser runs (plain text, Markdown, CSV, TSV, JSON, iCalendar, vCard), even when it holds markup. Ordinary text often does (a README opening `<p align="center">`, a syslog line `<134>…`, JSON carrying an HTML string), and sniffing cannot tell it from a page; what keeps a reader safe is how every file is served (`nosniff`, a sandbox with no sources), so such a file is shown as text and nothing in it runs. Markup declared as anything else (an active type, a binary type, another text type, or nothing) is what its bytes are. Before it settles a file, the workflow asserts the authority the upload was completed under ([Invocation, Authority](invocation.md#authority)), before any lock it protects: an uploader no longer a member of the organisation, or a credential in that chain revoked or expired, gets the file `rejected` ("The authority it was uploaded under no longer holds", its bytes purged), and nothing of it is attached, indexed or ingested; the settling transaction ends with the check at commit. An upload completed before kernel migration `0175` has no recorded authority and is refused the same way. Under the record's lock, the uploader must still be allowed to `attach` to the record, with their membership and permissions read then and the record's sharing grants locked while it settles; a grant revoked meanwhile gets the file `rejected` ("Its uploader may no longer attach files to its record"), as it refuses a new upload. Rejected and quarantined bytes are deleted: by the workflow, and by the files sweep for any whose run stopped before it deleted them. An available attached file's name is indexed for [Search](search.md) under its record, and the file is ingested when its entity asks.
|
|
88
|
+
|
|
89
|
+
`deleted`: deleted by an action, an abandoned or expired upload (`files.uploadTtlMs`), a staged file never attached (`files.stagedTtlMs`), or **its record deleted** (the kernel's tracking trigger, in the deleting transaction). The quota is released at once; the bytes are purged by the sweep once `files.deletedRetentionMs` has passed and no retention hold remains. Deleting a file removes its name's search document and everything ingested from it (its items' original, title, text and chunks), the one way [Ingestion](ingestion.md#every-copy-goes) removes ingested content, in the deleting transaction. Every change to an attached file (attaching, deleting, a retention hold, finalizing) takes the locks of the records it is attached to (or is being attached to) before the file's row, never the other way round: the row is read under its lock in a savepoint, and found attached to a record whose lock is not held (attached meanwhile), the savepoint is rolled back (letting go of the row), that record's lock taken, and the row read again. Staging a file for a record (`beginUpload` with `attachTo`) takes the record's lock before it looks for the record and records the record's generation ([Search](search.md#derived-copies-and-how-each-goes)); finalizing refuses the file (`rejected`, "Its record changed while the file was being uploaded: upload it again", its bytes purged) if that generation moved meanwhile (any write to the record, a scrub of its personal data), so nothing derived from it is made visible after a change it was prepared before; and it checks again, under the record's lock and in the transaction that makes the file `available` (its name indexed, its content submitted for ingestion), that the record still exists: a record deleted meanwhile takes the file with it (`deleted`, "Its record was deleted"), and nothing of it becomes visible. Events: `files.uploaded`, `files.available`, `files.rejected`, `files.deleted` (also for each file deleted with its record, in the deleting transaction) (payload: file id, the record, the state), for modules to react to.
|
|
90
|
+
|
|
91
|
+
## Guarantees
|
|
92
|
+
|
|
93
|
+
1. Nothing is stored before the size, declared type, the record's `attach` policy and the quota are checked; concurrent uploads never pass the quota together.
|
|
94
|
+
2. A file attached to a record is readable (metadata, download, text) exactly when its record is, by the entity's read policy, for the caller, now; a staged file by its uploader only; never across organisations. A record that does not exist and one the caller may not use get the same answer.
|
|
95
|
+
3. The type a file is served as comes from its bytes; markup is never served as something a browser runs.
|
|
96
|
+
4. A file is available only after the scan hook passed it (or the deployment has none and does not require one).
|
|
97
|
+
5. Deletion respects retention holds; deleted bytes are purged; deleting a record deletes its files; deleting a file leaves nothing of what was ingested from it.
|
|
98
|
+
6. File metadata syncs to each replica by the same rule as reads (below).
|
|
99
|
+
7. A module attaches and lists files (`ctx.files`) only of its own records, and only as its caller could.
|
|
100
|
+
8. A part URL works once, never writes the file's object, and nothing arrives after the upload closed; the object served is the one finalize verified.
|
|
101
|
+
9. A download URL works only while its holder may still read the file.
|
|
102
|
+
|
|
103
|
+
## Sync
|
|
104
|
+
|
|
105
|
+
The kernel's `eloxiv.file` is replicated. Its Zero table, `eloxivFile`, is generated from the kernel's Drizzle declaration of `eloxiv.file` (`fileEntity`, decision 9), and only fields on the sync type allowlist sync (the size as a `bigint` and two instants, each held to its exact window by a CHECK, and the checksum as text); the kernel refuses to start with a schema whose `eloxivFile` differs. An app installing Files adds `fileTables` and `fileQueries` from `@eloxiv/client/sync` to its sync schema, with the tables of the entities that accept files. Every query that reads `eloxiv.file` (`files.ofRecord` with `{ entity, id }`, `files.staged`, or an app's own) is filtered by the kernel: files of the acting organisation, not deleted, either staged by the actor or attached to a record whose entity's read filter admits the actor (a live permission subquery on that entity's sync table, so revoking a grant removes the file from the replica). A file whose entity's table is not in the sync schema is never synced.
|
|
106
|
+
|
|
107
|
+
## How an implementation is checked
|
|
108
|
+
|
|
109
|
+
`filesConformance(start)` takes a `FilesSubject` ([`FilesSubject.ts`](../../packages/testing/src/conformance/FilesSubject.ts)): a kernel serving the archive conformance app ([`conformance/archive`](../../packages/testing/src/conformance/archive)) with a scanner that flags the EICAR test string, and controls (users and roles, calls on every surface, superuser SQL, audit, the sync endpoint, a sweep, the stored keys). The kernel runs it with a local directory and with the S3 protocol fake ([`files.test.ts`](../../packages/testing/test/files.test.ts)).
|
|
110
|
+
|
|
111
|
+
## Not yet guaranteed
|
|
112
|
+
|
|
113
|
+
- Uploads go through the kernel's part route; direct uploads to the store over its signed part URLs are not offered yet.
|
|
114
|
+
- Downloads stream through the kernel (no offload to a store's presigned URLs), the price of checking access at every use.
|
|
115
|
+
- Content sniffing recognises the formats listed above; other binary formats are served as declared (never as markup).
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# Flags
|
|
2
|
+
|
|
3
|
+
Feature flags that modules declare in their manifests, each with a default, targeted per organisation by its administrators, and evaluated the same way in handlers and on clients (decisions.md "Kernel contracts"; the ledger's A-095, B-064, C-067).
|
|
4
|
+
|
|
5
|
+
- Kind: kernel service. Version 1.2.0 (1.1.0 adds labs; 1.2.0 external providers, the reasons `provider` and `provider-unavailable`).
|
|
6
|
+
- Schema: [`packages/contracts/schema/contracts/Flags.json`](../../packages/contracts/schema/contracts/Flags.json) (source [`Flags.ts`](../../packages/contracts/src/contracts/Flags.ts), including `evaluateFlag` and `flagBucket`).
|
|
7
|
+
- Implementation: the `Flags` service in [`packages/kernel/src/Flags.ts`](../../packages/kernel/src/Flags.ts); the kernel module `flagsModule` ([`flags/module.ts`](../../packages/kernel/src/flags/module.ts)); the client's sync table and `flagFromReplica` in [`@eloxiv/client/sync`](../../packages/client/src/PlatformSync.ts).
|
|
8
|
+
- Kit: `@eloxiv/testing/conformance/Flags` ([source](../../packages/testing/src/conformance/Flags.ts)).
|
|
9
|
+
|
|
10
|
+
## Declaring a flag
|
|
11
|
+
|
|
12
|
+
```ts
|
|
13
|
+
flags: {
|
|
14
|
+
"crm.forecasts": { description: "Revenue forecasts on the board.", default: false },
|
|
15
|
+
},
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Ids are namespaced by the module; the default is a boolean. Handlers ask **`ctx.flags.isEnabled("crm.forecasts")`**; an undeclared flag is a defect. It reads the flag's rules on the handler's own connection, without switching its role, through the platform read function `eloxiv_platform.flag_rules(flag)` (`SECURITY DEFINER`, owned by `eloxiv_platform_read`, fixed search path, executable by module runtime roles only), which returns exactly the rules the `flags` read policy gives the caller its invocation context records (see [Settings](settings.md#operations) for why no role switch).
|
|
19
|
+
|
|
20
|
+
## Targeting
|
|
21
|
+
|
|
22
|
+
An organisation's administrators (`eloxiv.flags.manage`, which the built-in `admin` role grants) target a flag in their organisation with rules (`FlagRule`): one per kind and subject.
|
|
23
|
+
|
|
24
|
+
| Kind | Subject | Applies to |
|
|
25
|
+
| --- | --- | --- |
|
|
26
|
+
| `user` | a user id | that person |
|
|
27
|
+
| `group` | a group id | the group's members |
|
|
28
|
+
| `role` | a role id | members holding the role |
|
|
29
|
+
| `org` | none | everyone in the organisation |
|
|
30
|
+
| `rollout` | none, with `percentage` (0 to 100, two decimals) | the people whose bucket falls inside the percentage |
|
|
31
|
+
|
|
32
|
+
**Precedence**, most specific first: a `user` rule, then `group` rules, `role` rules, the `org` rule, a `rollout`, then the declared default. Within one level, if several rules apply, **off wins** (a person in one group targeted on and another targeted off gets off), so conflicts fail closed. A rollout with `enabled: true` turns the flag on for the people inside its percentage and off for the rest (with `enabled: false`, the reverse).
|
|
33
|
+
|
|
34
|
+
**Bucketing is deterministic.** A person's bucket for a flag is FNV-1a (32-bit) of `<flag>:<userId>`, mixed and taken modulo 10,000 (`flagBucket`); a rollout of p percent covers buckets below p × 100. So the same person always gets the same answer on every runtime and client, buckets are independent across flags, and raising the percentage only ever adds people.
|
|
35
|
+
|
|
36
|
+
`evaluateFlag(flag, declaration, rules, { userId, groups, roles })` in `@eloxiv/contracts` is the one evaluation function; the kernel and clients both run it.
|
|
37
|
+
|
|
38
|
+
## Operations
|
|
39
|
+
|
|
40
|
+
| Operation | Action | Input | Output | Who |
|
|
41
|
+
| --- | --- | --- | --- | --- |
|
|
42
|
+
| `evaluate` | `flags.evaluate` (read-only) | `{ flag }` | `{ flag, enabled, reason }` (`reason`: the level that decided) | every member |
|
|
43
|
+
| `set` | `flags.set` | `FlagRuleWrite`: `flag`, `kind`, `subject` (for user, group, role), `enabled`, `percentage` (for rollout) | `{ id }` | administrators |
|
|
44
|
+
| `remove` | `flags.remove` | `{ id }` | `{ id }` | administrators |
|
|
45
|
+
| `rules` | `flags.rules` (read-only) | `{ flag }` | every rule of the organisation for the flag | administrators |
|
|
46
|
+
|
|
47
|
+
`set` replaces the rule with the same kind and subject (its id is `<org>:<flag>:<kind>:<subject>`). Errors: `InvalidInput` (an undeclared flag; a subject on `org` or `rollout`, none on the others; a percentage on anything but a rollout, or outside 0 to 100); `Forbidden` (not an administrator of the organisation acted in); `Unauthenticated`.
|
|
48
|
+
|
|
49
|
+
## Sync and client evaluation
|
|
50
|
+
|
|
51
|
+
The `flags` module's table syncs to each person's replica: **exactly the rules that can apply to them**, every one of them (the `flags.mine` query has no bound, since a client holding only some would evaluate differently from the kernel without knowing it), in the organisation they act in: the `org` and `rollout` rules, `role` rules, the `user` rules about them, and the `group` rules of the groups they are in. The read policy tests group membership live ([Sync](sync.md), guarantee 7), so leaving a group takes its rules off a connected replica and joining adds them, without reconnecting. A person never receives the rules about other people or about groups they are not in. Add `platformTables` and `platformQueries` (`flags.mine`) from `@eloxiv/client/sync` to the app's sync configuration.
|
|
52
|
+
|
|
53
|
+
`flagFromReplica(flag, declaration, rows, { userId, roles })` evaluates locally: group rules apply as given (the replica already holds only the person's), role rules for the roles the client was told (`GET /api/me/organizations`). The kernel evaluates with the person's live groups and roles over the same rules, so the two agree; a role change reaches the client's evaluation when it next reads its memberships.
|
|
54
|
+
|
|
55
|
+
## Audit
|
|
56
|
+
|
|
57
|
+
Every `set` and `remove` is an invocation, audited once ([Audit](audit.md)), with `detail` `{ flag, rule, before, after }` (`{ enabled, percentage }` or `null`). Refused changes are audited as `denied` or `failed`.
|
|
58
|
+
|
|
59
|
+
## Labs
|
|
60
|
+
|
|
61
|
+
A flag a module declares with `lab: true` is a lab: an experimental feature each person may try. `flags.optIn({ flag, enabled })` sets the caller's own user rule for it (the most specific level, so it wins over their organisation's targeting; audited), `flags.clearOptIn({ id })` drops it (the rule id, from `flags.labs`; only their own: another's is refused by the policy), and `flags.labs({})` lists the installed labs, each with what the caller gets now (`enabled`, `reason`) and their own choice (`mine`, or null). `optIn` on a flag that is not a lab is `InvalidInput`. Labs read through `flagStatus` like every flag: off until their rules are read (they do not read on while loading). Administrators still target labs as any flag. Tested in [`flags-labs.test.ts`](../../packages/testing/test/flags-labs.test.ts).
|
|
62
|
+
|
|
63
|
+
**In the client:** `flagStatus(flag, declarations, rules, subject)` (`@eloxiv/client/sync`) gives a UI each case on its own, `loading`, `unavailable` (with why), `unregistered`, or `on` / `off` with the reason, from the replica's rules evaluated as the kernel does; `isFlagOn` is true only for `on`, so every other state fails closed ([`client-flags.test.ts`](../../packages/testing/test/client-flags.test.ts)).
|
|
64
|
+
|
|
65
|
+
## Providers
|
|
66
|
+
|
|
67
|
+
An app can hand some of its declared flags to an external provider (a feature-flag service; a LaunchDarkly connector would be one, not built): `KernelApp.flagProviders`, each a `FlagProvider` (`@eloxiv/kernel`) with a `name`, the declared `flags` it decides, optionally the `orgs` it decides them for (every organisation otherwise), a `timeoutMs` (default 2 s) and `evaluate({ flag, orgId, userId, roles, groups })`. A flag no module declares, or one two providers claim, refuses the app at startup.
|
|
68
|
+
|
|
69
|
+
Inside a provider's scope, the kernel asks it before the organisation's rules: `true` or `false` decides (`reason: "provider"`); `undefined` leaves the flag to the rules, as if there were no provider; a failure, or no answer in time, turns the flag **off** (`reason: "provider-unavailable"`), never on, and what the provider said goes only to the log. This holds wherever the kernel evaluates: `flags.evaluate`, `flags.labs` and a handler's `ctx.flags`. Outside the scope (another flag, another organisation) nothing changes, and the provider is not asked. It is told the person's ids, roles and groups, nothing else.
|
|
70
|
+
|
|
71
|
+
**On the client**, a replica holds the organisation's rules, not a provider's answers: `flagFromReplica` and `flagStatus` evaluate the rules only, so a client that must agree with the kernel on a provider-decided flag asks `flags.evaluate`. Tested in [`flag-providers.test.ts`](../../packages/testing/test/flag-providers.test.ts).
|
|
72
|
+
|
|
73
|
+
## How an implementation is checked
|
|
74
|
+
|
|
75
|
+
`flagsConformance(start)` takes a `PlatformSubject` (see [QuerySurface](query-surface.md#how-an-implementation-is-checked)). The fixture's `crm` module declares `crm.forecasts` (default off) and `crm.board` (default on); its `crm.peek` action returns what `ctx.flags.isEnabled` gives.
|
|
76
|
+
|
|
77
|
+
The kit checks: defaults, and undeclared flags refused; precedence through every level and off winning within a level, in `flags.evaluate` and in a handler, another organisation untouched; a rollout at 0, 25, 50, 75 and 100 percent deciding each of six people by `flagBucket`, the same on every evaluation, only ever adding people; authorisation (members, an agent acting for a member, another organisation's administrator) and malformed rules refused; audit records of changes and refusals; each person's replica holding exactly their applicable rules, the client's evaluation over them (`flagFromReplica`) equal to the kernel's, including a rollout at seven percentages for seven people, `flags.mine` unbounded, and a group's rules leaving the replica when its member leaves. The Eloxiv kernel runs it in [`packages/testing/test/flags.test.ts`](../../packages/testing/test/flags.test.ts); bucketing (determinism, range, an even spread, monotonic rollout) and precedence are proven property-based in [`packages/contracts/test/platform.test.ts`](../../packages/contracts/test/platform.test.ts).
|
|
78
|
+
|
|
79
|
+
## Not yet guaranteed
|
|
80
|
+
|
|
81
|
+
- **Deployment-level targeting**: rules are per organisation; a deployment-wide change is a new declared default.
|
|
82
|
+
- **Provider adapters**: the seam exists (Providers, above); LaunchDarkly and similar providers (ledger A-097, B-065) would be registry connectors, not built.
|
|
83
|
+
- **Loading state on the client**: a replica that has not synced yet holds no rules, so `flagFromReplica` returns the default; a client that must fail closed waits for the query to complete (Zero's `complete` result type) before acting on a flag.
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# Host
|
|
2
|
+
|
|
3
|
+
What the shell needs from wherever it runs (decision 7): deep links, push, secure storage, updates and file access. The kernel defines the contract; each host implements it and reports per capability whether it supports it, so the shell asks rather than guesses. A host that lacks a capability fails its operations with `HostUnsupported`; it never pretends.
|
|
4
|
+
|
|
5
|
+
- Kind: shell contract. Version 1.1.0 (1.1.0: `pushToken` and `onNotificationResponse`, for native hosts).
|
|
6
|
+
- Schema: [`packages/contracts/schema/contracts/Host.json`](../../packages/contracts/schema/contracts/Host.json) (source [`Host.ts`](../../packages/contracts/src/contracts/Host.ts)).
|
|
7
|
+
- The interface a host implements: `Host` in `@eloxiv/shell-core` ([`Host.ts`](../../packages/shell-core/src/Host.ts)), with `unsupported(host)` for the capabilities it does not implement.
|
|
8
|
+
- Implementations: the web, `webHost` in `@eloxiv/shell-core/web` ([`web/Host.ts`](../../packages/shell-core/src/web/Host.ts)); the Tauri desktop template, `desktopHost` in the registry's `desktop` item ([`desktop/host.ts`](../../registry/app/desktop/host.ts) over [`src-tauri/src/host.rs`](../../registry/app/desktop/src-tauri/src/host.rs)). The native Rune host (`desktop-rune`, decision 14) implements it in Rust ([`app/src/host.rs`](../../registry/app/desktop-rune/app/src/host.rs) and the modules it names), for its own screens rather than a web shell. The Expo mobile host (the registry's `mobile` item) implements it in TypeScript, `expoHost` ([`mobile/src/host.ts`](../../registry/app/mobile/src/host.ts)), with Host 1.1.0's native members.
|
|
9
|
+
- Kit: `@eloxiv/testing/conformance/Host` ([source](../../packages/testing/src/conformance/Host.ts)).
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
const host = "__TAURI_INTERNALS__" in window ? desktopHost({ version }) : webHost({ version, kernelUrl })
|
|
13
|
+
const opened = host.capabilities().deepLinks === "supported" ? await host.initialLink() : null
|
|
14
|
+
if (opened) navigate(shell.parseLink(opened)) // the View contract refuses foreign links again
|
|
15
|
+
await host.secretSet("session", session.token)
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Operations
|
|
19
|
+
|
|
20
|
+
| Operation | Capability | What it does |
|
|
21
|
+
| --- | --- | --- |
|
|
22
|
+
| `capabilities` | | `{ host, deepLinks, push, secureStorage, updates, files }`, each `supported` or `unsupported` |
|
|
23
|
+
| `initialLink` | deepLinks | The link the app was opened with, on its own origin or scheme only, else `null` |
|
|
24
|
+
| `onLink` | deepLinks | Calls a listener with each link the app is asked to open while running (own origin or scheme only); returns a function that stops it |
|
|
25
|
+
| `secretGet`, `secretSet`, `secretDelete` | secureStorage | Small secrets (at most 16 KiB) under keys matching `^[a-z0-9][a-z0-9._-]{0,127}$` |
|
|
26
|
+
| `pushPermission`, `pushSubscribe`, `pushUnsubscribe` | push | The person's permission (`granted`, `denied`, `prompt`), a subscription (`web-push` endpoint and keys, or an `apns`/`fcm` token) for a NotificationChannel, and removing it |
|
|
27
|
+
| `pushToken` | push | Native hosts: this installation's APNs or FCM device token after the person's permission (never a relay service's token), as `PushToken { provider, token, appId, environment? }`, for [`notifications.registerInstallation`](notifications.md#push) with the app's own installation id. Optional in the interface: a host without native push leaves it out |
|
|
28
|
+
| `onNotificationResponse` | push | Native hosts: calls a listener with each response to a push notification, the one that launched the app included, as `NotificationResponse { notificationId, link, action? }` (from the payload's `eloxiv` key); returns a function that stops it. A tap (no `action`) only navigates, to `link` once signed in and in its organisation; a decision button (`action: "approve" \| "reject"`) opens its request for the person and installation the notification was sent to (the payload's `userId` and `installationId`), in the organisation the gate accepted: on iOS it is decided with the payload's token at [`POST /api/notifications/decide`](notifications.md#decisions-from-a-notification), each attempt bound to that sign-in, installation and organisation; on Android, whose payloads carry no token and whose actions another app with notification access can invoke, it decides nothing by itself: the request opens with the verdict preselected and the decision is sent through the person's own session with the existing actions only once they confirm it in the app. Optional in the interface |
|
|
29
|
+
| `checkUpdate`, `applyUpdate` | updates | `{ current, available }`: this build against the one the deployment serves; moving onto it (only when there is one) |
|
|
30
|
+
| `openFiles`, `saveFile` | files | Files the person picks (name, media type, size, bytes); saving bytes to a file they choose |
|
|
31
|
+
|
|
32
|
+
Errors: `HostUnsupported { capability }`, `HostPermissionDenied`, `HostCancelled` (a picker or prompt dismissed), `HostFailure`.
|
|
33
|
+
|
|
34
|
+
A native host's push flow: `pushToken()` after the person allows notifications, then `notifications.registerInstallation({ installationId, ...token })` from the person's signed-in session (again whenever the platform rotates the token), `notifications.unregisterInstallation` on sign-out (the kernel also removes the installation when the session ends). Notification actions use the category `eloxiv.decision` with the actions `approve` and `reject`.
|
|
35
|
+
|
|
36
|
+
## The implementations
|
|
37
|
+
|
|
38
|
+
| Capability | Web (`webHost`) | Desktop template (`desktopHost`) | Rune host (`desktop-rune`) |
|
|
39
|
+
| --- | --- | --- | --- |
|
|
40
|
+
| Deep links | The page's URL, and back/forward navigations (`popstate`), on the page's origin | The `eloxiv://` link in the launch arguments; `onLink` listens for the host's `eloxiv-host-link` event. Registering the scheme with the OS and links to a running app need `tauri-plugin-deep-link` and `tauri-plugin-single-instance` (the desktop README) | The app's scheme (`app.json`'s `urlScheme`), registered by the installers and, from an AppImage or a development build, with the OS at launch (Linux: a desktop entry with `x-scheme-handler/<scheme>` made the default with `xdg-mime`; Windows: `HKCU\Software\Classes\<scheme>`; macOS: the bundle's `CFBundleURLTypes`, written by packaging). One process per app (Rune's `single_instance`): a later launch hands its link to the running one and exits; macOS delivers Apple events. Each link is read with `parseLink` (a Rust port, over the app's views from its sidecar and the host's own screens) and opens its screen in the organisation it names when the person belongs to it |
|
|
41
|
+
| Secure storage | AES-GCM under a non-extractable key generated in the browser and kept in IndexedDB; each value bound to its key name (additional data). Script in the page can use the key, never read it; no protection against script running in the page | The OS credential store through the `keyring` crate's native APIs (Keychain Services, the Credential Manager, the Secret Service over D-Bus): no tool run, nothing prompted, any value kept as it is; namespaced by the app's identifier (`tauri.conf.json`, compiled in), so two apps never share a secret; a store failure is an error, never "absent" | The same as the desktop template (the same `keyring` backends and service naming), namespaced by `app.json`'s `identifier`; an invalid id leaves the capability unsupported. The person's session stays in the daemon's own SecretStore |
|
|
42
|
+
| Push | Web Push through the page's service worker, after `Notification.requestPermission` | Unsupported | Unsupported (no push subscription). Instead, while it runs, the person's new notification records (followed through its daemon) are shown as OS notifications: rune-notify on macOS and Windows, the freedesktop service on Linux; reported apart as `{ shown, backend, permission?, reason? }`, the permission being the OS's own answer where it gives one (macOS, Windows) ([desktop-rune](../registry/desktop-rune.md)) |
|
|
43
|
+
| Updates | This build's version against the app version the kernel advertises (`GET /release`, or a function the app gives); applying reloads | Stub, unsupported (needs `tauri-plugin-updater`, signing keys and an update endpoint) | A manifest at the app's update URL (per channel), the build downloaded and checked against the app's minisign (Ed25519) public key, whose signed trusted comment must name this app, version, platform and install kind; never a downgrade. Applied after the window closes: an AppImage, a macOS bundle or a Linux install directory swapped by rename, the new build started and kept only once it is interactive, else rolled back and the old one started again; Windows runs the new installer. Unsupported, with the reason, without an update host, in a development build, or where the person cannot replace the install (a system package) |
|
|
44
|
+
| Files | File System Access pickers where the browser has them, else a file input and a download | The webview's (the web host's) | Unsupported |
|
|
45
|
+
|
|
46
|
+
The Expo host (`expoHost`, the `mobile` item; [registry/mobile.md](../registry/mobile.md)): **deep links** from React Native's `Linking` (the launch URL and those while running), the app's scheme (`app.json`'s `scheme`) or its web origin only; **secure storage** in the Android Keystore or the iOS Keychain through `expo-secure-store`, under `<app id>.secret.<key>`, a store failure an error; **push** with the OS permission (`prompt` while the OS will still ask), `pushSubscribe` and `pushToken` giving the native FCM or APNs token (`getDevicePushTokenAsync`), and `onNotificationResponse` reading each tap or button with the app's one link parser (the host decides nothing itself: the app opens a button's request only for the person and installation the notification was sent to, through its link gate, and decides it with the decision token on iOS, or on Android through the person's session once they confirm it in the app); **updates** and **files** unsupported. Proven by the conformance kit over a stand-in for the platform modules (`registry/test/mobile-host.test.ts`) and on an Android emulator by CI's `mobile` lane.
|
|
47
|
+
|
|
48
|
+
## Guarantees
|
|
49
|
+
|
|
50
|
+
1. **Honest capabilities**: every operation of an unsupported capability fails with `HostUnsupported` naming it.
|
|
51
|
+
2. **Only the app's own links**, at launch and while running.
|
|
52
|
+
3. **Secrets**: round-trip, replace, delete, survive a restart, stay apart by key, are never stored in plain text by the host, and malformed keys are refused.
|
|
53
|
+
4. **Updates** report `available: null` when the served build is this one (or unknown), and `applyUpdate` moves only when there is a newer one.
|
|
54
|
+
|
|
55
|
+
## How an implementation is checked
|
|
56
|
+
|
|
57
|
+
`hostConformance(start)` takes a harness that starts the host (optionally opened with a link), restarts it over the same storage, delivers links as the platform would, gives the bytes its secure storage holds at rest, and sets the version the deployment serves; it checks the guarantees above for each supported capability and the unsupported failures for the rest.
|
|
58
|
+
|
|
59
|
+
- The web host runs it in [`host-web.test.ts`](../../packages/testing/test/host-web.test.ts), with the runtime's real WebCrypto and IndexedDB from `fake-indexeddb` (the IndexedDB API in JavaScript, standing in for the browser's), plus checks that pages of one app share a key and apps do not, and that a value moved under another key does not decrypt.
|
|
60
|
+
- The Rune host's Rust implementation is proven by `cargo test` in `registry/app/desktop-rune` (`mise run rust:check`): `parseLink`'s port against the View kit's shell fixture (resolution, refused origins and schemes, routing to the host's screens), links reaching their screens over a fake daemon (waiting for sign-in, switching organisation, refusals changing nothing), a second launch handing its link to the running app with a real window (Linux, with a display), the scheme registration's per-OS builders, the keychain's rules and a real round trip through the OS store where one answers, and the updater against a local update server (a good update; another key, changed bytes, an unsigned or undecodable signature and a validly signed older build replayed under a newer version, all refused; downgrades; interrupted and overlong downloads leaving nothing) and its apply step (a build that starts kept, one that exits or hangs rolled back and the old one started again). It does not run the TypeScript kit: it is not a TypeScript host.
|
|
61
|
+
- The desktop template's TypeScript host runs it in [`registry/test/host-desktop.test.ts`](../../registry/test/host-desktop.test.ts) over a stand-in for Tauri's bridge that answers as `host.rs` does; the Rust commands are proven by `cargo test` in `src-tauri` (key rules, link filtering, namespaces from valid identifiers only, two apps kept apart, a failing store reported as failing, and a real round trip per app, empty and multi-line values included, through the OS store where one answers).
|
|
62
|
+
|
|
63
|
+
## Not yet guaranteed
|
|
64
|
+
|
|
65
|
+
- **Push and files are not run by the kit** (they need a person or a push service); the web host's push and pickers are unproven in tests.
|
|
66
|
+
- **The Tauri desktop template's deep links are launch-only and unregistered**, and its updates are a stub (above).
|
|
67
|
+
- **The Rune host on macOS and Windows** is built and unit-tested there by CI (`cargo test`); its scheme registration, single instance, keychain and update apply steps have run on Linux only. On Windows an update is the installer's and is not rolled back by the host.
|
|
68
|
+
- **The web host has not run the kit in a real browser**; its secure storage in Chromium, WebKit and the Tauri webviews is untested.
|