@gjermundgaraba/effect-actions 0.29.0 → 0.31.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/README.md +2 -2
  2. package/dist/Action.d.mts +6 -6
  3. package/dist/Action.mjs +17 -18
  4. package/dist/ActionCli.d.mts +23 -23
  5. package/dist/ActionCli.mjs +4 -4
  6. package/dist/ActionHttp.d.mts +17 -16
  7. package/dist/ActionHttp.mjs +18 -22
  8. package/dist/ActionMcp.d.mts +8 -8
  9. package/dist/ActionMcp.mjs +13 -16
  10. package/dist/ActionRpc.d.mts +24 -23
  11. package/dist/ActionRpc.mjs +58 -72
  12. package/dist/ActionToolkit.d.mts +1 -1
  13. package/dist/ActionToolkit.mjs +6 -5
  14. package/dist/Authentication.d.mts +2 -2
  15. package/dist/Authentication.mjs +44 -46
  16. package/dist/Event.d.mts +4 -4
  17. package/dist/Event.mjs +3 -3
  18. package/dist/Webhook.d.mts +2 -0
  19. package/dist/Webhook.mjs +1 -0
  20. package/dist/authentication/provider.d.mts +15 -15
  21. package/dist/authentication/refusal.mjs +12 -5
  22. package/dist/cli/commands.d.mts +2 -2
  23. package/dist/cli/commands.mjs +13 -13
  24. package/dist/contract/authorizer.d.mts +1 -1
  25. package/dist/contract/call.d.mts +2 -2
  26. package/dist/contract/call.mjs +1 -1
  27. package/dist/contract/callback.mjs +6 -1
  28. package/dist/contract/caller.d.mts +1 -1
  29. package/dist/contract/declared.d.mts +1 -1
  30. package/dist/contract/declared.mjs +1 -1
  31. package/dist/contract/digest.mjs +3 -2
  32. package/dist/contract/feed.d.mts +1 -1
  33. package/dist/contract/feed.mjs +12 -10
  34. package/dist/contract/hub.d.mts +1 -1
  35. package/dist/contract/idempotency.d.mts +1 -1
  36. package/dist/contract/idempotency.mjs +4 -4
  37. package/dist/contract/implementation.d.mts +27 -27
  38. package/dist/contract/implementation.mjs +8 -18
  39. package/dist/contract/input-check.d.mts +3 -3
  40. package/dist/contract/listed.d.mts +1 -1
  41. package/dist/contract/listed.mjs +1 -1
  42. package/dist/contract/pages.d.mts +1 -1
  43. package/dist/contract/push.d.mts +2 -2
  44. package/dist/contract/push.mjs +5 -7
  45. package/dist/contract/receiving.d.mts +2 -2
  46. package/dist/contract/receiving.mjs +1 -1
  47. package/dist/contract/recent.mjs +3 -2
  48. package/dist/contract/serving.mjs +18 -18
  49. package/dist/contract/stream.d.mts +1 -1
  50. package/dist/contract/stream.mjs +14 -2
  51. package/dist/contract/subscribe.mjs +7 -2
  52. package/dist/contract/transient.mjs +1 -1
  53. package/dist/contract/watch.d.mts +1 -1
  54. package/dist/contract/watch.mjs +5 -8
  55. package/dist/contract/webhooks.d.mts +1 -1
  56. package/dist/contract/webhooks.mjs +17 -6
  57. package/dist/http/client.d.mts +9 -9
  58. package/dist/http/client.mjs +6 -4
  59. package/dist/http/events.d.mts +6 -6
  60. package/dist/http/events.mjs +7 -5
  61. package/dist/http/placed.d.mts +3 -3
  62. package/dist/http/placed.mjs +5 -5
  63. package/dist/http/streamed.d.mts +3 -2
  64. package/dist/http/streamed.mjs +11 -6
  65. package/dist/http/watch.mjs +1 -1
  66. package/dist/mcp/bridge.mjs +13 -22
  67. package/dist/mcp/client.d.mts +10 -10
  68. package/dist/mcp/client.mjs +5 -14
  69. package/dist/mcp/events.mjs +1 -1
  70. package/dist/mcp/progress.mjs +11 -1
  71. package/dist/mcp/reply.d.mts +1 -1
  72. package/dist/mcp/watch.mjs +4 -4
  73. package/dist/rpc/watch.mjs +3 -5
  74. package/dist/webhook/health.mjs +25 -28
  75. package/dist/webhook/receiver.mjs +4 -7
  76. package/dist/webhook/stored.mjs +1 -1
  77. package/dist/webhook/subscriptions.mjs +19 -17
  78. package/docs/Action.md +1 -1
  79. package/docs/setup-failures.md +1 -1
  80. package/docs/setup.md +4 -4
  81. package/package.json +11 -12
@@ -1,17 +1,17 @@
1
- import { Codec } from "./contract/codec.mjs";
1
+ import { Any as Any$1, Descriptor, DescriptorOf, LayerIdentity, Matching, ProviderOf, PublicOnly, RemoteRequest, Required, Security, ServedProvider, ServerBuildServices, VerifierError } from "./authentication/provider.mjs";
2
+ import { Any as Any$2, Errors } from "./Action.mjs";
3
+ import { Call } from "./contract/call.mjs";
2
4
  import { Anyone } from "./contract/caller.mjs";
5
+ import { Codec } from "./contract/codec.mjs";
6
+ import { Certain, ErrorsOf } from "./contract/declared.mjs";
3
7
  import { BuiltIn, BuiltIns, Unauthenticated } from "./contract/errors.mjs";
8
+ import { Any as Any$3, Received, SubscriptionError } from "./Event.mjs";
4
9
  import { EventBuildError, EventBuildServices, EventServedRequest, HoldingEvents, ServingEvents } from "./contract/feed.mjs";
5
- import { Any as Any$1, Received, SubscriptionError } from "./Event.mjs";
6
10
  import { BuildError, Holding, Known, Member, MiddlewareOf, Selected, SelectedEvents, Served } from "./contract/implementation.mjs";
7
- import { Call } from "./contract/call.mjs";
8
- import { Answer, StreamOf } from "./contract/stream.mjs";
9
- import { WatchArgs } from "./contract/watch.mjs";
10
- import { Any as Any$2, Errors } from "./Action.mjs";
11
- import { Certain, ErrorsOf } from "./contract/declared.mjs";
12
- import { Any as Any$3, Descriptor, DescriptorOf, LayerIdentity, Matching, ProviderOf, PublicOnly, RemoteRequest, Required, Security, ServedProvider, ServerBuildServices, VerifierError } from "./authentication/provider.mjs";
13
11
  import { Only } from "./contract/listed.mjs";
