@voltro/protocol 0.84.0 → 0.86.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/CHANGELOG.md +1215 -0
- package/README.md +14 -0
- package/THIRD-PARTY-NOTICES.md +5 -89
- package/dist/apikey.d.ts +32 -34
- package/dist/approval.js +64 -0
- package/dist/approvalDescriptors.js +26 -0
- package/dist/auth.js +369 -0
- package/dist/boundedRing.js +27 -0
- package/dist/businessRule.js +11 -0
- package/dist/connection.js +73 -0
- package/dist/devActivity.js +4 -0
- package/dist/errorValue.js +21 -0
- package/dist/event.js +104 -0
- package/dist/idempotency.js +66 -0
- package/dist/identity.js +5 -9
- package/dist/index.d.ts +1494 -1366
- package/dist/index.js +42 -1411
- package/dist/inspect.d.ts +88 -88
- package/dist/inspect.js +14 -190
- package/dist/inspectBackfill.js +52 -0
- package/dist/inspectCommandRejection.js +21 -0
- package/dist/inspectProjection.js +133 -0
- package/dist/inspectStorageProjection.js +86 -0
- package/dist/inspectValueIdentity.js +4 -0
- package/dist/inspectWorkflowExecution.js +34 -0
- package/dist/inspectWorkflowQueuedStart.js +31 -0
- package/dist/jsonSchema.js +54 -0
- package/dist/jwt.d.ts +32 -34
- package/dist/outbox.js +10 -0
- package/dist/pairing.js +75 -0
- package/dist/plugin.js +61 -0
- package/dist/pluginNaming.js +32 -0
- package/dist/procedure.js +262 -0
- package/dist/publicApi.js +344 -0
- package/dist/reactivityChannel.js +34 -0
- package/dist/rest.d.ts +105 -57
- package/dist/rest.js +259 -437
- package/dist/restFormat.js +163 -0
- package/dist/rowEquality.js +31 -0
- package/dist/rowPatch.js +182 -0
- package/dist/schemaShape.js +67 -0
- package/dist/scopes.js +240 -0
- package/dist/serverErrorBus.js +15 -0
- package/dist/serviceCall.js +14 -0
- package/dist/session.d.ts +90 -96
- package/dist/session.js +13 -15
- package/dist/{sessionHeader-DriTZhmv.js → sessionHeader.js} +1 -1
- package/dist/storageAccess.js +14 -0
- package/dist/storeErrors.js +66 -0
- package/dist/storeScreenshots.js +90 -0
- package/dist/strictInput.js +27 -0
- package/dist/subscriptionEvent.js +37 -0
- package/dist/tenantSelection.js +40 -0
- package/dist/time.js +7 -0
- package/dist/undo.js +38 -0
- package/dist/validation.js +39 -0
- package/dist/webSocketGateway.js +10 -0
- package/dist/workflow.js +297 -0
- package/dist/workflowAccess.js +61 -0
- package/dist/workflowRestart.js +45 -0
- package/dist/workflowRetry.js +44 -0
- package/dist/workflowStartOutcome.js +30 -0
- package/package.json +4 -8
- package/dist/restFormat-EZ8k9ZcQ.js +0 -304
- package/dist/scopes-Di756ENh.js +0 -518
package/README.md
CHANGED
|
@@ -24,3 +24,17 @@ deliberately short so there is nothing here to drift out of date.
|
|
|
24
24
|
|
|
25
25
|
Proprietary. © 2026 Voltro UG. Your use is governed by the
|
|
26
26
|
[Terms of Service](https://voltro.cloud/legal/terms). See the bundled `LICENSE`.
|
|
27
|
+
|
|
28
|
+
## Request-local tenant selection
|
|
29
|
+
|
|
30
|
+
`composeAuthStrategies` accepts `requestedTenant` with a fresh `memberships` source.
|
|
31
|
+
An explicit authenticated workspace is checked before scopes and guards, without
|
|
32
|
+
changing the stored selection. Missing hints retain the existing behavior; invalid
|
|
33
|
+
hints and revoked membership fail closed, including during live reauthorization.
|
|
34
|
+
API apps can configure `auth.requestedTenant` with `auth.memberships` in
|
|
35
|
+
`app.config.ts`; dev and compiled serve share the same builder. Clients still
|
|
36
|
+
need consistent transport and SSR workspace context. See the
|
|
37
|
+
[authentication strategies guide](https://voltro.dev/docs/authentication/strategies)
|
|
38
|
+
for its contract and tenant-specific authority requirements.
|
|
39
|
+
|
|
40
|
+
Request-local selection refusal has wire tag `RequestedTenantRefused`, distinct from credential rejection (`Unauthenticated`). It must not invalidate sibling sessions or trigger credential refresh. HTTP/WebSocket middleware and live reauthorization preserve this distinction.
|
package/THIRD-PARTY-NOTICES.md
CHANGED
|
@@ -1,70 +1,14 @@
|
|
|
1
1
|
# Third-Party Notices — @voltro/protocol
|
|
2
2
|
|
|
3
|
-
This package
|
|
3
|
+
This package uses the open-source software listed below. Each is the
|
|
4
4
|
property of its respective copyright holders and is used under the terms of
|
|
5
5
|
its license. This file is provided for attribution; it grants no rights in
|
|
6
6
|
@voltro/protocol itself, which is proprietary (see LICENSE).
|
|
7
7
|
|
|
8
|
-
Generated from the resolved runtime dependency closure (
|
|
8
|
+
Generated from the resolved runtime dependency closure (4 packages).
|
|
9
9
|
|
|
10
10
|
---
|
|
11
11
|
|
|
12
|
-
## @effect/experimental@0.61.1
|
|
13
|
-
|
|
14
|
-
License: MIT
|
|
15
|
-
|
|
16
|
-
```
|
|
17
|
-
MIT License
|
|
18
|
-
|
|
19
|
-
Copyright (c) 2023-present The Contributors
|
|
20
|
-
|
|
21
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
22
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
23
|
-
in the Software without restriction, including without limitation the rights
|
|
24
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
25
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
26
|
-
furnished to do so, subject to the following conditions:
|
|
27
|
-
|
|
28
|
-
The above copyright notice and this permission notice shall be included in all
|
|
29
|
-
copies or substantial portions of the Software.
|
|
30
|
-
|
|
31
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
32
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
33
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
34
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
35
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
36
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
37
|
-
SOFTWARE.
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
## @effect/sql@0.52.1
|
|
41
|
-
|
|
42
|
-
License: MIT
|
|
43
|
-
|
|
44
|
-
```
|
|
45
|
-
MIT License
|
|
46
|
-
|
|
47
|
-
Copyright (c) 2023-present The Contributors
|
|
48
|
-
|
|
49
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
50
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
51
|
-
in the Software without restriction, including without limitation the rights
|
|
52
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
53
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
54
|
-
furnished to do so, subject to the following conditions:
|
|
55
|
-
|
|
56
|
-
The above copyright notice and this permission notice shall be included in all
|
|
57
|
-
copies or substantial portions of the Software.
|
|
58
|
-
|
|
59
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
60
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
61
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
62
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
63
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
64
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
65
|
-
SOFTWARE.
|
|
66
|
-
```
|
|
67
|
-
|
|
68
12
|
## jose@6.2.12
|
|
69
13
|
|
|
70
14
|
License: MIT
|
|
@@ -93,34 +37,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
93
37
|
SOFTWARE.
|
|
94
38
|
```
|
|
95
39
|
|
|
96
|
-
## layerr@3.0.0
|
|
97
|
-
|
|
98
|
-
License: MIT
|
|
99
|
-
|
|
100
|
-
```
|
|
101
|
-
MIT License
|
|
102
|
-
|
|
103
|
-
Copyright (c) 2020 Perry Mitchell
|
|
104
|
-
|
|
105
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
106
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
107
|
-
in the Software without restriction, including without limitation the rights
|
|
108
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
109
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
110
|
-
furnished to do so, subject to the following conditions:
|
|
111
|
-
|
|
112
|
-
The above copyright notice and this permission notice shall be included in all
|
|
113
|
-
copies or substantial portions of the Software.
|
|
114
|
-
|
|
115
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
116
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
117
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
118
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
119
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
120
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
121
|
-
SOFTWARE.
|
|
122
|
-
```
|
|
123
|
-
|
|
124
40
|
## typeid-js@1.2.0
|
|
125
41
|
|
|
126
42
|
License: Apache-2.0
|
|
@@ -329,14 +245,14 @@ Apache License
|
|
|
329
245
|
limitations under the License.
|
|
330
246
|
```
|
|
331
247
|
|
|
332
|
-
##
|
|
248
|
+
## ulid@3.0.2
|
|
333
249
|
|
|
334
250
|
License: MIT
|
|
335
251
|
|
|
336
252
|
```
|
|
337
|
-
MIT License
|
|
253
|
+
The MIT License (MIT)
|
|
338
254
|
|
|
339
|
-
Copyright (c)
|
|
255
|
+
Copyright (c) 2017 Alizain Feerasta
|
|
340
256
|
|
|
341
257
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
342
258
|
of this software and associated documentation files (the "Software"), to deal
|
package/dist/apikey.d.ts
CHANGED
|
@@ -194,33 +194,31 @@ declare type StrategyResolution = {
|
|
|
194
194
|
readonly reason: string;
|
|
195
195
|
};
|
|
196
196
|
|
|
197
|
-
declare const Subject: Schema.Union<[Schema.Struct<{
|
|
198
|
-
type: Schema.Literal<
|
|
199
|
-
id:
|
|
200
|
-
tenantId:
|
|
201
|
-
scopes: Schema.optional<Schema
|
|
202
|
-
metadata: Schema.optional<Schema
|
|
197
|
+
declare const Subject: Schema.Union<readonly [Schema.Struct<{
|
|
198
|
+
readonly type: Schema.Literal<"user">;
|
|
199
|
+
readonly id: Schema.String;
|
|
200
|
+
readonly tenantId: Schema.String;
|
|
201
|
+
readonly scopes: Schema.optional<Schema.$Array<Schema.String>>;
|
|
202
|
+
readonly metadata: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
203
203
|
}>, Schema.Struct<{
|
|
204
|
-
type: Schema.Literal<
|
|
205
|
-
id:
|
|
206
|
-
tenantId:
|
|
207
|
-
scopes: Schema.optional<Schema
|
|
208
|
-
metadata: Schema.optional<Schema
|
|
204
|
+
readonly type: Schema.Literal<"apiKey">;
|
|
205
|
+
readonly id: Schema.String;
|
|
206
|
+
readonly tenantId: Schema.String;
|
|
207
|
+
readonly scopes: Schema.optional<Schema.$Array<Schema.String>>;
|
|
208
|
+
readonly metadata: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
209
209
|
}>, Schema.Struct<{
|
|
210
|
-
type: Schema.Literal<
|
|
211
|
-
id:
|
|
212
|
-
tenantId:
|
|
210
|
+
readonly type: Schema.Literal<"serviceAccount">;
|
|
211
|
+
readonly id: Schema.String;
|
|
212
|
+
readonly tenantId: Schema.String;
|
|
213
213
|
/** Application actor used for audit columns; null means machine work with
|
|
214
214
|
* no application actor. Identity only, never a permission grant. */
|
|
215
|
-
auditActorId: Schema.
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
scopes: Schema.optional<Schema.Array$<typeof Schema.String>>;
|
|
219
|
-
metadata: Schema.optional<Schema.Record$<typeof Schema.String, typeof Schema.Unknown>>;
|
|
215
|
+
readonly auditActorId: Schema.optionalKey<Schema.NullOr<Schema.String>>;
|
|
216
|
+
readonly scopes: Schema.optional<Schema.$Array<Schema.String>>;
|
|
217
|
+
readonly metadata: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
220
218
|
}>, Schema.Struct<{
|
|
221
|
-
type: Schema.Literal<
|
|
222
|
-
id:
|
|
223
|
-
tenantId: Schema.NullOr<
|
|
219
|
+
readonly type: Schema.Literal<"anonymous">;
|
|
220
|
+
readonly id: Schema.Null;
|
|
221
|
+
readonly tenantId: Schema.NullOr<Schema.String>;
|
|
224
222
|
/**
|
|
225
223
|
* Set when this caller PRESENTED a credential and it was rejected — an
|
|
226
224
|
* expired token above all. Absent when they presented none.
|
|
@@ -237,21 +235,21 @@ declare const Subject: Schema.Union<[Schema.Struct<{
|
|
|
237
235
|
* must not break an `openAccess` procedure that needs no session at all. The
|
|
238
236
|
* fact travels, and only a guard that actually refuses spends it.
|
|
239
237
|
*/
|
|
240
|
-
credentialRejected: Schema.optional<
|
|
238
|
+
readonly credentialRejected: Schema.optional<Schema.String>;
|
|
241
239
|
}>, Schema.Struct<{
|
|
242
|
-
type: Schema.Literal<
|
|
243
|
-
id:
|
|
244
|
-
tenantId:
|
|
245
|
-
scopes: Schema.optional<Schema
|
|
246
|
-
metadata: Schema.optional<Schema
|
|
240
|
+
readonly type: Schema.Literal<"system">;
|
|
241
|
+
readonly id: Schema.String;
|
|
242
|
+
readonly tenantId: Schema.Null;
|
|
243
|
+
readonly scopes: Schema.optional<Schema.$Array<Schema.String>>;
|
|
244
|
+
readonly metadata: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
247
245
|
}>, Schema.Struct<{
|
|
248
|
-
type: Schema.Literal<
|
|
249
|
-
id:
|
|
246
|
+
readonly type: Schema.Literal<"service">;
|
|
247
|
+
readonly id: Schema.String;
|
|
250
248
|
/** The calling app's name, as the callee lists it in `serviceCallers`. */
|
|
251
|
-
service:
|
|
252
|
-
tenantId:
|
|
253
|
-
scopes: Schema.optional<Schema
|
|
254
|
-
metadata: Schema.optional<Schema
|
|
249
|
+
readonly service: Schema.String;
|
|
250
|
+
readonly tenantId: Schema.Null;
|
|
251
|
+
readonly scopes: Schema.optional<Schema.$Array<Schema.String>>;
|
|
252
|
+
readonly metadata: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
255
253
|
}>]>;
|
|
256
254
|
|
|
257
255
|
declare type Subject = typeof Subject.Type;
|
package/dist/approval.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { Schema as e } from "effect";
|
|
2
|
+
//#region src/approval.ts
|
|
3
|
+
var t = class extends e.TaggedError()("ApprovalRequired", {
|
|
4
|
+
approvalId: e.String,
|
|
5
|
+
procedure: e.String,
|
|
6
|
+
expiresAt: e.String,
|
|
7
|
+
requiredScopes: e.Array(e.String),
|
|
8
|
+
reason: e.NullOr(e.String),
|
|
9
|
+
created: e.Boolean
|
|
10
|
+
}) {}, n = class extends e.TaggedError()("ApprovalNotFound", { approvalId: e.String }) {}, r = class extends e.TaggedError()("ApprovalSelfApproval", {
|
|
11
|
+
approvalId: e.String,
|
|
12
|
+
subjectId: e.NullOr(e.String)
|
|
13
|
+
}) {}, i = class extends e.TaggedError()("ApprovalRejected", {
|
|
14
|
+
approvalId: e.String,
|
|
15
|
+
decidedBy: e.NullOr(e.String),
|
|
16
|
+
note: e.NullOr(e.String)
|
|
17
|
+
}) {}, a = class extends e.TaggedError()("ApprovalExpired", {
|
|
18
|
+
approvalId: e.String,
|
|
19
|
+
expiredAt: e.String
|
|
20
|
+
}) {}, o = class extends e.TaggedError()("ApprovalNotPending", {
|
|
21
|
+
approvalId: e.String,
|
|
22
|
+
status: e.String
|
|
23
|
+
}) {}, s = class extends e.TaggedError()("ApprovalForbidden", {
|
|
24
|
+
approvalId: e.String,
|
|
25
|
+
required: e.NullOr(e.String),
|
|
26
|
+
message: e.String
|
|
27
|
+
}) {}, c = class extends e.TaggedError()("ApprovalUnavailable", {
|
|
28
|
+
procedure: e.String,
|
|
29
|
+
message: e.String
|
|
30
|
+
}) {}, l = e.Union([
|
|
31
|
+
t,
|
|
32
|
+
i,
|
|
33
|
+
a,
|
|
34
|
+
c
|
|
35
|
+
]), u = e.Union([
|
|
36
|
+
n,
|
|
37
|
+
r,
|
|
38
|
+
a,
|
|
39
|
+
o,
|
|
40
|
+
s,
|
|
41
|
+
c
|
|
42
|
+
]), d = e.Struct({
|
|
43
|
+
id: e.String,
|
|
44
|
+
procedure: e.String,
|
|
45
|
+
kind: e.Literals(["mutation", "action"]),
|
|
46
|
+
requestedBy: e.NullOr(e.String),
|
|
47
|
+
status: e.Literals([
|
|
48
|
+
"pending",
|
|
49
|
+
"approved",
|
|
50
|
+
"rejected",
|
|
51
|
+
"expired",
|
|
52
|
+
"consumed"
|
|
53
|
+
]),
|
|
54
|
+
reason: e.NullOr(e.String),
|
|
55
|
+
requiredScopes: e.Array(e.String),
|
|
56
|
+
requestedAt: e.String,
|
|
57
|
+
expiresAt: e.String,
|
|
58
|
+
decidedBy: e.NullOr(e.String),
|
|
59
|
+
decidedAt: e.NullOr(e.String),
|
|
60
|
+
note: e.NullOr(e.String),
|
|
61
|
+
relation: e.Literals(["to-decide", "requested"])
|
|
62
|
+
});
|
|
63
|
+
//#endregion
|
|
64
|
+
export { u as ApprovalDecisionErrors, l as ApprovalErrors, a as ApprovalExpired, s as ApprovalForbidden, n as ApprovalNotFound, o as ApprovalNotPending, i as ApprovalRejected, t as ApprovalRequired, r as ApprovalSelfApproval, c as ApprovalUnavailable, d as PendingApproval };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ApprovalDecisionErrors as e, PendingApproval as t } from "./approval.js";
|
|
2
|
+
import { defineMutation as n, defineQuery as r } from "./procedure.js";
|
|
3
|
+
import { Schema as i } from "effect";
|
|
4
|
+
//#region src/approvalDescriptors.ts
|
|
5
|
+
var a = "__voltro.approvals.pending", o = "__voltro.approvals.decide", s = r({
|
|
6
|
+
name: a,
|
|
7
|
+
source: "_voltro_approvals",
|
|
8
|
+
input: i.Struct({ limit: i.optional(i.Number) }),
|
|
9
|
+
output: i.Array(t),
|
|
10
|
+
openAccess: "the answer is scoped to the caller — a row appears only if they requested it or hold its recorded approver scopes, so an anonymous caller sees nothing"
|
|
11
|
+
}), c = n({
|
|
12
|
+
name: o,
|
|
13
|
+
input: i.Struct({
|
|
14
|
+
approvalId: i.String,
|
|
15
|
+
decision: i.Literals(["approve", "reject"]),
|
|
16
|
+
note: i.optional(i.String)
|
|
17
|
+
}),
|
|
18
|
+
output: i.Struct({
|
|
19
|
+
approvalId: i.String,
|
|
20
|
+
status: i.Literals(["approved", "rejected"])
|
|
21
|
+
}),
|
|
22
|
+
error: e,
|
|
23
|
+
openAccess: "the approver authority is the PENDING ROW's own recorded scopes (plus an unconditional self-approval refusal), checked in-handler — a descriptor-level scope would have to be the union of every approval-requiring procedure in the app"
|
|
24
|
+
});
|
|
25
|
+
//#endregion
|
|
26
|
+
export { o as APPROVALS_DECIDE_TAG, a as APPROVALS_PENDING_TAG, c as approvalsDecideDescriptor, s as approvalsPendingQueryDescriptor };
|
package/dist/auth.js
ADDED
|
@@ -0,0 +1,369 @@
|
|
|
1
|
+
import { RequestedTenantRefused as e, TenantSelectionRefused as t, isTenantSelectable as n, selectSubjectTenant as r } from "./tenantSelection.js";
|
|
2
|
+
import { Context as i, Schema as a, Struct as o } from "effect";
|
|
3
|
+
import { RpcMiddleware as s } from "effect/rpc";
|
|
4
|
+
//#region src/auth.ts
|
|
5
|
+
var c = a.Record(a.String, a.Unknown), l = a.optional(a.Array(a.String)), u = a.Struct({
|
|
6
|
+
type: a.Literal("user"),
|
|
7
|
+
id: a.String,
|
|
8
|
+
tenantId: a.String,
|
|
9
|
+
scopes: l,
|
|
10
|
+
metadata: a.optional(c)
|
|
11
|
+
}), d = a.Struct({
|
|
12
|
+
type: a.Literal("apiKey"),
|
|
13
|
+
id: a.String,
|
|
14
|
+
tenantId: a.String,
|
|
15
|
+
scopes: l,
|
|
16
|
+
metadata: a.optional(c)
|
|
17
|
+
}), f = a.Struct({
|
|
18
|
+
type: a.Literal("serviceAccount"),
|
|
19
|
+
id: a.String,
|
|
20
|
+
tenantId: a.String,
|
|
21
|
+
auditActorId: a.optionalKey(a.NullOr(a.String)),
|
|
22
|
+
scopes: l,
|
|
23
|
+
metadata: a.optional(c)
|
|
24
|
+
}), p = a.Struct({
|
|
25
|
+
type: a.Literal("anonymous"),
|
|
26
|
+
id: a.Null,
|
|
27
|
+
tenantId: a.NullOr(a.String),
|
|
28
|
+
credentialRejected: a.optional(a.String)
|
|
29
|
+
}), m = a.Struct({
|
|
30
|
+
type: a.Literal("system"),
|
|
31
|
+
id: a.String,
|
|
32
|
+
tenantId: a.Null,
|
|
33
|
+
scopes: l,
|
|
34
|
+
metadata: a.optional(c)
|
|
35
|
+
}), h = a.Struct({
|
|
36
|
+
type: a.Literal("service"),
|
|
37
|
+
id: a.String,
|
|
38
|
+
service: a.String,
|
|
39
|
+
tenantId: a.Null,
|
|
40
|
+
scopes: l,
|
|
41
|
+
metadata: a.optional(c)
|
|
42
|
+
}), g = a.Union([
|
|
43
|
+
u,
|
|
44
|
+
d,
|
|
45
|
+
f,
|
|
46
|
+
p,
|
|
47
|
+
m,
|
|
48
|
+
h
|
|
49
|
+
]), _ = a.Union([
|
|
50
|
+
u.mapFields(o.omit(["scopes"])),
|
|
51
|
+
d.mapFields(o.omit(["scopes"])),
|
|
52
|
+
f.mapFields(o.omit(["scopes"])),
|
|
53
|
+
p,
|
|
54
|
+
m.mapFields(o.omit(["scopes"])),
|
|
55
|
+
h.mapFields(o.omit(["scopes"]))
|
|
56
|
+
]), v = (e) => {
|
|
57
|
+
if (e.type === "anonymous") return e;
|
|
58
|
+
let { scopes: t, ...n } = e;
|
|
59
|
+
return n;
|
|
60
|
+
}, y = (e) => e.scopes ?? [], b = (e, t) => ({
|
|
61
|
+
type: "anonymous",
|
|
62
|
+
id: null,
|
|
63
|
+
tenantId: e,
|
|
64
|
+
...t === void 0 ? {} : { credentialRejected: t }
|
|
65
|
+
}), x = (e, t = ["admin:full"]) => ({
|
|
66
|
+
type: "system",
|
|
67
|
+
id: e,
|
|
68
|
+
tenantId: null,
|
|
69
|
+
scopes: t
|
|
70
|
+
}), S = (e) => ({
|
|
71
|
+
type: "service",
|
|
72
|
+
id: `service:${e}`,
|
|
73
|
+
service: e,
|
|
74
|
+
tenantId: null,
|
|
75
|
+
scopes: []
|
|
76
|
+
}), C = (e) => e.type === "service", w = (e) => e.type === "system" || e.type === "service", T = (e) => {
|
|
77
|
+
if (e.type === "system") return null;
|
|
78
|
+
if (e.type === "serviceAccount" && e.auditActorId !== void 0) return e.auditActorId;
|
|
79
|
+
if (e.type !== "apiKey") return e.id;
|
|
80
|
+
let t = e.metadata?.userId;
|
|
81
|
+
return typeof t == "string" && t !== "" ? t : e.id;
|
|
82
|
+
}, E = (e, t) => {
|
|
83
|
+
let n = e;
|
|
84
|
+
return {
|
|
85
|
+
type: "serviceAccount",
|
|
86
|
+
id: e.id ?? "system",
|
|
87
|
+
tenantId: t,
|
|
88
|
+
auditActorId: T(e),
|
|
89
|
+
scopes: y(e),
|
|
90
|
+
...n.metadata === void 0 ? {} : { metadata: n.metadata }
|
|
91
|
+
};
|
|
92
|
+
}, D = (e) => e.type === "system", O = "impersonation", k = (e) => e.metadata?.impersonation ?? null, A = class extends i.Service()("@voltro/Subject") {}, j = class extends i.Service()("@voltro/ConnectionInfo") {}, M = class extends a.TaggedError()("Unauthenticated", { reason: a.optional(a.String) }) {
|
|
93
|
+
get message() {
|
|
94
|
+
return this.reason ?? "Unauthenticated";
|
|
95
|
+
}
|
|
96
|
+
}, N = class extends s.Service()("@voltro/AuthMiddleware", { error: a.Union([M, e]) }) {}, P = class extends s.Service()("@voltro/ConnectionInfoMiddleware") {}, F = /* @__PURE__ */ new WeakMap(), I = (e, t) => {
|
|
97
|
+
let n = { ...e };
|
|
98
|
+
return F.set(n, {
|
|
99
|
+
current: n,
|
|
100
|
+
resolve: t
|
|
101
|
+
}), n;
|
|
102
|
+
}, L = (e) => F.get(e)?.current ?? e, R = async (e, t) => {
|
|
103
|
+
let n = F.get(e);
|
|
104
|
+
if (n === void 0) return await t?.(e), e;
|
|
105
|
+
let r = await n.resolve();
|
|
106
|
+
if (r.type !== e.type || r.id !== e.id || r.tenantId !== e.tenantId || e.type === "service" && (r.type !== "service" || r.service !== e.service)) throw new M({ reason: "subscription identity or tenant changed; subscribe again" });
|
|
107
|
+
return F.set(r, {
|
|
108
|
+
current: r,
|
|
109
|
+
resolve: n.resolve
|
|
110
|
+
}), await t?.(r), n.current = r, r;
|
|
111
|
+
}, z = (e) => typeof e.mountRoutes == "function", B = (e) => Array.isArray(e) ? {
|
|
112
|
+
kind: "grant",
|
|
113
|
+
scopes: e
|
|
114
|
+
} : e, V = (e, t) => {
|
|
115
|
+
if (t.kind === "vetoed") throw new M({ reason: `${t.code}: ${t.message}` });
|
|
116
|
+
if (e.type === "anonymous") return {
|
|
117
|
+
subject: e,
|
|
118
|
+
removed: []
|
|
119
|
+
};
|
|
120
|
+
let n = y(e);
|
|
121
|
+
if (t.kind === "grant") {
|
|
122
|
+
if (t.scopes.length === 0) return {
|
|
123
|
+
subject: e,
|
|
124
|
+
removed: []
|
|
125
|
+
};
|
|
126
|
+
let r = [.../* @__PURE__ */ new Set([...n, ...t.scopes])];
|
|
127
|
+
return {
|
|
128
|
+
subject: {
|
|
129
|
+
...e,
|
|
130
|
+
scopes: r
|
|
131
|
+
},
|
|
132
|
+
removed: []
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
let r = new Set(t.scopes), i = n.filter((e) => !r.has(e));
|
|
136
|
+
return {
|
|
137
|
+
subject: {
|
|
138
|
+
...e,
|
|
139
|
+
scopes: [...r]
|
|
140
|
+
},
|
|
141
|
+
removed: i
|
|
142
|
+
};
|
|
143
|
+
}, H = 3e4, U = 1e4, W = (e) => `${e.type}\u0000${e.tenantId ?? ""}\u0000${e.id ?? ""}`, G = () => {
|
|
144
|
+
if (typeof process > "u") return;
|
|
145
|
+
let e = process.env.VOLTRO_AUTH_SCOPE_CACHE_TTL_MS;
|
|
146
|
+
if (e === void 0 || e === "") return;
|
|
147
|
+
let t = Number(e);
|
|
148
|
+
return Number.isFinite(t) && t >= 0 ? t : void 0;
|
|
149
|
+
}, K = (e = {}) => {
|
|
150
|
+
let t = e.ttlMs ?? G() ?? 3e4, n = e.maxEntries ?? 1e4, r = e.now ?? Date.now, i = /* @__PURE__ */ new Map(), a = () => {
|
|
151
|
+
if (i.size <= n) return;
|
|
152
|
+
let e = r();
|
|
153
|
+
for (let [t, n] of i) n.freshUntil <= e && i.delete(t);
|
|
154
|
+
for (let e of i.keys()) {
|
|
155
|
+
if (i.size <= n) break;
|
|
156
|
+
i.delete(e);
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
return {
|
|
160
|
+
ttlMs: t,
|
|
161
|
+
invalidate: (e) => {
|
|
162
|
+
i.delete(e);
|
|
163
|
+
},
|
|
164
|
+
invalidateAll: () => {
|
|
165
|
+
i.clear();
|
|
166
|
+
},
|
|
167
|
+
resolve: async (e, n) => {
|
|
168
|
+
let o = r();
|
|
169
|
+
if (t > 0) {
|
|
170
|
+
let t = i.get(e);
|
|
171
|
+
if (t && t.freshUntil > o) return {
|
|
172
|
+
decision: t.decision,
|
|
173
|
+
fresh: !1
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
let s = await n();
|
|
177
|
+
return t > 0 && s.kind !== "unavailable" && (i.set(e, {
|
|
178
|
+
decision: s,
|
|
179
|
+
freshUntil: o + t
|
|
180
|
+
}), a()), {
|
|
181
|
+
decision: s,
|
|
182
|
+
fresh: !0
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
}, q = (e) => typeof e.resolve == "function", J = (e) => {
|
|
187
|
+
let t = e.authorization ?? e.Authorization;
|
|
188
|
+
if (t !== void 0) return /^Bearer\s+(.+)$/i.exec(t.trim())?.[1]?.trim();
|
|
189
|
+
}, Y = async (e, i, a, o) => {
|
|
190
|
+
let s;
|
|
191
|
+
try {
|
|
192
|
+
s = await a.source(e, i);
|
|
193
|
+
} catch {
|
|
194
|
+
throw o("target-unavailable");
|
|
195
|
+
}
|
|
196
|
+
if (s === null) return;
|
|
197
|
+
if (typeof s != "string" || s.trim().length === 0) throw o("invalid-target");
|
|
198
|
+
if (!n(e)) throw o("subject-has-no-tenant");
|
|
199
|
+
let c;
|
|
200
|
+
try {
|
|
201
|
+
c = await a.memberships(e, i);
|
|
202
|
+
} catch {
|
|
203
|
+
throw o("memberships-unavailable");
|
|
204
|
+
}
|
|
205
|
+
try {
|
|
206
|
+
return r(e, s, c);
|
|
207
|
+
} catch (e) {
|
|
208
|
+
throw e instanceof t ? o(e.reason) : e;
|
|
209
|
+
}
|
|
210
|
+
}, X = async (e, i, a, o) => {
|
|
211
|
+
if (!n(e)) return e;
|
|
212
|
+
let s = {
|
|
213
|
+
type: e.type,
|
|
214
|
+
id: e.id
|
|
215
|
+
}, c;
|
|
216
|
+
try {
|
|
217
|
+
c = await a.store.read(s);
|
|
218
|
+
} catch (e) {
|
|
219
|
+
throw o(`tenant selection unavailable: ${e instanceof Error ? e.message : String(e)}`);
|
|
220
|
+
}
|
|
221
|
+
if (c === null || c === e.tenantId) return e;
|
|
222
|
+
let l;
|
|
223
|
+
try {
|
|
224
|
+
l = await a.memberships(e, i);
|
|
225
|
+
} catch (e) {
|
|
226
|
+
throw o(`memberships unavailable: ${e instanceof Error ? e.message : String(e)}`);
|
|
227
|
+
}
|
|
228
|
+
try {
|
|
229
|
+
return r(e, c, l);
|
|
230
|
+
} catch (n) {
|
|
231
|
+
if (!(n instanceof t)) throw n;
|
|
232
|
+
try {
|
|
233
|
+
await a.store.clear(s);
|
|
234
|
+
} catch (e) {
|
|
235
|
+
throw o(`tenant selection unavailable: ${e instanceof Error ? e.message : String(e)}`);
|
|
236
|
+
}
|
|
237
|
+
return e;
|
|
238
|
+
}
|
|
239
|
+
}, Z = (e, t) => {
|
|
240
|
+
let n = J(t);
|
|
241
|
+
if (n === void 0) return e;
|
|
242
|
+
let r = e.filter((e) => e.claimsBearerPrefix !== void 0 && e.claimsBearerPrefix !== "" && n.startsWith(e.claimsBearerPrefix));
|
|
243
|
+
if (r.length === 0) return e;
|
|
244
|
+
let i = new Set(r);
|
|
245
|
+
return [...r, ...e.filter((e) => !i.has(e))];
|
|
246
|
+
}, Q = (e, t) => {
|
|
247
|
+
if (e === "refuse") throw new M({ reason: "anonymous callers are refused" });
|
|
248
|
+
if (e === "no-tenant") return "";
|
|
249
|
+
if (e === "header") {
|
|
250
|
+
if (t === void 0 || t === "") throw new M({ reason: "tenant required (x-tenant header missing)" });
|
|
251
|
+
return t;
|
|
252
|
+
}
|
|
253
|
+
return "tenantId" in e ? e.tenantId : t !== void 0 && t !== "" ? t : e.headerOrTenant;
|
|
254
|
+
}, $ = (t, n) => {
|
|
255
|
+
let r = n?.resolveScopes, i = n?.subjectGuards ?? [], a = n?.tenantSelection !== void 0 || n?.requestedTenant !== void 0;
|
|
256
|
+
if (n?.memberships !== void 0 !== a) throw Error("composeAuthStrategies: memberships and tenant selection come together; `memberships` requires `tenantSelection` or `requestedTenant`; each tenant selector requires `memberships` to authorize its target.");
|
|
257
|
+
let o = n?.memberships !== void 0 && n.tenantSelection !== void 0 ? {
|
|
258
|
+
memberships: n.memberships,
|
|
259
|
+
store: n.tenantSelection
|
|
260
|
+
} : void 0, s = r !== void 0 || i.length > 0, c = !s || n?.scopeCache === !1 ? null : n?.scopeCache !== void 0 && q(n.scopeCache) ? n.scopeCache : K(n?.scopeCache ?? {}), l = async (a) => {
|
|
261
|
+
let l = n?.getStore?.(), u = l === void 0 ? a : {
|
|
262
|
+
...a,
|
|
263
|
+
store: l
|
|
264
|
+
}, d;
|
|
265
|
+
for (let a of Z(t, u.headers)) {
|
|
266
|
+
let t = await a.resolve(u);
|
|
267
|
+
if (t.kind === "matched") {
|
|
268
|
+
let l = (e) => (n?.onStrategyFailed?.({
|
|
269
|
+
strategyId: a.id,
|
|
270
|
+
reason: e
|
|
271
|
+
}), new M({ reason: e })), d = n?.requestedTenant === void 0 || n.memberships === void 0 ? void 0 : await Y(t.subject, u, {
|
|
272
|
+
source: n.requestedTenant,
|
|
273
|
+
memberships: n.memberships
|
|
274
|
+
}, (t) => (n?.onStrategyFailed?.({
|
|
275
|
+
strategyId: a.id,
|
|
276
|
+
reason: `requested tenant refused: ${t}`
|
|
277
|
+
}), new e({ reason: t })));
|
|
278
|
+
if (t.subject.type === "service") return { subject: {
|
|
279
|
+
...t.subject,
|
|
280
|
+
scopes: []
|
|
281
|
+
} };
|
|
282
|
+
let f = d ?? (o === void 0 ? t.subject : await X(t.subject, u, o, l)), p = f;
|
|
283
|
+
if (s) {
|
|
284
|
+
let e = async () => {
|
|
285
|
+
let e = r === void 0 ? {
|
|
286
|
+
kind: "grant",
|
|
287
|
+
scopes: []
|
|
288
|
+
} : B(await r(f, u));
|
|
289
|
+
if (e.kind === "unavailable" || i.length === 0) return e;
|
|
290
|
+
let t = V(f, e).subject, n = {
|
|
291
|
+
origin: "request",
|
|
292
|
+
headers: u.headers,
|
|
293
|
+
clientId: u.clientId,
|
|
294
|
+
store: u.store
|
|
295
|
+
};
|
|
296
|
+
for (let e of i) {
|
|
297
|
+
let r = await e(t, n);
|
|
298
|
+
if (!r.ok) return {
|
|
299
|
+
kind: "vetoed",
|
|
300
|
+
code: r.code,
|
|
301
|
+
message: r.message
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
return e;
|
|
305
|
+
}, { decision: t, fresh: o } = c === null ? {
|
|
306
|
+
decision: await e(),
|
|
307
|
+
fresh: !0
|
|
308
|
+
} : await c.resolve(W(f), e);
|
|
309
|
+
if (t.kind === "vetoed") {
|
|
310
|
+
let e = `${t.code}: ${t.message}`;
|
|
311
|
+
throw n?.onStrategyFailed?.({
|
|
312
|
+
strategyId: a.id,
|
|
313
|
+
reason: e
|
|
314
|
+
}), new M({ reason: e });
|
|
315
|
+
}
|
|
316
|
+
if (t.kind === "unavailable") {
|
|
317
|
+
let e = `scope resolution unavailable: ${t.reason}`;
|
|
318
|
+
throw n?.onStrategyFailed?.({
|
|
319
|
+
strategyId: a.id,
|
|
320
|
+
reason: e
|
|
321
|
+
}), new M({ reason: e });
|
|
322
|
+
}
|
|
323
|
+
let s = V(f, t);
|
|
324
|
+
o && s.removed.length > 0 && n?.onScopesNarrowed?.({
|
|
325
|
+
strategyId: a.id,
|
|
326
|
+
subjectType: f.type,
|
|
327
|
+
subjectId: f.id,
|
|
328
|
+
removed: s.removed,
|
|
329
|
+
granted: t.scopes
|
|
330
|
+
}), p = s.subject;
|
|
331
|
+
}
|
|
332
|
+
return t.credentialExpiresAt === void 0 ? { subject: p } : {
|
|
333
|
+
subject: p,
|
|
334
|
+
credentialExpiresAt: t.credentialExpiresAt
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
if (t.kind === "failed") {
|
|
338
|
+
n?.onStrategyFailed?.({
|
|
339
|
+
strategyId: a.id,
|
|
340
|
+
reason: t.reason
|
|
341
|
+
}), d = t.reason;
|
|
342
|
+
break;
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
if (n?.fallback) {
|
|
346
|
+
let e = await n.fallback(u);
|
|
347
|
+
return { subject: d !== void 0 && e.type === "anonymous" ? {
|
|
348
|
+
...e,
|
|
349
|
+
credentialRejected: d
|
|
350
|
+
} : e };
|
|
351
|
+
}
|
|
352
|
+
if (d !== void 0) throw new M({ reason: `credential rejected: ${d}` });
|
|
353
|
+
return { subject: b(Q(n?.anonymous ?? "no-tenant", u.headers["x-tenant"])) };
|
|
354
|
+
};
|
|
355
|
+
return async (e) => {
|
|
356
|
+
let t = {
|
|
357
|
+
...e,
|
|
358
|
+
headers: { ...e.headers }
|
|
359
|
+
}, n = await l(t), r = I(n.subject, async () => ({ ...(await l(t)).subject }));
|
|
360
|
+
return {
|
|
361
|
+
...n,
|
|
362
|
+
subject: r
|
|
363
|
+
};
|
|
364
|
+
};
|
|
365
|
+
}, ee = (e, t) => {
|
|
366
|
+
if (e.type === "anonymous") throw new M(t === void 0 ? {} : { reason: t });
|
|
367
|
+
};
|
|
368
|
+
//#endregion
|
|
369
|
+
export { N as AuthMiddleware, j as ConnectionInfo, P as ConnectionInfoMiddleware, U as DEFAULT_SCOPE_CACHE_MAX_ENTRIES, H as DEFAULT_SCOPE_CACHE_TTL_MS, O as IMPERSONATION_METADATA_KEY, g as Subject, _ as SubjectIdentity, A as SubjectService, M as Unauthenticated, b as anonymousSubject, V as applyScopeDecision, ee as assertAuthenticated, I as bindSubjectAuthority, $ as composeAuthStrategies, L as currentSubjectAuthority, z as hasCallbackRoutes, w as isMachineSubject, C as isServiceSubject, D as isSystemSubject, K as makeScopeCache, Z as orderByBearerPrefix, k as rawImpersonationMark, R as reauthorizeSubject, W as scopeCacheKey, S as serviceSubject, T as subjectAuditActorId, v as subjectIdentity, x as systemSubject, E as tenantScopedSubject };
|