@gjermundgaraba/effect-actions 0.11.0 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +102 -41
- package/dist/Action.d.mts +31 -117
- package/dist/Action.mjs +14 -53
- package/dist/ActionCli.d.mts +60 -28
- package/dist/ActionCli.mjs +54 -48
- package/dist/ActionHttp.d.mts +18 -67
- package/dist/ActionHttp.mjs +20 -70
- package/dist/ActionMcp.d.mts +23 -29
- package/dist/ActionMcp.mjs +56 -114
- package/dist/ActionRpc.d.mts +147 -0
- package/dist/ActionRpc.mjs +113 -0
- package/dist/ActionToolkit.d.mts +28 -9
- package/dist/ActionToolkit.mjs +31 -4
- package/dist/Authentication.d.mts +15 -15
- package/dist/Authentication.mjs +42 -96
- package/dist/Testing.d.mts +30 -23
- package/dist/Testing.mjs +27 -44
- package/dist/{internal/authentication.d.mts → authentication/provider.d.mts} +41 -9
- package/dist/authentication/provider.mjs +12 -0
- package/dist/authentication/refusal.mjs +36 -0
- package/dist/{internal/cli.d.mts → cli/commands.d.mts} +16 -12
- package/dist/cli/commands.mjs +302 -0
- package/dist/{internal → contract}/call.d.mts +2 -2
- package/dist/contract/call.mjs +10 -0
- package/dist/{internal → contract}/errors.d.mts +13 -10
- package/dist/{internal → contract}/errors.mjs +9 -14
- package/dist/{internal → contract}/implementation.d.mts +37 -21
- package/dist/{internal → contract}/implementation.mjs +18 -49
- package/dist/contract/media.d.mts +13 -0
- package/dist/contract/media.mjs +18 -0
- package/dist/contract/rules.d.mts +25 -0
- package/dist/{internal/actions.mjs → contract/rules.mjs} +6 -42
- package/dist/{internal → http}/client.d.mts +7 -9
- package/dist/http/client.mjs +17 -0
- package/dist/http/declared.mjs +20 -0
- package/dist/http/schema-errors.mjs +9 -0
- package/dist/mcp/protocol.d.mts +18 -0
- package/dist/{internal/mcp.mjs → mcp/protocol.mjs} +29 -62
- package/dist/stdio/console.mjs +64 -0
- package/dist/{internal → testing}/memory.d.mts +1 -1
- package/dist/{internal → testing}/memory.mjs +5 -17
- package/dist/toolkit/tools.mjs +29 -0
- package/docs/Action-failures.md +47 -0
- package/docs/Action-in-process.md +93 -0
- package/docs/Action.md +211 -426
- package/docs/ActionCli-failures.md +104 -0
- package/docs/ActionCli.md +208 -293
- package/docs/ActionHttp-failures.md +83 -0
- package/docs/ActionHttp.md +205 -282
- package/docs/ActionMcp-failures.md +31 -0
- package/docs/ActionMcp.md +222 -271
- package/docs/ActionRpc-failures.md +21 -0
- package/docs/ActionRpc.md +179 -0
- package/docs/ActionToolkit-failures.md +15 -0
- package/docs/ActionToolkit.md +103 -119
- package/docs/Authentication-advanced.md +139 -0
- package/docs/Authentication-failures.md +99 -0
- package/docs/Authentication.md +143 -392
- package/docs/CONTEXT.md +40 -24
- package/docs/README.md +75 -35
- package/docs/Testing-failures.md +21 -0
- package/docs/Testing.md +193 -151
- package/docs/guarantees.md +35 -96
- package/docs/setup-failures.md +37 -0
- package/docs/setup.md +90 -92
- package/examples/README.md +68 -0
- package/examples/assistant/README.md +92 -0
- package/examples/assistant/src/agent.ts +92 -0
- package/examples/assistant/src/cli.ts +34 -0
- package/examples/assistant/src/commands.ts +25 -0
- package/examples/assistant/src/identity/Identity.ts +33 -0
- package/examples/assistant/src/identity/authorize.ts +24 -0
- package/examples/assistant/src/identity/handlers.ts +10 -0
- package/examples/assistant/src/identity/members.ts +9 -0
- package/examples/assistant/src/identity/permissions.ts +23 -0
- package/examples/assistant/src/scripted.ts +23 -0
- package/examples/assistant/src/tasks/Tasks.ts +63 -0
- package/examples/assistant/src/tasks/handlers.ts +25 -0
- package/examples/assistant/src/tasks/store.ts +96 -0
- package/examples/assistant/src/toolkit.ts +30 -0
- package/examples/assistant/test/commands.test.ts +57 -0
- package/examples/assistant/test/identity/identity.test.ts +43 -0
- package/examples/assistant/test/tasks/store.test.ts +48 -0
- package/examples/assistant/test/tasks/tasks.test.ts +75 -0
- package/examples/assistant/test/toolkit.test.ts +121 -0
- package/examples/kitchen-sink/README.md +318 -0
- package/examples/kitchen-sink/src/Actions.ts +19 -0
- package/examples/kitchen-sink/src/Api.ts +24 -0
- package/examples/kitchen-sink/src/Rpc.ts +12 -0
- package/examples/kitchen-sink/src/admin/Admin.ts +59 -0
- package/examples/kitchen-sink/src/admin/authenticate.ts +18 -0
- package/examples/kitchen-sink/src/admin/authorize.ts +27 -0
- package/examples/kitchen-sink/src/admin/grants.ts +22 -0
- package/examples/kitchen-sink/src/admin/handlers.ts +21 -0
- package/examples/kitchen-sink/src/admin/keys.ts +8 -0
- package/examples/kitchen-sink/src/agent.ts +47 -0
- package/examples/kitchen-sink/src/assistant/Assistant.ts +82 -0
- package/examples/kitchen-sink/src/assistant/conversations.ts +71 -0
- package/examples/kitchen-sink/src/assistant/demo-model.ts +33 -0
- package/examples/kitchen-sink/src/assistant/handlers.ts +126 -0
- package/examples/kitchen-sink/src/attachments/Attachments.ts +48 -0
- package/examples/kitchen-sink/src/attachments/download.ts +49 -0
- package/examples/kitchen-sink/src/attachments/handlers.ts +38 -0
- package/examples/kitchen-sink/src/attachments/store.ts +58 -0
- package/examples/kitchen-sink/src/browser.ts +33 -0
- package/examples/kitchen-sink/src/cli.ts +85 -0
- package/examples/kitchen-sink/src/config.ts +18 -0
- package/examples/kitchen-sink/src/identity/Identity.ts +61 -0
- package/examples/kitchen-sink/src/identity/authenticate.ts +87 -0
- package/examples/kitchen-sink/src/identity/authorize.ts +16 -0
- package/examples/kitchen-sink/src/identity/directory.ts +52 -0
- package/examples/kitchen-sink/src/identity/handlers.ts +9 -0
- package/examples/kitchen-sink/src/identity/members.ts +13 -0
- package/examples/kitchen-sink/src/identity/quota.ts +62 -0
- package/examples/kitchen-sink/src/issues/Issues.ts +111 -0
- package/examples/kitchen-sink/src/issues/assistant.ts +23 -0
- package/examples/kitchen-sink/src/issues/guide.ts +37 -0
- package/examples/kitchen-sink/src/issues/handlers.ts +37 -0
- package/examples/kitchen-sink/src/issues/store.ts +96 -0
- package/examples/kitchen-sink/src/issues/write-limit.ts +42 -0
- package/examples/kitchen-sink/src/memory.ts +30 -0
- package/examples/kitchen-sink/src/ops.ts +42 -0
- package/examples/kitchen-sink/src/request-policy.ts +63 -0
- package/examples/kitchen-sink/src/routes.ts +120 -0
- package/examples/kitchen-sink/src/sdk.ts +46 -0
- package/examples/kitchen-sink/src/seed.ts +65 -0
- package/examples/kitchen-sink/src/server.ts +62 -0
- package/examples/kitchen-sink/src/stdio.ts +34 -0
- package/examples/kitchen-sink/src/workspaces/Workspaces.ts +28 -0
- package/examples/kitchen-sink/src/workspaces/handlers.ts +23 -0
- package/examples/kitchen-sink/src/workspaces/registry.ts +46 -0
- package/examples/kitchen-sink/src/workspaces/tenant.ts +17 -0
- package/examples/kitchen-sink/test/admin/admin.test.ts +67 -0
- package/examples/kitchen-sink/test/assistant/assistant.test.ts +435 -0
- package/examples/kitchen-sink/test/attachments/attachments.test.ts +161 -0
- package/examples/kitchen-sink/test/identity/identity.test.ts +137 -0
- package/examples/kitchen-sink/test/identity/session.test.ts +110 -0
- package/examples/kitchen-sink/test/issues/assistant.test.ts +75 -0
- package/examples/kitchen-sink/test/issues/issues.test.ts +135 -0
- package/examples/kitchen-sink/test/request-policy.test.ts +125 -0
- package/examples/kitchen-sink/test/routes.test.ts +123 -0
- package/examples/kitchen-sink/test/support/scripted.ts +40 -0
- package/examples/live-rpc/README.md +107 -0
- package/examples/live-rpc/src/Rpc.ts +8 -0
- package/examples/live-rpc/src/browser.ts +98 -0
- package/examples/live-rpc/src/chat/Chat.ts +77 -0
- package/examples/live-rpc/src/chat/authorize.ts +16 -0
- package/examples/live-rpc/src/chat/handlers.ts +50 -0
- package/examples/live-rpc/src/chat/room.ts +23 -0
- package/examples/live-rpc/src/chat/store.ts +54 -0
- package/examples/live-rpc/src/client.ts +37 -0
- package/examples/live-rpc/src/identity/Identity.ts +19 -0
- package/examples/live-rpc/src/identity/members.ts +8 -0
- package/examples/live-rpc/src/identity/verifier.ts +23 -0
- package/examples/live-rpc/src/routes.ts +22 -0
- package/examples/live-rpc/src/server.ts +43 -0
- package/examples/live-rpc/test/browser.test.ts +105 -0
- package/examples/live-rpc/test/chat/chat.test.ts +69 -0
- package/examples/live-rpc/test/routes.test.ts +99 -0
- package/examples/live-rpc/test/server.test.ts +75 -0
- package/examples/mcp-tools/README.md +141 -0
- package/examples/mcp-tools/src/instructions.ts +12 -0
- package/examples/mcp-tools/src/printers/Printers.ts +121 -0
- package/examples/mcp-tools/src/printers/fake.ts +115 -0
- package/examples/mcp-tools/src/printers/farm.ts +136 -0
- package/examples/mcp-tools/src/printers/handlers.ts +29 -0
- package/examples/mcp-tools/src/routes.ts +52 -0
- package/examples/mcp-tools/src/server.ts +31 -0
- package/examples/mcp-tools/src/stdio.ts +26 -0
- package/examples/mcp-tools/test/printers/printers.test.ts +189 -0
- package/examples/mcp-tools/test/routes.test.ts +202 -0
- package/examples/notes-service/README.md +111 -0
- package/examples/notes-service/src/Api.ts +13 -0
- package/examples/notes-service/src/browser.ts +41 -0
- package/examples/notes-service/src/cli.ts +22 -0
- package/examples/notes-service/src/commands.ts +137 -0
- package/examples/notes-service/src/identity/Identity.ts +31 -0
- package/examples/notes-service/src/identity/authorize.ts +18 -0
- package/examples/notes-service/src/identity/handlers.ts +10 -0
- package/examples/notes-service/src/identity/users.ts +9 -0
- package/examples/notes-service/src/identity/verifier.ts +36 -0
- package/examples/notes-service/src/notes/Notes.ts +119 -0
- package/examples/notes-service/src/notes/handlers.ts +39 -0
- package/examples/notes-service/src/notes/store.ts +84 -0
- package/examples/notes-service/src/routes.ts +45 -0
- package/examples/notes-service/src/server.ts +26 -0
- package/examples/notes-service/src/status/Status.ts +10 -0
- package/examples/notes-service/src/status/handlers.ts +14 -0
- package/examples/notes-service/src/stdio.ts +25 -0
- package/examples/notes-service/test/commands.test.ts +288 -0
- package/examples/notes-service/test/notes/notes.test.ts +103 -0
- package/examples/notes-service/test/routes.test.ts +84 -0
- package/examples/quickstart/README.md +31 -0
- package/examples/quickstart/src/Api.ts +5 -0
- package/examples/quickstart/src/client.ts +13 -0
- package/examples/quickstart/src/greeting/Greeting.ts +12 -0
- package/examples/quickstart/src/greeting/handlers.ts +6 -0
- package/examples/quickstart/src/routes.ts +11 -0
- package/examples/quickstart/src/server.ts +16 -0
- package/examples/quickstart/test/greeting/greeting.test.ts +18 -0
- package/package.json +27 -9
- package/dist/internal/actions.d.mts +0 -9
- package/dist/internal/authentication.mjs +0 -11
- package/dist/internal/call.mjs +0 -12
- package/dist/internal/cli.mjs +0 -328
- package/dist/internal/client.mjs +0 -25
- package/dist/internal/console.mjs +0 -77
- package/dist/internal/declared.d.mts +0 -13
- package/dist/internal/declared.mjs +0 -34
- package/dist/internal/mcp.d.mts +0 -14
- package/dist/internal/media.d.mts +0 -8
- package/dist/internal/media.mjs +0 -26
- package/dist/internal/refusal.mjs +0 -67
- package/dist/internal/schema-errors.mjs +0 -20
- package/dist/internal/tools.mjs +0 -44
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
# Authentication failure modes
|
|
2
|
+
|
|
3
|
+
What you see when something is wrong, and the fix. Search for a fragment of the message.
|
|
4
|
+
Tasks: [Authentication.md](Authentication.md),
|
|
5
|
+
[Authentication-advanced.md](Authentication-advanced.md).
|
|
6
|
+
|
|
7
|
+
## Types and startup
|
|
8
|
+
|
|
9
|
+
- `Provider<CurrentUser, "notes-service.Login">` among a layer's requirements,
|
|
10
|
+
`Type 'Provider<...>' is not assignable to type 'never'` at `Layer.launch` or
|
|
11
|
+
`NodeRuntime.runMain`, or `Expected 2 arguments, but got 1` at a web handler's
|
|
12
|
+
`handler(request)`: a layer serving protected actions requires the provider of the descriptor
|
|
13
|
+
it names. Provide it, `Layer.provide(authenticate)`. Nothing else satisfies it: not the
|
|
14
|
+
identity itself, nor the provider of another descriptor, of the same identity or not
|
|
15
|
+
([Verify credentials](Authentication.md#verify-credentials)).
|
|
16
|
+
- `Authentication "<name>": the binding's descriptor is not its provider's`, a defect when
|
|
17
|
+
`ActionHttp.layer`, `ActionRpc.layer`, `ActionMcp.layerHttp` or `Authentication.protect`
|
|
18
|
+
builds: it names a descriptor built apart from the one `Authentication.layer` was given, such
|
|
19
|
+
as the same options passed to `make` twice, or a browser's static cookie descriptor served
|
|
20
|
+
with a provider built at startup. Build the server's surfaces and its provider from one
|
|
21
|
+
descriptor value.
|
|
22
|
+
- `Protected action '<name>' requires its matching authentication descriptor` thrown by `make`
|
|
23
|
+
or `layer` of `ActionHttp` or `ActionRpc`, or by `ActionMcp.layerHttp`, or a type error there,
|
|
24
|
+
such as `No overload matches this call`, naming `authentication`,
|
|
25
|
+
`"Protected actions take options naming their authentication"` or
|
|
26
|
+
`"Authentication descriptor does not cover every protected action"`: a protected action is
|
|
27
|
+
served and no descriptor is named, or one of another identity than the action declares. Give
|
|
28
|
+
`{ authentication: Login }`.
|
|
29
|
+
- `Invalid authentication name: "<name>", not an OpenAPI key` thrown by `make`: the name holds a
|
|
30
|
+
character such as `/` or `:`. Use letters, digits, `_`, `.` and `-`.
|
|
31
|
+
- `Authentication takes one native HttpApiSecurity scheme` thrown by `make`, or a type error on
|
|
32
|
+
its `security`: `security` is a record of schemes, or no native scheme. Omit `security` for
|
|
33
|
+
Bearer, or give one scheme.
|
|
34
|
+
- `A protected resource is published only for a Bearer scheme` thrown by `layer` or
|
|
35
|
+
`refusalResponse`, or a type error on `protectedResource` at `layer`: the descriptor names a
|
|
36
|
+
scheme other than Bearer. Drop `protectedResource`, or authenticate with a Bearer descriptor.
|
|
37
|
+
- Type error at `layer` on `verify`: the verifier fails with an error that is neither a refusal
|
|
38
|
+
nor one its descriptor declares, or succeeds with a value that is not the identity. Declare
|
|
39
|
+
the error in the descriptor's `error`, or map it to a refusal where it is the caller's.
|
|
40
|
+
- `Authentication "<name>": error _tag "<tag>" is built in, and declared on every surface` thrown
|
|
41
|
+
by `make`: an `error` entry has the `_tag` of `InvalidInput`, `Unauthenticated` or `Forbidden`.
|
|
42
|
+
Fail with the built-in refusal itself, or give the error a `_tag` of its own.
|
|
43
|
+
- A startup service that the Effect building a verifier yields is unsatisfied where the server
|
|
44
|
+
launches: provide it to the provider's layer,
|
|
45
|
+
`Authentication.layer(Login, build).pipe(Layer.provide(Directory.layer))`, or above it.
|
|
46
|
+
- `Request<"Requires", Tenant>` still owed although the tenant middleware's layer is provided:
|
|
47
|
+
the middleware's layer is in one `Layer.provide([...])` array with the provider, whose
|
|
48
|
+
members do not provide to one another. Provide it in a later `Layer.provide` of its own
|
|
49
|
+
([Read request context in a verifier](Authentication-advanced.md#read-request-context-in-a-verifier)).
|
|
50
|
+
|
|
51
|
+
## Requests
|
|
52
|
+
|
|
53
|
+
- An action that must be authenticated answers without credentials: its contract states
|
|
54
|
+
`caller: Action.Anyone`. Make it protected; the surfaces then authenticate it, whatever its
|
|
55
|
+
handler reads.
|
|
56
|
+
- A request the `Host` or `Origin` check should refuse gets a 401 and a challenge: the check is
|
|
57
|
+
the layer's own `middleware`, which runs inside authentication. Make it global router
|
|
58
|
+
middleware
|
|
59
|
+
([Run a request policy before authentication](Authentication-advanced.md#run-a-request-policy-before-authentication)).
|
|
60
|
+
- An MCP host asks for sign-in when it connects: every tool of the endpoint is protected, or
|
|
61
|
+
the host opens a session with `initialize`, as a client of MCP 2025 does, and a session's
|
|
62
|
+
every request authenticates wherever a protected tool is served. Only a 2026-07-28 request
|
|
63
|
+
lists the tools and calls a public one signed out, on an endpoint that serves public tools
|
|
64
|
+
too ([ActionMcp.md](ActionMcp.md#protect-tools)).
|
|
65
|
+
- A verifier's declared error arrives as 422: the error states no `httpApiStatus`. Give it the
|
|
66
|
+
status it means, such as `{ httpApiStatus: 503 }`.
|
|
67
|
+
- `Testing.mcpClient` fails with an `McpCallError`, not a typed error, when the verifier fails
|
|
68
|
+
with an error its descriptor declares: over MCP that failure is the endpoint's HTTP answer,
|
|
69
|
+
before any tool runs. The `McpCallError` names its status and body.
|
|
70
|
+
- A route's `Cache-Control` is replaced by `no-store`: only a route's own answer keeps its
|
|
71
|
+
caching, and this response is a failure that enclosing middleware serialized.
|
|
72
|
+
|
|
73
|
+
## Discovery and scopes
|
|
74
|
+
|
|
75
|
+
- OAuth discovery returns 404, or an MCP client does not find the authorization server: the
|
|
76
|
+
request's path and query do not match `resource`'s exactly, or the provider is provided to no
|
|
77
|
+
served layer. Set `resource` to the endpoint's exact public URL, and provide the provider to
|
|
78
|
+
the routes served.
|
|
79
|
+
- A request the `Host` or `Origin` policy refuses elsewhere still reads the OAuth discovery
|
|
80
|
+
document: the policy registered after the provider. Provide the policy in the last
|
|
81
|
+
`Layer.provide`
|
|
82
|
+
([Run a request policy before authentication](Authentication-advanced.md#run-a-request-policy-before-authentication)).
|
|
83
|
+
- An MCP client asks a user who only reads to consent to writes on first login: the 401 names no
|
|
84
|
+
scope, so the client requests every one of `scopesSupported`. Give `scopesRequired`.
|
|
85
|
+
- An MCP client reports `InsufficientScopeError` instead of re-authorizing: it has no OAuth
|
|
86
|
+
provider configured. Configure one, or grant the scope up front.
|
|
87
|
+
- `new Action.Forbidden({ scopes })` throws a schema validation error, or
|
|
88
|
+
`Invalid scope in scopesRequired: "<scope>"`, or `in scopesSupported`, is thrown by `layer` or
|
|
89
|
+
`refusalResponse`, or is a defect when a resource an Effect builds is built: a scope is no
|
|
90
|
+
OAuth scope token (it is empty, or holds a space, `"` or `\`). Give each scope as its own
|
|
91
|
+
element.
|
|
92
|
+
- `A protected resource has no fragment: <resource>` thrown by `layer` or `refusalResponse`, or
|
|
93
|
+
a defect when a resource an Effect builds is built: `resource` has a `#fragment`, which no
|
|
94
|
+
request URL carries. Drop the fragment.
|
|
95
|
+
|
|
96
|
+
## Refusing outside the router
|
|
97
|
+
|
|
98
|
+
- `Not a refusal, nor an error the authentication declares` thrown by `refusalResponse`: the
|
|
99
|
+
error is neither, or the descriptor declaring it was not given. Pass `authentication`.
|