14
12
  import { PushedOf, SubscriptionOf } from "./contract/push.mjs";
13
+ import { Answer, StreamOf } from "./contract/stream.mjs";
14
+ import { WatchArgs } from "./contract/watch.mjs";
15
15
  import { Context, Effect, Layer, Schedule, Schema, Scope, Stream, Types } from "effect";
16
16
  import { HttpRouter, HttpServerRequest } from "effect/http";
17
17
  import { Rpc, RpcClient, RpcClientError, RpcGroup, RpcMessage, RpcMiddleware, RpcSchema, RpcServer } from "effect/rpc";
@@ -28,7 +28,7 @@ type ElementedOf<Element extends Schema.Constraint, P> = Schema.Union<readonly [
28
28
  readonly value: P;
29
29
  }>] : [])]>;
30
30
  type RpcOf<A extends Any$2, E extends Errors, D> = A extends Any$2 ? A["success"] extends StreamOf<infer Element> ? Rpc.Rpc<A["name"], A["input"], RpcSchema.Stream<ElementedOf<Element, A["progress"]>, ErrorOf<A, E, D>>> : A["progress"] extends Codec ? Rpc.Rpc<A["name"], A["input"], RpcSchema.Stream<ReturnType<typeof ProgressedOf<A["progress"], A["success"]>>, ErrorOf<A, E, D>>> : Rpc.Rpc<A["name"], A["input"], A["success"], ErrorOf<A, E, D>> : never;
31
- type EventRpcOf<V extends Any$1, E extends Errors, D> = V extends Any$1 ? Rpc.Rpc<V["name"], ReturnType<typeof SubscriptionOf<V>>, RpcSchema.Stream<ReturnType<typeof PushedOf<V>>, Schema.Union<ReadonlyArray<E[number] | VerifierError<V, D> | BuiltIns>>>> : never;
31
+ type EventRpcOf<V extends Any$3, E extends Errors, D> = V extends Any$3 ? Rpc.Rpc<V["name"], ReturnType<typeof SubscriptionOf<V>>, RpcSchema.Stream<ReturnType<typeof PushedOf<V>>, Schema.Union<ReadonlyArray<E[number] | VerifierError<V, D> | BuiltIns>>>> : never;
32
32
  declare const authenticatedKey = "effect-actions/ActionRpc/Authenticated";
33
33
  type RefusalOf<E extends Errors> = Schema.Union<ReadonlyArray<typeof Unauthenticated | E[number]>>;
34
34
  declare const authenticatedBrand: unique symbol;
@@ -42,14 +42,14 @@ interface Authenticated<I, E extends Errors = Errors> {
42
42
  };
43
43
  }
44
44
  type AuthenticatedOf<D> = D extends Descriptor<infer I, unknown, Security, string, infer E> ? RpcMiddleware.ServiceClass<Authenticated<I, E>, typeof authenticatedKey, I, RefusalOf<E>, never, never, false> : never;
45
- type NativeOf<N extends Rpc.Any, D> = [D] extends [Any$3] ? Rpc.AddMiddleware<N, AuthenticatedOf<D>> : N;
45
+ type NativeOf<N extends Rpc.Any, D> = [D] extends [Any$1] ? Rpc.AddMiddleware<N, AuthenticatedOf<D>> : N;
46
46
  /**
47
47
  * An RPC binding: actions, event types, the errors every rpc declares, the descriptor
48
48
  * authenticating its protected ones, and the native rpcs it serves beside them. Plain data, so a
49
49
  * copy of it, or one made by another installed copy of this package, serves the same; `layer`
50
50
  * serves it and `client` calls it.
51
51
  */
