@spine-event-engine/auth 2.0.0-snapshot.2

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 (57) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +112 -0
  3. package/REFERENCE.md +94 -0
  4. package/dist/gateway/dynamic-subscription-creator.d.ts +52 -0
  5. package/dist/gateway/dynamic-subscription-creator.d.ts.map +1 -0
  6. package/dist/gateway/dynamic-subscription-creator.js +71 -0
  7. package/dist/gateway/dynamic-subscription-creator.js.map +1 -0
  8. package/dist/gateway/dynamic-unary-forwarder.d.ts +130 -0
  9. package/dist/gateway/dynamic-unary-forwarder.d.ts.map +1 -0
  10. package/dist/gateway/dynamic-unary-forwarder.js +185 -0
  11. package/dist/gateway/dynamic-unary-forwarder.js.map +1 -0
  12. package/dist/gateway/index.d.ts +164 -0
  13. package/dist/gateway/index.d.ts.map +1 -0
  14. package/dist/gateway/index.js +195 -0
  15. package/dist/gateway/index.js.map +1 -0
  16. package/dist/index.d.ts +433 -0
  17. package/dist/index.d.ts.map +1 -0
  18. package/dist/index.js +56 -0
  19. package/dist/index.js.map +1 -0
  20. package/dist/native/index.d.ts +182 -0
  21. package/dist/native/index.d.ts.map +1 -0
  22. package/dist/native/index.js +463 -0
  23. package/dist/native/index.js.map +1 -0
  24. package/dist/oidc/contracts.d.ts +334 -0
  25. package/dist/oidc/contracts.d.ts.map +1 -0
  26. package/dist/oidc/contracts.js +15 -0
  27. package/dist/oidc/contracts.js.map +1 -0
  28. package/dist/oidc/index.d.ts +41 -0
  29. package/dist/oidc/index.d.ts.map +1 -0
  30. package/dist/oidc/index.js +825 -0
  31. package/dist/oidc/index.js.map +1 -0
  32. package/dist/providers/index.d.ts +154 -0
  33. package/dist/providers/index.d.ts.map +1 -0
  34. package/dist/providers/index.js +574 -0
  35. package/dist/providers/index.js.map +1 -0
  36. package/dist/request/index.d.ts +10 -0
  37. package/dist/request/index.d.ts.map +1 -0
  38. package/dist/request/index.js +81 -0
  39. package/dist/request/index.js.map +1 -0
  40. package/dist/sessions/cookies.d.ts +104 -0
  41. package/dist/sessions/cookies.d.ts.map +1 -0
  42. package/dist/sessions/cookies.js +295 -0
  43. package/dist/sessions/cookies.js.map +1 -0
  44. package/dist/sessions/opaque.d.ts +163 -0
  45. package/dist/sessions/opaque.d.ts.map +1 -0
  46. package/dist/sessions/opaque.js +268 -0
  47. package/dist/sessions/opaque.js.map +1 -0
  48. package/dist/sessions/signed.d.ts +245 -0
  49. package/dist/sessions/signed.d.ts.map +1 -0
  50. package/dist/sessions/signed.js +534 -0
  51. package/dist/sessions/signed.js.map +1 -0
  52. package/dist/subscriptions/index.d.ts +463 -0
  53. package/dist/subscriptions/index.d.ts.map +1 -0
  54. package/dist/subscriptions/index.js +814 -0
  55. package/dist/subscriptions/index.js.map +1 -0
  56. package/dist/tsconfig.tsbuildinfo +1 -0
  57. package/package.json +37 -0
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,112 @@
1
+ # Authentication for Spine applications
2
+
3
+ Use this package to build an application gateway that authenticates a request,
4
+ authorizes it, resolves a trusted actor context, and forwards approved Spine
5
+ traffic. Spine bounded contexts do not perform these routines themselves.
6
+
7
+ For gateway, session, OIDC, subscription, and native-transport details, read
8
+ the [reference](REFERENCE.md).
9
+
10
+ ## 💡 Why use it?
11
+
12
+ - ✅ Keeps credentials outside bounded contexts.
13
+ - ✅ Turns a verified session into a trusted actor and optional tenant.
14
+ - ✅ Supports bearer sessions, CSRF-protected opaque cookies, and application
15
+ adapters for Google, GitHub, or another OpenID Connect provider.
16
+ - ✅ Applies the same authorization boundary to commands, queries, and
17
+ subscriptions.
18
+
19
+ The [browser client and gateway guide](../../docs/BROWSER_CLIENT_AUTH_EXTENSION_GUIDE.md)
20
+ explains how an application composes these extension points.
21
+
22
+ ## 🚀 Build a unary gateway
23
+
24
+ Supply application session, authorization, context, and forwarding
25
+ collaborators. The gateway replaces a matching caller context with a freshly
26
+ resolved trusted `ActorContext`; it never forwards the credential.
27
+
28
+ ```ts
29
+ import { type SessionResolver, UnaryGateway } from "@spine-event-engine/auth";
30
+
31
+ const gateway = new UnaryGateway({
32
+ maxRequestBytes: 1_048_576,
33
+ sessions: applicationSessions,
34
+ authorize: applicationPolicy.authorize,
35
+ contexts: applicationContexts,
36
+ clock: applicationClock,
37
+ forward: applicationBackend.forward,
38
+ });
39
+
40
+ declare const applicationSessions: SessionResolver;
41
+ declare const applicationPolicy: {
42
+ authorize: ConstructorParameters<typeof UnaryGateway>[0]["authorize"];
43
+ };
44
+ declare const applicationContexts: ConstructorParameters<typeof UnaryGateway>[0]["contexts"];
45
+ declare const applicationClock: ConstructorParameters<typeof UnaryGateway>[0]["clock"];
46
+ declare const applicationBackend: {
47
+ forward: ConstructorParameters<typeof UnaryGateway>[0]["forward"];
48
+ };
49
+ void gateway;
50
+ ```
51
+
52
+ For an intentionally public endpoint, replace `sessions` with
53
+ `publicAccess: true`. The two admission modes are mutually exclusive. Public
54
+ mode has no login session or synthetic expiry; the application still authorizes
55
+ every operation and rebuilds trusted context.
56
+
57
+ The package gives applications extension points, not a deployment mandate or an
58
+ identity-provider configuration. Applications choose their listener, routes,
59
+ session persistence, identity provider, authorization rules, and backend.
60
+
61
+ ## 🧪 Use a local session store in development
62
+
63
+ `OpaqueSessions` is a process-local store. It is useful for a local gateway or
64
+ a single process, not for a shared production deployment.
65
+
66
+ ```ts
67
+ import { OpaqueSessions } from "@spine-event-engine/auth";
68
+
69
+ const sessions = new OpaqueSessions({
70
+ ttlMilliseconds: 60 * 60 * 1_000,
71
+ maxSessions: 1_000,
72
+ });
73
+
74
+ await sessions.close();
75
+ ```
76
+
77
+ For browser clients, use an application sign-in route and exchange its result
78
+ for an application cookie or bearer session. Do not put provider access tokens
79
+ in client-side storage.
80
+
81
+ ## 🔐 Configure an external sign-in provider
82
+
83
+ An application can create a Google or GitHub provider adapter, then give its
84
+ verified identity result to an `OidcFlow` and application session issuer. The
85
+ [OIDC composition section](../../docs/BROWSER_CLIENT_AUTH_EXTENSION_GUIDE.md#external-provider-sign-in)
86
+ shows the complete start, callback, and one-time session-exchange flow. These
87
+ helpers configure bounded provider calls; they do not create browser routes,
88
+ users, permissions, or a session issuer.
89
+
90
+ ```ts
91
+ import { createGitHubProvider, createGoogleProvider } from "@spine-event-engine/auth";
92
+
93
+ const google = await createGoogleProvider({ clientId: "google-client-id" });
94
+ const github = createGitHubProvider({
95
+ clientId: "github-client-id",
96
+ clientSecret: "server-only-secret",
97
+ });
98
+ if (google === undefined) throw new Error("Google provider discovery failed");
99
+ void github;
100
+ ```
101
+
102
+ ## ⚠️ What the package does not do
103
+
104
+ It does not create sign-in pages, application users, permissions, HTTP routes,
105
+ TLS, or a production session database. Applications select those pieces and
106
+ deploy the gateway at the appropriate trust boundary.
107
+
108
+ ## 🔗 Learn more
109
+
110
+ - [Browser authentication and extension guide](../../docs/BROWSER_CLIENT_AUTH_EXTENSION_GUIDE.md)
111
+ - [Server package](../server/README.md)
112
+ - [Detailed coding-agent reference](REFERENCE.md)
package/REFERENCE.md ADDED
@@ -0,0 +1,94 @@
1
+ # @spine-event-engine/auth reference
2
+
3
+ This reference records the exact public contract of `@spine-event-engine/auth`.
4
+ Start with the [authentication overview](README.md) when choosing a gateway shape.
5
+
6
+ ## Purpose and trust boundary
7
+
8
+ The package supplies provider-neutral gateway building blocks. An application places its gateway in front of a Spine TS or Spine JVM backend, then supplies the listener, credential extraction, identity provider, session storage, authorization rules, actor/tenant resolution, and forwarding implementation. The framework does not enforce a particular proxy, route topology, identity provider, tenant policy, or deployment configuration.
9
+
10
+ `TransportFacts.from()` exposes only allowlisted request facts. Credentials are passed only to `Authenticator` or `SessionResolver`; they are not included in `IncomingRequest`. `IncomingRequest` is a discriminated union for command, query, subscription creation, activation, and cancellation. Command facts can include a decoded message when a `TypeRegistryLookup` knows its packed type; unknown and malformed `Any` values remain type-URL-only facts.
11
+
12
+ `AuthorizationPolicy.authorize()` is evaluated separately for each incoming request. `ContextResolver.resolve()` returns the trusted actor, optional tenant, timestamp, zone, and language. The caller-provided `ActorContext` must match that resolved actor and tenant, otherwise `UnaryGateway` rejects the request as `context-stale`. Backends can trust the forwarded, gateway-replaced context only when the deployment routes traffic through an application-selected gateway.
13
+
14
+ ## Dynamic subscription membership
15
+
16
+ A standalone browser Gateway uses one complete membership owner for commands,
17
+ queries, and native subscription streams. A fixed backend list is static
18
+ membership input and is not capped; dynamic discovery replaces it with later
19
+ complete snapshots. Notices can be duplicated, missing, or lost.
20
+ Browser code must treat notices as refresh hints and use Queries as the
21
+ authoritative state source. The owner keeps one native child stream for every
22
+ active logical subscription on every current node. Membership changes converge
23
+ through one latest-only generation owner: removed or stale nodes cannot revive
24
+ their children, while a zero-node interval retains an existing definition for
25
+ later recovery. New subscription creation reports backend unavailability while
26
+ membership is empty.
27
+
28
+ ## Unary requests
29
+
30
+ `UnaryGateway` accepts `CommandService.Post`, `QueryService.Read`, and
31
+ `AuthenticationService.ResolveContext`. Construct both `UnaryGateway` and
32
+ `SubscriptionGateway` with exactly one admission mode: a `SessionResolver`, or
33
+ `publicAccess: true`. Public access creates no login session and no synthetic
34
+ expiry. It is appropriate only when the application deliberately exposes the
35
+ Gateway, its authorization policy admits the public principal, and its
36
+ `ContextResolver` reconstructs trusted context from request facts. Both modes
37
+ also require finite request limits, an authorization function,
38
+ `ContextResolver`, clock, and the corresponding forwarding collaborator.
39
+
40
+ For Post and Read, it bounds and decodes bytes, admits the request through the selected mode, authorizes the decoded request, resolves trusted context, checks requested actor/tenant, and forwards exactly once. In authenticated mode, admission resolves the supplied session. In public mode, it uses the framework-owned public principal and no session. The forwarder receives only service, method, bytes, and optional cancellation signal. It does not receive credentials or extra transport facts. It returns `forwarded`, `resolved`, or a rejection reason: `request-too-large`, `unknown-operation`, `malformed-request`, `unauthenticated`, `forbidden`, or `context-stale`. Mapping a rejection to HTTP or gRPC status is the native transport adapter's job.
41
+
42
+ ResolveContext returns informational trusted actor and tenant facts in both modes. In authenticated mode, it validates the current session and also returns its expiry. In public mode, it resolves context for the framework-owned public principal and omits `expiresAt` because no session exists. It neither authorizes a business request nor creates a reusable credential. Later requests are independently admitted and authorized.
43
+
44
+ ## Sessions and sign-in
45
+
46
+ `OpaqueSessions` implements a bounded, process-local `SessionResolver` with random cookie credentials. Defaults are an eight-hour lifetime, 10,000 retained sessions, and three identifier attempts. It lazily removes expired entries and is terminal after `close()`. It suits local development and the supported single-Gateway shape; choose an application session strategy that meets that gateway's restart and revocation requirements.
47
+
48
+ `SignedSessions` provides signed application session tokens. Local signature validation can delay revocation; shared revocation requires an explicit `SignedTokenRevocation` implementation. `OpaqueSessionCookies` supplies strict cookie parsing and serialization helpers. Neither strategy provisions users nor grants permissions.
49
+
50
+ `OidcFlow` is a bounded authorization-code and PKCE transaction manager. It works with `createGoogleProvider`, `createGitHubProvider`, or a discovered or configured OIDC provider. Applications expose start/callback/exchange endpoints, perform HTTP routing, map verified external identity through `IdentityMapping`, and issue an application session through `ApplicationSessionIssuer`. Provider access, refresh, and ID tokens remain sensitive server-side material; do not return them to browser application code.
51
+
52
+ ## Subscription and native adapters
53
+
54
+ `SubscriptionGateway` and `InMemorySubscriptionBindings` compose subscription creation, activation, cancellation, and relaying at the gateway boundary. The Gateway accepts a logical `SubscriptionCoordinator`; native `SubscriptionCreator` instances remain a per-node implementation seam. This is an intentional replacement of the former public native-creator input, with no compatibility adapter because Spine TS has no deployed users. In-memory bindings are local to one process and have finite operation limits; they do not provide cross-machine propagation. `createNativeGatewayServices`, `NativeSubscriptionCreator`, and `SubscriptionUpdateRelay` adapt these public contracts to the native service layer. They do not make a deployment secure by themselves: applications choose how their listener accepts only gateway-routed traffic.
55
+
56
+ `DurableSubscriptionBindings` in the Server package retains one approved
57
+ `GatewayAuthenticatedSubscription` per public Subscription. The retained Topic
58
+ includes the trusted Actor and Tenant, so Activate and Cancel compare that pair
59
+ with the newly resolved request context. It is single-Gateway persistence, not
60
+ cross-process quota, reservation, lease, fence, or fingerprint coordination.
61
+
62
+ Public subscription creation has two stages. `Subscribe` stores a process-local
63
+ definition and returns its ID; `Activate` must arrive within the shared
64
+ 30-second incomplete Subscribe-to-Activate handshake. If activation never
65
+ arrives, that public definition is cancelled. Once activated, a healthy public
66
+ stream has no framework time-to-live. It ends only when the caller cancels or
67
+ disconnects, the backend ends the stream, or the Gateway shuts down.
68
+
69
+ Authenticated durable definitions instead use the real session-derived expiry
70
+ stored with the definition. Expiry maintenance first stops an active binding,
71
+ waits for its serialized work, cancels the backend subscription once, and then
72
+ deletes the stored record. Concurrent maintenance callers join the same purge
73
+ operation. Public mode has no session expiry and does not use that durable
74
+ authenticated record; its process-local definitions disappear when the Gateway
75
+ process ends. Neither mode stores a replayable history of emitted updates, so a
76
+ reconnecting browser queries authoritative state before subscribing again.
77
+
78
+ ## Errors, lifecycle, and extension
79
+
80
+ Public callbacks may reject; applications decide how their native listener maps those failures. Values handed to request collaborators are defensive gateway facts, while applications remain responsible for mutable state and cleanup. Always give gateway operations a finite request limit and make credential, provider, session, and forwarding adapters cancellation-aware.
81
+
82
+ Read the [browser client and gateway guide](../../docs/BROWSER_CLIENT_AUTH_EXTENSION_GUIDE.md) for composition examples and deployment guidance.
83
+
84
+ # Dynamic unary discovery
85
+
86
+ `DynamicUnaryForwarder` accepts complete current application-node snapshots. It serializes reconciliation, retains only the latest pending snapshot during churn, starts clients in bounded batches, disposes departed clients, and round-robins commands and queries across the resulting set. A dispatched unary request is never retried. Empty membership reports backend unavailability until a later snapshot restores clients.
87
+
88
+ Dynamic subscriptions use the same reconciliation owner. Durable bindings retain
89
+ the logical subscription definition and trusted Actor/Tenant facts only; native streams are
90
+ ephemeral per-node work. Nodes may be added, removed, or re-added without
91
+ changing a durable definition. Notifications are best effort, may duplicate,
92
+ and browser clients reconnect and re-query authoritative state after loss.
93
+
94
+ Closing the forwarder aborts in-flight client creation, waits for that work to settle, and cleans up current clients. Failed cleanup remains retryable on a later close.
@@ -0,0 +1,52 @@
1
+ import type { PublicSubscriptionWire, SubscriptionCoordinator, SubscriptionUpdateSink } from "../subscriptions/index.js";
2
+ import { DynamicUnaryForwarder } from "./dynamic-unary-forwarder.js";
3
+ /**
4
+ * Adapts logical subscriptions to the shared dynamic membership owner.
5
+ */
6
+ export declare class DynamicSubscriptionCreator implements SubscriptionCoordinator {
7
+ #private;
8
+ /**
9
+ * Creates the adapter for one shared dynamic owner.
10
+ *
11
+ * @param owner Serializes node and subscription reconciliation.
12
+ */
13
+ constructor(owner: DynamicUnaryForwarder);
14
+ /**
15
+ * Restores a retained durable definition into the current native membership.
16
+ *
17
+ * @param definition Supplies the retained canonical definition.
18
+ * @returns Completes after child creation settles.
19
+ */
20
+ rehydrate(definition: PublicSubscriptionWire): Promise<void>;
21
+ /**
22
+ * Creates native children for one logical definition across current membership.
23
+ *
24
+ * @param request Supplies the canonical public definition.
25
+ * @param signal Cancels child creation.
26
+ * @param maxBackendEnvelopeBytes Limits every native child envelope.
27
+ * @returns Completes after all current native children are installed.
28
+ */
29
+ subscribe(request: PublicSubscriptionWire, signal: AbortSignal, maxBackendEnvelopeBytes?: number): Promise<void>;
30
+ /**
31
+ * Activates native children and relays their updates until cancellation.
32
+ *
33
+ * @param request Supplies the definition and update relay.
34
+ * @param signal Ends active child streams.
35
+ * @returns Completes after the active relay ends.
36
+ */
37
+ activate(request: {
38
+ readonly wire: PublicSubscriptionWire;
39
+ readonly updates: SubscriptionUpdateSink;
40
+ }, signal: AbortSignal): Promise<void>;
41
+ /**
42
+ * Cancels every native child for a logical definition.
43
+ *
44
+ * @param request Supplies the definition to cancel.
45
+ * @param signal Cancels cleanup.
46
+ * @returns Completes after child cleanup settles.
47
+ */
48
+ cancel(request: {
49
+ readonly wire: PublicSubscriptionWire;
50
+ }, signal: AbortSignal): Promise<void>;
51
+ }
52
+ //# sourceMappingURL=dynamic-subscription-creator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dynamic-subscription-creator.d.ts","sourceRoot":"","sources":["../../src/gateway/dynamic-subscription-creator.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EACV,sBAAsB,EACtB,uBAAuB,EACvB,sBAAsB,EACvB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAErE;;GAEG;AACH,qBAAa,0BAA2B,YAAW,uBAAuB;;IAGxE;;;;OAIG;gBACS,KAAK,EAAE,qBAAqB;IAIxC;;;;;OAKG;IACH,SAAS,CAAC,UAAU,EAAE,sBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC;IAI5D;;;;;;;OAOG;IACH,SAAS,CACP,OAAO,EAAE,sBAAsB,EAC/B,MAAM,EAAE,WAAW,EACnB,uBAAuB,CAAC,EAAE,MAAM,GAC/B,OAAO,CAAC,IAAI,CAAC;IAIhB;;;;;;OAMG;IACH,QAAQ,CACN,OAAO,EAAE;QACP,QAAQ,CAAC,IAAI,EAAE,sBAAsB,CAAC;QACtC,QAAQ,CAAC,OAAO,EAAE,sBAAsB,CAAC;KAC1C,EACD,MAAM,EAAE,WAAW,GAClB,OAAO,CAAC,IAAI,CAAC;IAKhB;;;;;;OAMG;IACH,MAAM,CAAC,OAAO,EAAE;QAAE,QAAQ,CAAC,IAAI,EAAE,sBAAsB,CAAA;KAAE,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;CAG/F"}
@@ -0,0 +1,71 @@
1
+ /*
2
+ * Copyright 2026, CodeMatters. All rights reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5
+ * in compliance with the License. You may obtain a copy of the License at
6
+ *
7
+ * https://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
10
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11
+ * or implied. See the License for the specific language governing permissions and limitations under
12
+ * the License.
13
+ */
14
+ import { DynamicUnaryForwarder } from "./dynamic-unary-forwarder.js";
15
+ /**
16
+ * Adapts logical subscriptions to the shared dynamic membership owner.
17
+ */
18
+ export class DynamicSubscriptionCreator {
19
+ #owner;
20
+ /**
21
+ * Creates the adapter for one shared dynamic owner.
22
+ *
23
+ * @param owner Serializes node and subscription reconciliation.
24
+ */
25
+ constructor(owner) {
26
+ this.#owner = owner;
27
+ }
28
+ /**
29
+ * Restores a retained durable definition into the current native membership.
30
+ *
31
+ * @param definition Supplies the retained canonical definition.
32
+ * @returns Completes after child creation settles.
33
+ */
34
+ rehydrate(definition) {
35
+ return this.#owner.rehydrateDefinition(definition);
36
+ }
37
+ /**
38
+ * Creates native children for one logical definition across current membership.
39
+ *
40
+ * @param request Supplies the canonical public definition.
41
+ * @param signal Cancels child creation.
42
+ * @param maxBackendEnvelopeBytes Limits every native child envelope.
43
+ * @returns Completes after all current native children are installed.
44
+ */
45
+ subscribe(request, signal, maxBackendEnvelopeBytes) {
46
+ return this.#owner.subscribeDefinition(request, signal, maxBackendEnvelopeBytes);
47
+ }
48
+ /**
49
+ * Activates native children and relays their updates until cancellation.
50
+ *
51
+ * @param request Supplies the definition and update relay.
52
+ * @param signal Ends active child streams.
53
+ * @returns Completes after the active relay ends.
54
+ */
55
+ activate(request, signal) {
56
+ if (signal.aborted)
57
+ return Promise.resolve();
58
+ return this.#owner.activateDefinition(request.wire, request.updates, signal);
59
+ }
60
+ /**
61
+ * Cancels every native child for a logical definition.
62
+ *
63
+ * @param request Supplies the definition to cancel.
64
+ * @param signal Cancels cleanup.
65
+ * @returns Completes after child cleanup settles.
66
+ */
67
+ cancel(request, signal) {
68
+ return this.#owner.cancelDefinition(request.wire, signal);
69
+ }
70
+ }
71
+ //# sourceMappingURL=dynamic-subscription-creator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dynamic-subscription-creator.js","sourceRoot":"","sources":["../../src/gateway/dynamic-subscription-creator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAOH,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAErE;;GAEG;AACH,MAAM,OAAO,0BAA0B;IAC5B,MAAM,CAAwB;IAEvC;;;;OAIG;IACH,YAAY,KAA4B;QACtC,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACtB,CAAC;IAED;;;;;OAKG;IACH,SAAS,CAAC,UAAkC;QAC1C,OAAO,IAAI,CAAC,MAAM,CAAC,mBAAmB,CAAC,UAAU,CAAC,CAAC;IACrD,CAAC;IAED;;;;;;;OAOG;IACH,SAAS,CACP,OAA+B,EAC/B,MAAmB,EACnB,uBAAgC;QAEhC,OAAO,IAAI,CAAC,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,MAAM,EAAE,uBAAuB,CAAC,CAAC;IACnF,CAAC;IAED;;;;;;OAMG;IACH,QAAQ,CACN,OAGC,EACD,MAAmB;QAEnB,IAAI,MAAM,CAAC,OAAO;YAAE,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;QAC7C,OAAO,IAAI,CAAC,MAAM,CAAC,kBAAkB,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IAC/E,CAAC;IAED;;;;;;OAMG;IACH,MAAM,CAAC,OAAkD,EAAE,MAAmB;QAC5E,OAAO,IAAI,CAAC,MAAM,CAAC,gBAAgB,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAC5D,CAAC;CACF"}