52
- export interface Binding<Actions extends readonly Any$2[], E extends Errors = [], D extends Any$3 | undefined = undefined, Events extends readonly Any$1[] = readonly [], N extends Rpc.Any = never> {
52
+ export interface Binding<Actions extends readonly Any$2[], E extends Errors = [], D extends Any$1 | undefined = undefined, Events extends readonly Any$3[] = readonly [], N extends Rpc.Any = never> {
53
53
  /** The descriptor authenticating its protected actions, or `undefined` when it names none. */
54
54
  readonly authentication: D;
55
55
  /** The exact actions bound to this binding. */
@@ -80,9 +80,9 @@ export interface Binding<Actions extends readonly Any$2[], E extends Errors = []
80
80
  * their rpcs; `actions` carries the types.
81
81
  */
82
82
  export interface Any {
83
- readonly authentication?: Any$3 | undefined;
83
+ readonly authentication?: Any$1 | undefined;
84
84
  readonly actions: readonly Any$2[];
85
- readonly events: readonly Any$1[];
85
+ readonly events: readonly Any$3[];
86
86
  readonly error: Errors;
87
87
  readonly rpcs: RpcGroup.Any;
88
88
  readonly group: RpcGroup.Any;
@@ -98,7 +98,7 @@ export interface Options<E extends Errors = Errors> {
98
98
  * `Authentication.make(...)` of the protected actions' identity, which authenticates each of
99
99
  * their messages: required when the binding holds a protected action, and of its identity.
100
100
  */
101
- readonly authentication?: Any$3;
101
+ readonly authentication?: Any$1;
102
102
  /**
103
103
  * Native rpcs the binding serves beside its actions and event types, with their own schemas
104
104
  * and handlers: `RpcGroup.make(Upload)`. Under an `authentication`, each of their messages
@@ -134,11 +134,11 @@ type RpcsOf<O> = O extends {
134
134
  * - An action declaring `progress` is a stream rpc taking its input, streaming `{ _tag: "Progress", value }` for each value its handler reports, then one `{ _tag: "Final", value }` holding its answer: the native client's method of it returns a `Stream`.
135
135
  * - An action answering a stream, `Action.Stream`, is a stream rpc taking its input, streaming `{ _tag: "Element", value }` for each element, beside `{ _tag: "Progress", value }` for each value where it declares `progress`; `client`'s method returns a `Stream` of the elements.
136
136
  */
137
- export declare function make<const Contracts extends ReadonlyArray<(Any$2 | Any$1) & {
137
+ export declare function make<const Contracts extends ReadonlyArray<(Any$2 | Any$3) & {
138
138
  readonly caller: typeof Anyone;
139
- }>>(contracts: Contracts): Binding<Only<Contracts, Any$2>, [], undefined, Only<Contracts, Any$1>>;
140
- export declare function make<const Contracts extends ReadonlyArray<Any$2 | Any$1>, const O extends Options = {}>(contracts: Contracts, options: O & Required<Contracts[number]> & Matching<Contracts[number], NoInfer<DescriptorOf<O>>> & NoInfer<Known<O, Options>>): Binding<Only<Contracts, Any$2>, ErrorsOf<O>, DescriptorOf<O>, Only<Contracts, Any$1>, RpcsOf<O>>;
141
- export declare function make<const Contracts extends ReadonlyArray<Any$2 | Any$1>>(contracts: Contracts & PublicOnly<Contracts>): Binding<Only<Contracts, Any$2>, [], undefined, Only<Contracts, Any$1>>;
139
+ }>>(contracts: Contracts): Binding<Only<Contracts, Any$2>, [], undefined, Only<Contracts, Any$3>>;
140
+ export declare function make<const Contracts extends ReadonlyArray<Any$2 | Any$3>, const O extends Options = {}>(contracts: Contracts, options: O & Required<Contracts[number]> & Matching<Contracts[number], NoInfer<DescriptorOf<O>>> & NoInfer<Known<O, Options>>): Binding<Only<Contracts, Any$2>, ErrorsOf<O>, DescriptorOf<O>, Only<Contracts, Any$3>, RpcsOf<O>>;
141
+ export declare function make<const Contracts extends ReadonlyArray<Any$2 | Any$3>>(contracts: Contracts & PublicOnly<Contracts>): Binding<Only<Contracts, Any$2>, [], undefined, Only<Contracts, Any$3>>;
142
142
  type Middleware = readonly RpcMiddleware.AnyService[];
143
143
  type IdOf<K> = K extends Context.Key<infer I extends RpcMiddleware.AnyId, unknown> ? I : never;
144
144
  type Through<M extends Middleware, R> = number extends M["length"] ? R | RpcMiddleware.Requires<IdOf<M[number]>> : M extends readonly [infer K, ...infer Rest extends Middleware] ? Through<Rest, true extends Types.IsUnion<IdOf<K>> ? R | RpcMiddleware.Requires<IdOf<K>> : RpcMiddleware.ApplyServices<IdOf<K>, R>> : R;
@@ -148,15 +148,15 @@ type ForClient<K> = K extends {
148
148
  type ServerOnly<M extends Middleware, E extends Errors> = [Exclude<RpcMiddleware.Error<IdOf<M[number]>>, Extract<Certain<E>, BindingError>["Type"] | BuiltIn> | ForClient<M[number]>] extends [never] ? unknown : {
149
149
  readonly "Layer middleware fails only with the binding's errors and needs no client": never;
150
150
  };
151
- type LayerRequest<App, A extends Any$2, E extends Any$1, M extends Middleware> = Exclude<Through<M, RemoteRequest<App, A> | EventServedRequest<App, E>>, HttpServerRequest.HttpServerRequest | HttpServerRequest.ParsedSearchParams | LayerIdentity<App, A, E>>;
152
- type RpcLayer<B extends Any, Apps extends Served, M extends Middleware, A extends Any$2 = B["actions"][number], E extends Any$1 = B["events"][number]> = Layer.Layer<never, BuildError<Holding<Member<Apps>, A>, A> | EventBuildError<HoldingEvents<Member<Apps>, E>, E>, ServerBuildServices<Holding<Member<Apps>, A>, A> | EventBuildServices<HoldingEvents<Member<Apps>, E>, E> | RpcServer.Protocol | HttpRouter.Request.From<"Requires", LayerRequest<Member<Apps>, A, E, M>> | ServedProvider<Member<Apps>, A, B extends {
151
+ type LayerRequest<App, A extends Any$2, E extends Any$3, M extends Middleware> = Exclude<Through<M, RemoteRequest<App, A> | EventServedRequest<App, E>>, HttpServerRequest.HttpServerRequest | HttpServerRequest.ParsedSearchParams | LayerIdentity<App, A, E>>;
152
+ type RpcLayer<B extends Any, Apps extends Served, M extends Middleware, A extends Any$2 = B["actions"][number], E extends Any$3 = B["events"][number]> = Layer.Layer<never, BuildError<Holding<Member<Apps>, A>, A> | EventBuildError<HoldingEvents<Member<Apps>, E>, E>, ServerBuildServices<Holding<Member<Apps>, A>, A> | EventBuildServices<HoldingEvents<Member<Apps>, E>, E> | RpcServer.Protocol | HttpRouter.Request.From<"Requires", LayerRequest<Member<Apps>, A, E, M>> | ServedProvider<Member<Apps>, A, B extends {
153
153
  readonly authentication: infer D;
154
154
  } ? D : never, ServingEvents<Member<Apps>, E>> | IdOf<M[number]> | NativeServer<RpcGroup.Rpcs<B["rpcs"]>, B extends {
155
155
  readonly authentication: infer D;
156
156
  } ? D : never>>;
157
157
  type NativeServer<N extends Rpc.Any, D> = [N] extends [never] ? never : Rpc.ToHandler<N> | Exclude<Rpc.Middleware<N>, Authenticated<unknown>> | Rpc.ServicesServer<N> | ProviderOf<D>;
158
158
  /** `ActionRpc.layer`'s options. */
159
- export interface LayerOptions<M extends Middleware = [], C extends Any$2 | Any$1 = never> {
159
+ export interface LayerOptions<M extends Middleware = [], C extends Any$2 | Any$3 = never> {
160
160
  /**
161
161
  * The actions and event types it serves, among the binding's the implementations hold:
162
162
  * `[GetUser, UserRenamed]`, exactly those. Defaults to every one of them.
@@ -196,7 +196,8 @@ export interface KeptSubscription {
196
196
  readonly headers: ReadonlyArray<readonly [string, string]>;
197
197
  /**
198
198
  * The payload that resumes the subscription after `values`, a chunk sent for it, or
199
- * `undefined` where they reach no position.
199
+ * `undefined` where they reach no position. It never throws, being called as the protocol
200
+ * sends: an input that does not encode fails its subscription as it is admitted instead.
200
201
  */
201
202
  readonly resumeFrom: (values: RpcMessage.ResponseChunkEncoded["values"]) => Schema.Json | undefined;
202
203
  }
@@ -262,7 +263,7 @@ type Method<A extends Any$2, E extends BindingError> = Call<A, Answer<A["success
262
263
  * `mode: "poll"`, which rpcs do not serve, `NotServed` for an event the server does not serve), or
263
264
  * Effect's own `RpcClientError` that no reconnect outlasts. An element that does not decode is a defect, as for a call.
264
265
  */
265
- export type WatchError<W extends Any$1, B extends Any> = SubscriptionError | BuiltIns["Type"] | B["error"][number]["Type"] | VerifierError<W, B["authentication"]>["Type"] | RpcClientError.RpcClientError;
266
+ export type WatchError<W extends Any$3, B extends Any> = SubscriptionError | BuiltIns["Type"] | B["error"][number]["Type"] | VerifierError<W, B["authentication"]>["Type"] | RpcClientError.RpcClientError;
266
267
  type Watching<B extends Any> = [B["events"][number]] extends [never] ? unknown : {
267
268
  readonly watch: <W extends B["events"][number], SE = never>(event: W, ...args: WatchArgs<W, SE>) => Stream.Stream<Received<W>, WatchError<W, B> | SE>;
268
269
  };
@@ -1,17 +1,17 @@
1
+ import { providerOf } from "./authentication/provider.mjs";
2
+ import { checked, checkedStream, decodeInput, sendingJson, watchInput } from "./contract/call.mjs";
1
3
  import { Anyone } from "./contract/caller.mjs";
2
- import { InvalidInput, Unauthenticated } from "./contract/errors.mjs";
3
4
  import { bindingErrors, bindingOf, eventErrors } from "./contract/declared.mjs";
5
+ import { Unauthenticated } from "./contract/errors.mjs";
6
+ import { acquireFeeds } from "./contract/feed.mjs";
7
+ import { acquire, elementsOf } from "./contract/implementation.mjs";
8
+ import { listed } from "./contract/listed.mjs";
4
9
  import { reservedList, reservedNames } from "./contract/names.mjs";
5
10
  import { answerFrom, elementsFrom } from "./contract/progress.mjs";
6
- import { elementOf } from "./contract/stream.mjs";
7
- import { acquire, elementsOf } from "./contract/implementation.mjs";
8
- import { checked, checkedStream, decodeInput, inputParseOptions, sendingJson, watchInput } from "./contract/call.mjs";
11
+ import { PushedOf, SubscriptionOf, queuedPush } from "./contract/push.mjs";
9
12
  import { concealed } from "./contract/reported.mjs";
10
- import { acquireFeeds } from "./contract/feed.mjs";
11
- import { PushedOf, Subscription, SubscriptionOf, queuedPush } from "./contract/push.mjs";
12
- import { providerOf } from "./authentication/provider.mjs";
13
- import { listed } from "./contract/listed.mjs";
14
13
  import { provideServed, servingOf } from "./contract/serving.mjs";
14
+ import { Answering, answeringOf, elementOf } from "./contract/stream.mjs";
15
15
  import { watching } from "./contract/watch.mjs";
16
16
  import { transportOf } from "./rpc/watch.mjs";
17
17
  import { Cause, Effect, ErrorReporter, Layer, Match, Option, Predicate, Queue, Result, Schedule, Schema, SchemaTransformation, Stream } from "effect";
@@ -21,13 +21,12 @@ import { Rpc, RpcClient, RpcGroup, RpcMiddleware, RpcSchema, RpcServer } from "e
21
21
  // src/rpc/ActionRpc.ts
22
22
  const ProgressedOf = (progress, success) => Schema.Union([Schema.TaggedStruct("Progress", { value: progress }), Schema.TaggedStruct("Final", { value: success })]);
23
23
  const elementedOf = (element, progress) => Schema.Union([Schema.TaggedStruct("Element", { value: element }), ...progress === void 0 ? [] : [Schema.TaggedStruct("Progress", { value: progress })]]);
24
- const streams = (action) => action.progress !== void 0 || elementOf(action.success) !== void 0;
25
- const streamedOf = (action) => {
26
- const element = elementOf(action.success);
27
- if (element !== void 0) return elementedOf(element, action.progress);
28
- return action.progress === void 0 ? void 0 : ProgressedOf(action.progress, action.success);
29
- };
30
- const sentOf = (action) => streamedOf(action) ?? action.success;
24
+ const streams = (action) => !Answering.$is("Value")(answeringOf(action));
25
+ const streamedOf = (action) => Answering.$match(answeringOf(action), {
26
+ Value: () => void 0,
27
+ Progressed: ({ success, progress }) => ProgressedOf(progress, success),
28
+ Elements: ({ element, progress }) => elementedOf(element, progress)
29
+ });
31
30
  const authenticatedKey = "effect-actions/ActionRpc/Authenticated";
32
31
  const nativeOf = (group) => group;
33
32
  const authenticatedOf = (authentication) => RpcMiddleware.Service()(authenticatedKey, { error: Schema.Union([Unauthenticated, ...authentication.error]) });
@@ -35,12 +34,15 @@ const authenticatedIn = (rpc) => [...rpc.middlewares].find(({ key }) => key ===
35
34
  function make(contracts, options = {}) {
36
35
  const { actions, events } = listed(contracts);
37
36
  const bound = bindingOf("ActionRpc binding", actions, events, options);
38
- const rpcOf = (action) => Rpc.make(action.name, {
39
- payload: action.input,
40
- success: sentOf(action),
41
- error: Schema.Union(bindingErrors(action, bound)),
42
- stream: streams(action)
43
- });
37
+ const rpcOf = (action) => {
38
+ const streamed = streamedOf(action);
39
+ return Rpc.make(action.name, {
40
+ payload: action.input,
41
+ success: streamed ?? action.success,
42
+ error: Schema.Union(bindingErrors(action, bound)),
43
+ stream: streamed !== void 0
44
+ });
45
+ };
44
46
  const given = options.rpcs === void 0 ? RpcGroup.make() : nativeOf(options.rpcs);
45
47
  for (const tag of given.requests.keys()) if (reservedNames.includes(tag) || contracts.some((contract) => contract.name === tag)) throw new Error(`ActionRpc binding: the rpc "${tag}" of rpcs is named after an action, an event type or a name the client keeps, ${reservedList} (rename it)`);
46
48
  const rpcs = bound.authentication === void 0 ? given : given.middleware(authenticatedOf(bound.authentication));
@@ -111,40 +113,29 @@ const callBoundaryOf = (error) => {
111
113
  })) : Effect.failCause(failure.failure);
112
114
  });
113
115
  };
116
+ const servedCall = (steps, boundary, call) => (payload, options) => boundary(throughSteps(steps, call(payload, options), {
117
+ ...options,
118
+ payload
119
+ }));
114
120
  const handlerOf = (action, run, steps, error) => {
115
121
  const decode = decodeInput(action);
116
122
  const encode = Schema.encodeUnknownEffect(Schema.toCodecJson(action.success));
117
- const boundary = callBoundaryOf(error);
118
- return (payload, options) => {
119
- const call = Effect.suspend(() => decode(payload)).pipe(Effect.flatMap(run), Effect.flatMap(encode));
120
- const wrapped = throughSteps(steps, call, {
121
- ...options,
122
- payload
123
- });
124
- return boundary(wrapped);
125
- };
123
+ return servedCall(steps, callBoundaryOf(error), (payload) => Effect.suspend(() => decode(payload)).pipe(Effect.flatMap(run), Effect.flatMap(encode)));
126
124
  };
127
125
  const streamingHandlerOf = (action, sending, steps, error) => {
128
126
  const decode = decodeInput(action);
129
127
  const boundary = callBoundaryOf(error);
130
128
  const encodeProgress = Schema.encodeUnknownEffect(Schema.toCodecJson(action.progress ?? Schema.Never));
131
- return (payload, options) => {
132
- const call = Effect.gen(function* () {
133
- const input = yield* decode(payload);
134
- const sent = yield* Queue.bounded(1);
135
- const send = (each) => Effect.asVoid(Queue.offer(sent, each));
136
- yield* sending(input, { progress: (value) => Effect.flatMap(Effect.orDie(encodeProgress(value)), (json) => send({
137
- _tag: "Progress",
138
- value: json
139
- })) }, send).pipe(boundary, Queue.into(sent), Effect.forkScoped({ startImmediately: true }));
140
- return sent;
141
- });
142
- const wrapped = throughSteps(steps, call, {
143
- ...options,
144
- payload
145
- });
146
- return boundary(wrapped);
147
- };
129
+ return servedCall(steps, boundary, (payload) => Effect.gen(function* () {
130
+ const input = yield* decode(payload);
131
+ const sent = yield* Queue.bounded(1);
132
+ const send = (each) => Effect.asVoid(Queue.offer(sent, each));
133
+ yield* sending(input, { progress: (value) => Effect.flatMap(Effect.orDie(encodeProgress(value)), (json) => send({
134
+ _tag: "Progress",
135
+ value: json
136
+ })) }, send).pipe(boundary, Queue.into(sent), Effect.forkScoped({ startImmediately: true }));
137
+ return sent;
138
+ }));
148
139
  };
149
140
  const sendingAnswer = (success, run) => {
150
141
  const encode = Schema.encodeUnknownEffect(Schema.toCodecJson(success));
@@ -168,20 +159,17 @@ const keeperOf = (protocol) => {
168
159
  return isSubscriptionKeeper(kept) ? kept : void 0;
169
160
  };
170
161
  const subscriptionHandlerOf = (feed, steps, error, keeper) => {
171
- const decode = Schema.decodeUnknownEffect(Subscription, inputParseOptions);
172
- const decodeEventInput = decodeInput(feed.event);
162
+ const decode = decodeInput({ input: SubscriptionOf(feed.event) });
163
+ const encodeInput = Schema.encodeEffect(Schema.toCodecJson(feed.event.input));
173
164
  const sent = Schema.toCodecJson(PushedOf(feed.event));
174
165
  const encode = Schema.encodeEffect(sent);
175
166
  const decodeSent = Schema.decodeUnknownOption(sent);
176
167
  const boundary = callBoundaryOf(error);
177
- return (payload, options) => {
178
- const call = Effect.gen(function* () {
179
- const { input, cursor } = yield* Effect.mapError(decode(payload), InvalidInput.fromSchemaError);
180
- const open = yield* feed.stream(yield* decodeEventInput(input));
181
- if (keeper === void 0) return yield* queuedPush(open, cursor, encode, {
182
- ending: boundary,
183
- positions: "heartbeat"
184
- });
168
+ return servedCall(steps, boundary, (payload, options) => Effect.gen(function* () {
169
+ const { input, cursor } = yield* decode(payload);
170
+ const open = yield* feed.stream(input);
171
+ if (keeper !== void 0) {
172
+ const resumed = yield* Effect.orDie(encodeInput(input));
185
173
  yield* keeper.keep({
186
174
  clientId: options.client.id,
187
175
  requestId: options.requestId,
@@ -191,22 +179,17 @@ const subscriptionHandlerOf = (feed, steps, error, keeper) => {
191
179
  resumeFrom: (values) => {
192
180
  const reached = values.flatMap((value) => Option.toArray(decodeSent(value))).map((pushed) => Match.value(pushed).pipe(Match.tag("Failed", () => null), Match.orElse((positioned) => positioned.cursor))).findLast(Predicate.isNotNull);
193
181
  return reached === void 0 ? void 0 : {
194
- input,
182
+ input: resumed,
195
183
  cursor: reached
196
184
  };
197
185
  }
198
186
  });
199
- return yield* queuedPush(open, cursor, encode, {
200
- ending: boundary,
201
- positions: "watermark"
202
- });
203
- });
204
- const wrapped = throughSteps(steps, call, {
205
- ...options,
206
- payload
187
+ }
188
+ return yield* queuedPush(open, cursor, encode, {
189
+ ending: boundary,
190
+ positions: keeper === void 0 ? "heartbeat" : "watermark"
207
191
  });
208
- return boundary(wrapped);
209
- };
192
+ }));
210
193
  };
211
194
  /**
212
195
  * The key a protocol answering each call once sets to `true` on its `RpcServer.Protocol`
@@ -246,9 +229,12 @@ function layer(binding, served, options = {}) {
246
229
  requested
247
230
  ];
248
231
  const handlerFor = (action, run, steps, error) => {
249
- const element = elementOf(action.success);
250
- if (element !== void 0) return streamingHandlerOf(action, sendingElements(element, run), steps, error);
251
- return action.progress === void 0 ? handlerOf(action, run, steps, error) : streamingHandlerOf(action, sendingAnswer(action.success, run), steps, error);
232
+ const streaming = (sending) => streamingHandlerOf(action, sending, steps, error);
233
+ return Answering.$match(answeringOf(action), {
234
+ Value: () => handlerOf(action, run, steps, error),
235
+ Progressed: ({ success }) => streaming(sendingAnswer(success, run)),
236
+ Elements: ({ element }) => streaming(sendingElements(element, run))
237
+ });
252
238
  };
253
239
  const byName = {
254
240
  ...Object.fromEntries(bound.map(([action, run]) => [action.name, handlerFor(action, run, stepsOf(action.caller), Schema.Union(bindingErrors(action, binding)))])),
@@ -259,7 +245,7 @@ function layer(binding, served, options = {}) {
259
245
  if (authenticated === void 0 || authenticating === void 0) return servedActions;
260
246
  const authenticate = authenticating(verifyingNative);
261
247
  return Layer.merge(servedActions, Layer.succeed(authenticated)(authenticate));
262
- })).pipe(provideServed(selected));
248
+ })).pipe(provideServed(selected.apps, selected.events));
263
249
  return RpcServer.layer(jsonGroup.merge(binding.rpcs), { disableFatalDefects: true }).pipe(Layer.provide(handlers));
264
250
  }
265
251
  const isDeclared = (failure) => failure instanceof DeclaredFailure;
@@ -1,8 +1,8 @@
1
+ import { Any } from "./Action.mjs";
1
2
  import { Codec } from "./contract/codec.mjs";
2
3
  import { BuiltIns } from "./contract/errors.mjs";
3
4
  import { ActionOf, BuildError, BuildServices, Holding, Known, Member, Offered, OptionalUnless, RequestOf, SelectedOf, ServedActions, Serving } from "./contract/implementation.mjs";
4
5
  import { ToolSuccess } from "./contract/stream.mjs";
5
- import { Any } from "./Action.mjs";
6
6
  import { Effect, Layer, Schema } from "effect";
7
7
  import { Prompt, Tool, Toolkit } from "effect/ai";
8
8
  type NativeTool<A extends Any, R> = Tool.Tool<A["name"], {
@@ -1,10 +1,11 @@
1
1
  import { projectedErrors } from "./contract/declared.mjs";
2
+ import { hintsOf } from "./contract/hints.mjs";
3
+ import { Implementation, acquire, actionKind, answeringWhole, select, toList } from "./contract/implementation.mjs";
4
+ import { liftOf, liftedFrom } from "./contract/lift.mjs";
2
5
  import { assertOnce, heldOnce } from "./contract/names.mjs";
3
6
  import { progressSink } from "./contract/progress.mjs";
7
+ import { provideServed } from "./contract/serving.mjs";
4
8
  import { toolSuccessOf } from "./contract/stream.mjs";
5
- import { Implementation, acquire, answeringWhole, provideHandlers, select, toList } from "./contract/implementation.mjs";
6
- import { hintsOf } from "./contract/hints.mjs";
7
- import { liftOf, liftedFrom } from "./contract/lift.mjs";
8
9
  import { Effect, Schema, SchemaGetter } from "effect";
9
10
  import { Prompt, Tool, Toolkit } from "effect/ai";
10
11
  // src/toolkit/ActionToolkit.ts
@@ -50,7 +51,7 @@ const jsonToolOf = (action) => {
50
51
  });
51
52
  };
52
53
  function make(apps, options) {
53
- const served = select(toList(apps), options?.actions);
54
+ const served = select(actionKind, toList(apps), options?.actions);
54
55
  const needsApproval = options?.needsApproval;
55
56
  assertOnce("tool", served.flatMap((app) => app.actions), heldOnce);
56
57
  const toolOf = (action, app) => Object.assign(needsApproval === void 0 ? jsonToolOf(action) : jsonToolOf(action).setNeedsApproval((input, context) => {
@@ -67,7 +68,7 @@ function make(apps, options) {
67
68
  layer: toolkit.toLayer(Effect.map(acquire(served, void 0), (bound) => Object.fromEntries(bound.map(([action, handler]) => {
68
69
  const run = answeringWhole(action, handler);
69
70
  return [action.name, (input, { preliminary }) => run(input, progressSink((value) => preliminary(new Reported(value))))];
70
- })))).pipe(provideHandlers(served))
71
+ })))).pipe(provideServed(served))
71
72
  };
72
73
  }
73
74
  /**
@@ -1,8 +1,8 @@
1
+ import { Errors } from "./Action.mjs";
1
2
  import { Codec } from "./contract/codec.mjs";
3
+ import { ErrorsOf } from "./contract/declared.mjs";
2
4
  import { Refusal } from "./contract/errors.mjs";
3
5
  import { Known, OptionalUnless } from "./contract/implementation.mjs";
4
- import { Errors } from "./Action.mjs";
5
- import { ErrorsOf } from "./contract/declared.mjs";
6
6
  import { Any, Descriptor, Provider, Security } from "./authentication/provider.mjs";
7
7
  import { Array, Context, Effect, Layer, Option, Redacted, Schema, Scope } from "effect";
8
8
  import { HttpRouter, HttpServerResponse } from "effect/http";
@@ -1,5 +1,5 @@
1
- import { Unauthenticated, builtIns, scopeToken } from "./contract/errors.mjs";
2
1
  import { assertDistinctTags, errorList } from "./contract/declared.mjs";
2
+ import { Unauthenticated, builtIns, scopeToken } from "./contract/errors.mjs";
3
3
  import { providerOf } from "./authentication/provider.mjs";
4
4
  import { answer, answerStepUp, bearer, challenge, declaredResponse, isRefusal, isStepUp, plain } from "./authentication/refusal.mjs";
5
5
  import { Context, Effect, Function, Layer, Match, Option, Predicate, Redacted } from "effect";
@@ -25,12 +25,6 @@ const namedOf = (options) => ({
25
25
  scope: options?.scopesRequired?.join(" "),
26
26
  metadataUrl: options === void 0 ? void 0 : metadataUrlOf(options).href
27
27
  });
28
- const presentsBearerToken = (authorization) => Option.isSome(bearerTokenOf(authorization));
29
- const bearerChallengeOf = (named, presented) => bearer([
30
- ["error", presented ? "invalid_token" : void 0],
31
- ["scope", named.scope],
32
- ["resource_metadata", named.metadataUrl]
33
- ]);
34
28
  const assertPublishableResource = (oauth, options) => {
35
29
  if (options === void 0) return;
36
30
  if (!oauth) throw new Error("A protected resource is published only for a Bearer scheme: drop `protectedResource`, or authenticate with a Bearer descriptor");
@@ -50,6 +44,32 @@ const withNoStoreAndChallenge = (response, wwwAuthenticate) => HttpServerRespons
50
44
  const isBearer = (security) => Predicate.isTagged(security, "Http") && security.scheme.toLowerCase() === "bearer";
51
45
  const openApiComponentKey = /^[\w.-]+$/u;
52
46
  const nonBearerChallengeOf = (security, name) => Match.value(security).pipe(Match.tag("Http", ({ scheme }) => challenge(scheme, [])), Match.tag("Basic", () => challenge("Basic", [["realm", name]])), Match.tag("ApiKey", Function.constUndefined), Match.exhaustive);
47
+ const refusingOf = (authentication, resource) => {
48
+ const oauth = authentication === void 0 || isBearer(authentication.security);
49
+ assertPublishableResource(oauth, resource);
50
+ const { scope, metadataUrl } = namedOf(resource);
51
+ const bearerChallenge = (presented) => bearer([
52
+ ["error", presented ? "invalid_token" : void 0],
53
+ ["scope", scope],
54
+ ["resource_metadata", metadataUrl]
55
+ ]);
56
+ const invalid = bearerChallenge(true);
57
+ const anonymous = bearerChallenge(false);
58
+ const other = authentication === void 0 || oauth ? void 0 : nonBearerChallengeOf(authentication.security, authentication.name);
59
+ return {
60
+ missing: new Unauthenticated({ message: oauth ? "A bearer token is required." : "A credential is required." }),
61
+ challenge: (presented) => {
62
+ if (!oauth) return other;
63
+ return presented ? invalid : anonymous;
64
+ },
65
+ response: (error) => {
66
+ if (!isRefusal(error)) return declaredResponse(authentication?.error ?? [], error);
67
+ return oauth ? answer(error, metadataUrl) : plain(error);
68
+ },
69
+ stepUp: (route) => oauth ? Effect.catchIf(route, isStepUp, (error) => Effect.succeed(answer(error, metadataUrl))) : route,
70
+ answeringStepUp: (route) => oauth ? answerStepUp(route, metadataUrl) : route
71
+ };
72
+ };
53
73
  /**
54
74
  * The response `layer` answers a refusal with, for a caller the router never routes, such as a
55
75
  * Node `upgrade` handler admitting a socket, which holds a header and no request: read its token
@@ -59,17 +79,10 @@ const nonBearerChallengeOf = (security, name) => Match.value(security).pipe(Matc
59
79
  * naming scopes. `HttpServerResponse.toWeb` gives it as a web `Response`.
60
80
  */
61
81
  const refusalResponse = (error, options) => {
62
- const authentication = options?.authentication;
63
- const oauth = authentication === void 0 || isBearer(authentication.security);
64
- assertPublishableResource(oauth, options?.protectedResource);
65
- const named = namedOf(options?.protectedResource);
66
- const wwwAuthenticate = authentication !== void 0 && !oauth ? nonBearerChallengeOf(authentication.security, authentication.name) : bearerChallengeOf(named, presentsBearerToken(options?.authorization));
67
- if (!isRefusal(error)) {
68
- const response = declaredResponse(authentication?.error ?? [], error);
69
- if (response === void 0) throw new Error("Not a refusal, nor an error the authentication declares: pass the descriptor declaring it as `authentication`, or answer the error yourself");
70
- return withNoStoreAndChallenge(response, wwwAuthenticate);
71
- }
72
- return withNoStoreAndChallenge(oauth ? answer(error, named.metadataUrl) : plain(error), wwwAuthenticate);
82
+ const refusing = refusingOf(options?.authentication, options?.protectedResource);
83
+ const response = refusing.response(error);
84
+ if (response === void 0) throw new Error("Not a refusal, nor an error the authentication declares: pass the descriptor declaring it as `authentication`, or answer the error yourself");
85
+ return withNoStoreAndChallenge(response, refusing.challenge(Option.isSome(bearerTokenOf(options?.authorization))));
73
86
  };
74
87
  const mayResolveToDiscoveryPath = /\.well-known|[\t\n\r]/u;
75
88
  const corsPreflight = (request) => {
@@ -103,15 +116,6 @@ const discoveryMiddleware = (options) => {
103
116
  return next;
104
117
  });
105
118
  };
106
- const resourceAnswersOf = (options) => {
107
- const named = namedOf(options);
108
- return {
109
- metadataUrl: named.metadataUrl,
110
- invalid: bearerChallengeOf(named, true),
111
- anonymous: bearerChallengeOf(named, false),
112
- published: options === void 0 ? void 0 : discoveryMiddleware(options)
113
- };
114
- };
115
119
  /**
116
120
  * Browser-safe declaration shared by clients and remote surfaces: the `identity` it
117
121
  * authenticates, and the scheme a caller proves it by, `Options.security`. The literal name
@@ -142,31 +146,25 @@ const make = (name, identity, ...options) => {
142
146
  const presented = (credential) => Redacted.isRedacted(credential) ? Redacted.value(credential) !== "" : credential.username !== "" || Redacted.value(credential.password) !== "";
143
147
  function layer(authentication, verify, options = {}) {
144
148
  const { security } = authentication;
145
- const oauth = isBearer(security);
146
149
  const { protectedResource } = options;
147
- assertPublishableResource(oauth, protectedResource);
148
- const resource = Effect.isEffect(protectedResource) ? Effect.map(protectedResource, (built) => {
149
- assertPublishableResource(oauth, built);
150
- return resourceAnswersOf(built);
151
- }) : Effect.succeed(resourceAnswersOf(protectedResource));
152
- const missing = new Unauthenticated({ message: oauth ? "A bearer token is required." : "A credential is required." });
150
+ const published = (built) => ({
151
+ refusing: refusingOf(authentication, built),
152
+ discovery: built === void 0 ? void 0 : discoveryMiddleware(built)
153
+ });
154
+ const resource = Effect.isEffect(protectedResource) ? Effect.map(protectedResource, published) : Effect.succeed(published(protectedResource));
153
155
  return Layer.effect(authentication["~provider"], Effect.gen(function* () {
154
- const { metadataUrl, invalid, anonymous, published } = yield* resource;
155
- if (published !== void 0) yield* (yield* HttpRouter.HttpRouter).addGlobalMiddleware(published);
156
+ const { refusing, discovery } = yield* resource;
157
+ if (discovery !== void 0) yield* (yield* HttpRouter.HttpRouter).addGlobalMiddleware(discovery);
156
158
  const verifier = Effect.isEffect(verify) ? yield* verify : verify;
157
159
  if (!Predicate.isFunction(verifier)) return yield* Effect.die(/* @__PURE__ */ new Error("Missing verify: pass a verify function, or an Effect building one"));
158
- const authenticate = (credential) => presented(credential) ? verifier(credential) : Effect.fail(missing);
160
+ const authenticate = (credential) => presented(credential) ? verifier(credential) : Effect.fail(refusing.missing);
159
161
  const noStoreOnFailure = HttpEffect.appendPreResponseHandler((_request, response) => Effect.succeed(HttpServerResponse.setHeader(response, "cache-control", "no-store")));
160
- const challengeOf = (credential) => {
161
- if (!oauth) return nonBearerChallengeOf(security, authentication.name);
162
- return presented(credential) ? invalid : anonymous;
163
- };
164
- const refuse = (error) => isRefusal(error) ? Effect.succeed(oauth ? answer(error, metadataUrl) : plain(error)) : Effect.suspend(() => {
165
- const response = declaredResponse(authentication.error, error);
162
+ const refuse = (error) => Effect.suspend(() => {
163
+ const response = refusing.response(error);
166
164
  return response === void 0 ? Effect.die(error) : Effect.succeed(response);
167
165
  });
168
166
  const verified = (credential, route, slot) => {
169
- const wwwAuthenticate = challengeOf(credential);
167
+ const wwwAuthenticate = refusing.challenge(presented(credential));
170
168
  return Effect.matchEffect(authenticate(credential), {
171
169
  onFailure: refuse,
172
170
  onSuccess: (actor) => Effect.provideService(route, slot, actor)
@@ -176,8 +174,8 @@ function layer(authentication, verify, options = {}) {
176
174
  descriptor: authentication,
177
175
  authenticate,
178
176
  middleware: { [authentication.name]: (route, { credential }) => verified(credential, route, authentication.identity) },
179
- stepUp: (route) => oauth ? Effect.catchIf(route, isStepUp, (error) => Effect.succeed(answer(error, metadataUrl))) : route,
180
- http: ((route, optional) => Effect.flatMap(HttpApiBuilder.securityDecode(security), (credential) => optional && !presented(credential) ? route : verified(credential, oauth ? answerStepUp(route, metadataUrl) : route, authentication["~verified"]))),
177
+ stepUp: refusing.stepUp,
178
+ http: ((route, optional) => Effect.flatMap(HttpApiBuilder.securityDecode(security), (credential) => optional && !presented(credential) ? route : verified(credential, refusing.answeringStepUp(route), authentication["~verified"]))),
181
179
  route: ((route) => Effect.flatMap(HttpApiBuilder.securityDecode(security), (credential) => verified(credential, Effect.catchIf(route, isRefusal, refuse), authentication.identity)))
182
180
  };
183
181
  }));
package/dist/Event.d.mts CHANGED
@@ -1,12 +1,12 @@
1
+ import { Options as Options$1 } from "./Action.mjs";
2
+ import { Authorizer, Deferred as Deferred$1 } from "./contract/authorizer.mjs";
1
3
  import { Codec, CodecOf, Fields, NoInput } from "./contract/codec.mjs";
2
4
  import { Refusal } from "./contract/errors.mjs";
3
- import { Gap, OccurrenceSchema } from "./contract/occurrence.mjs";
4
5
  import { AnyEventImplementation, EventImplementation } from "./contract/feed.mjs";
5
- import { Listed, LogStorage } from "./contract/log.mjs";
6
6
  import { Events, KeyOptions, MakeEventsOptions, RevisionStorage, layerMemory, makeEvents } from "./contract/hub.mjs";
7
7
  import { Protected } from "./contract/implementation.mjs";
8
- import { Authorizer, Deferred as Deferred$1 } from "./contract/authorizer.mjs";
9
- import { Options as Options$1 } from "./Action.mjs";
8
+ import { Gap, OccurrenceSchema } from "./contract/occurrence.mjs";
9
+ import { Listed, LogStorage } from "./contract/log.mjs";
10
10
  import { DateTime, Duration, Effect, Schema, Scope, Stream } from "effect";
11
11
  declare const TypeId = "~@gjermundgaraba/effect-actions/Event";
12
12
  /** What `make` needs to define an event type. */
package/dist/Event.mjs CHANGED
@@ -1,10 +1,10 @@
1
+ import { authorizerOf } from "./contract/authorizer.mjs";
1
2
  import { Anyone, assertCaller } from "./contract/caller.mjs";
2
- import { assertEventName, assertOnce } from "./contract/names.mjs";
3
3
  import { codecOf } from "./contract/codec.mjs";
4
- import { authorizerOf } from "./contract/authorizer.mjs";
4
+ import { EventImplementation, sourcesOf } from "./contract/feed.mjs";
5
+ import { assertEventName, assertOnce } from "./contract/names.mjs";
5
6
  import { Events, layerMemory, makeEvents } from "./contract/hub.mjs";
6
7
  import { Gap } from "./contract/occurrence.mjs";
7
- import { EventImplementation, sourcesOf } from "./contract/feed.mjs";
8
8
  import { Array as Array$1, Data, Effect, Match, Predicate, Schema } from "effect";
9
9
  // src/contract/Event.ts
10
10
  const TypeId = "~@gjermundgaraba/effect-actions/Event";
@@ -89,6 +89,7 @@ export interface Options {
89
89
  * - An occurrence given up, its body over 256 KiB or its POST answered `410` or `413`, is POSTed as a `gap` at its cursor; one whose admission fails with no refusal is reported and read again, from before it, every 5 seconds.
90
90
  * - A refresh restarts its subscription's reading under the refreshed subscriber, from where delivery reached: the subscription hook set up again once the old one is released, and a delivery in flight sent again, which the subscriber drops by its `eventId`.
91
91
  * - A refresh its authorizer refuses ends the subscription it names, POSTing `terminated`, though each delivery, admitted as the subscriber of the last grant, would still pass.
92
+ * - A `terminated` POST is tried four times, and one never accepted is logged as a warning naming the subscription; one answered `410` or `413` is given up at once, unlogged.
92
93
  * - A refresh with a new secret signs each POST with both secrets for 5 minutes, `webhook-signature` holding two, so a receiver may switch over; after that, with the new one alone.
93
94
  * - A delivery runs in the subscribe request's context without the request: an authorizer or a source reading `HttpServerRequest` fails in a delivery, so read what it needs in middleware, which provides it as a service.
94
95
  * - `allowedCallbacks` throws when `layer` is called for an entry that is not an https URL.
@@ -121,6 +122,7 @@ export type DeliveryOptions = ConstructorParameters<typeof WebhookDelivery>[0];
121
122
  * - A server refuses a callback that is not globally reachable, so `baseUrl` is a public name of this process, such as a tunnel's in development.
122
123
  * - The URL subscribed carries a `watch` query parameter, one per watch, so watches never share a subscription: a proxy in front of the route must pass the query on.
123
124
  * - A restarted process subscribes afresh from the cursor `resume` kept, so the server sends again what the last process accepted and never handed on; the old subscription lapses at its grant, each delivery to it answered 410.
125
+ * - An unsubscribe that fails, or is not answered within 5 seconds, is not reported: the subscription lapses at its grant, as a restarted process's does.
124
126
  */
125
127
  export declare const delivery: (options: DeliveryOptions) => WebhookDelivery;
126
128
  /** Where `layerReceiver` serves its route. */
package/dist/Webhook.mjs CHANGED
@@ -49,6 +49,7 @@ function layer(options = {}) {
49
49
  * - A server refuses a callback that is not globally reachable, so `baseUrl` is a public name of this process, such as a tunnel's in development.
50
50
  * - The URL subscribed carries a `watch` query parameter, one per watch, so watches never share a subscription: a proxy in front of the route must pass the query on.
51
51
  * - A restarted process subscribes afresh from the cursor `resume` kept, so the server sends again what the last process accepted and never handed on; the old subscription lapses at its grant, each delivery to it answered 410.
52
+ * - An unsubscribe that fails, or is not answered within 5 seconds, is not reported: the subscription lapses at its grant, as a restarted process's does.
52
53
  */
53
54
  const delivery = (options) => new WebhookDelivery(options);
54
55
  /**