@voltro/protocol 0.85.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 +666 -0
- package/README.md +14 -0
- package/THIRD-PARTY-NOTICES.md +5 -33
- 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 +225 -21
- package/dist/index.js +42 -1700
- package/dist/inspect.js +14 -240
- 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/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 +33 -0
- package/dist/rest.js +213 -470
- 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.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 +3 -3
- package/dist/restFormat-BlgTLxm1.js +0 -298
- package/dist/scopes-ClywBij8.js +0 -548
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,11 +1,11 @@
|
|
|
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
|
|
|
@@ -37,34 +37,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
37
37
|
SOFTWARE.
|
|
38
38
|
```
|
|
39
39
|
|
|
40
|
-
## layerr@3.0.0
|
|
41
|
-
|
|
42
|
-
License: MIT
|
|
43
|
-
|
|
44
|
-
```
|
|
45
|
-
MIT License
|
|
46
|
-
|
|
47
|
-
Copyright (c) 2020 Perry Mitchell
|
|
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
40
|
## typeid-js@1.2.0
|
|
69
41
|
|
|
70
42
|
License: Apache-2.0
|
|
@@ -273,14 +245,14 @@ Apache License
|
|
|
273
245
|
limitations under the License.
|
|
274
246
|
```
|
|
275
247
|
|
|
276
|
-
##
|
|
248
|
+
## ulid@3.0.2
|
|
277
249
|
|
|
278
250
|
License: MIT
|
|
279
251
|
|
|
280
252
|
```
|
|
281
|
-
MIT License
|
|
253
|
+
The MIT License (MIT)
|
|
282
254
|
|
|
283
|
-
Copyright (c)
|
|
255
|
+
Copyright (c) 2017 Alizain Feerasta
|
|
284
256
|
|
|
285
257
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
286
258
|
of this software and associated documentation files (the "Software"), to deal
|
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 };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
//#region src/boundedRing.ts
|
|
2
|
+
var e = class {
|
|
3
|
+
slots = [];
|
|
4
|
+
head = 0;
|
|
5
|
+
size = 0;
|
|
6
|
+
capacity;
|
|
7
|
+
constructor(e) {
|
|
8
|
+
this.capacity = Number.isNaN(e) ? Infinity : Math.max(0, Math.floor(e));
|
|
9
|
+
}
|
|
10
|
+
get length() {
|
|
11
|
+
return this.size;
|
|
12
|
+
}
|
|
13
|
+
get(e) {
|
|
14
|
+
if (!(!Number.isInteger(e) || e < 0 || e >= this.size)) return this.slots[(this.head + e) % this.capacity];
|
|
15
|
+
}
|
|
16
|
+
push(e) {
|
|
17
|
+
this.capacity !== 0 && (this.size < this.capacity ? (this.slots[(this.head + this.size) % this.capacity] = e, this.size++) : (this.slots[this.head] = e, this.head = (this.head + 1) % this.capacity));
|
|
18
|
+
}
|
|
19
|
+
clear() {
|
|
20
|
+
this.slots.length = 0, this.head = 0, this.size = 0;
|
|
21
|
+
}
|
|
22
|
+
*[Symbol.iterator]() {
|
|
23
|
+
for (let e = 0; e < this.size; e++) yield this.get(e);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
//#endregion
|
|
27
|
+
export { e as BoundedRing };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Schema as e } from "effect";
|
|
2
|
+
//#region src/businessRule.ts
|
|
3
|
+
var t = class extends e.TaggedError()("BusinessRuleViolation", {
|
|
4
|
+
rule: e.String,
|
|
5
|
+
params: e.optional(e.Record(e.String, e.Unknown)),
|
|
6
|
+
field: e.optional(e.String),
|
|
7
|
+
message: e.optional(e.String),
|
|
8
|
+
severity: e.Literals(["error", "warning"])
|
|
9
|
+
}) {};
|
|
10
|
+
//#endregion
|
|
11
|
+
export { t as BusinessRuleViolation };
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { defineAction as e, defineMutation as t, defineQuery as n } from "./procedure.js";
|
|
2
|
+
import { Schema as r } from "effect";
|
|
3
|
+
//#region src/connection.ts
|
|
4
|
+
var i = "__voltro.connections.list", a = "__voltro.connections.start", o = "__voltro.connections.submitToken", s = "__voltro.connections.disconnect", c = r.Literals(["oauth2", "pat"]), l = r.Literals([
|
|
5
|
+
"disconnected",
|
|
6
|
+
"connected",
|
|
7
|
+
"expired",
|
|
8
|
+
"revoked",
|
|
9
|
+
"error"
|
|
10
|
+
]), u = r.Struct({
|
|
11
|
+
connectionId: r.String,
|
|
12
|
+
kind: c,
|
|
13
|
+
label: r.String,
|
|
14
|
+
status: l,
|
|
15
|
+
accountId: r.NullOr(r.String),
|
|
16
|
+
accountLabel: r.NullOr(r.String),
|
|
17
|
+
scopes: r.Array(r.String),
|
|
18
|
+
expiresAt: r.NullOr(r.String),
|
|
19
|
+
lastError: r.NullOr(r.String),
|
|
20
|
+
connectedAt: r.NullOr(r.String)
|
|
21
|
+
}), d = class extends r.TaggedError()("ConnectionNotDeclared", { connectionId: r.String }) {}, f = class extends r.TaggedError()("ConnectionSubjectRequired", { connectionId: r.String }) {}, p = class extends r.TaggedError()("ConnectionKindMismatch", {
|
|
22
|
+
connectionId: r.String,
|
|
23
|
+
expected: c,
|
|
24
|
+
actual: c
|
|
25
|
+
}) {}, m = class extends r.TaggedError()("ConnectionHandshakeFailed", {
|
|
26
|
+
connectionId: r.String,
|
|
27
|
+
reason: r.String,
|
|
28
|
+
transient: r.Boolean
|
|
29
|
+
}) {
|
|
30
|
+
get message() {
|
|
31
|
+
return this.reason;
|
|
32
|
+
}
|
|
33
|
+
}, h = r.Union([
|
|
34
|
+
d,
|
|
35
|
+
f,
|
|
36
|
+
p,
|
|
37
|
+
m
|
|
38
|
+
]), g = n({
|
|
39
|
+
name: i,
|
|
40
|
+
source: "_voltro_connections",
|
|
41
|
+
input: r.Struct({}),
|
|
42
|
+
output: r.Array(u),
|
|
43
|
+
openAccess: "self-scoped read: projects the declared connections for the calling subject only (its own connect/disconnect state)"
|
|
44
|
+
}), _ = e({
|
|
45
|
+
name: a,
|
|
46
|
+
input: r.Struct({
|
|
47
|
+
connectionId: r.String,
|
|
48
|
+
redirectTo: r.optional(r.String)
|
|
49
|
+
}),
|
|
50
|
+
output: r.Struct({
|
|
51
|
+
authorizeUrl: r.String,
|
|
52
|
+
state: r.String
|
|
53
|
+
}),
|
|
54
|
+
error: h,
|
|
55
|
+
openAccess: "self-service: begins an oauth handshake that stores a credential for the calling subject only; anonymous callers fail typed with ConnectionSubjectRequired"
|
|
56
|
+
}), v = t({
|
|
57
|
+
name: o,
|
|
58
|
+
input: r.Struct({
|
|
59
|
+
connectionId: r.String,
|
|
60
|
+
token: r.String
|
|
61
|
+
}),
|
|
62
|
+
output: r.Struct({ ok: r.Boolean }),
|
|
63
|
+
error: h,
|
|
64
|
+
openAccess: "self-service: stores a pasted token as the calling subject's own credential; anonymous callers fail typed with ConnectionSubjectRequired"
|
|
65
|
+
}), y = t({
|
|
66
|
+
name: s,
|
|
67
|
+
input: r.Struct({ connectionId: r.String }),
|
|
68
|
+
output: r.Struct({ ok: r.Boolean }),
|
|
69
|
+
error: h,
|
|
70
|
+
openAccess: "self-service: deletes only the calling subject's own credential row for this connection"
|
|
71
|
+
});
|
|
72
|
+
//#endregion
|
|
73
|
+
export { i as CONNECTIONS_LIST_TAG, s as CONNECTION_DISCONNECT_TAG, a as CONNECTION_START_TAG, o as CONNECTION_SUBMIT_TOKEN_TAG, m as ConnectionHandshakeFailed, c as ConnectionKind, p as ConnectionKindMismatch, d as ConnectionNotDeclared, u as ConnectionState, l as ConnectionStatus, f as ConnectionSubjectRequired, y as connectionDisconnectDescriptor, _ as connectionStartDescriptor, v as connectionSubmitTokenDescriptor, g as connectionsListQueryDescriptor };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
//#region src/errorValue.ts
|
|
2
|
+
var e = (e) => {
|
|
3
|
+
if (typeof e != "object" || !e) return;
|
|
4
|
+
let t = e._tag;
|
|
5
|
+
return typeof t == "string" ? t : void 0;
|
|
6
|
+
}, t = (t) => {
|
|
7
|
+
if (typeof t == "string") return t;
|
|
8
|
+
if (typeof t == "object" && t) {
|
|
9
|
+
let n = t.message;
|
|
10
|
+
if (typeof n == "string" && n !== "") return n;
|
|
11
|
+
let r = e(t);
|
|
12
|
+
if (r !== void 0) return r;
|
|
13
|
+
}
|
|
14
|
+
return String(t);
|
|
15
|
+
}, n = (n) => {
|
|
16
|
+
if (n instanceof Error) return n;
|
|
17
|
+
let r = Error(t(n), { cause: n });
|
|
18
|
+
return r.name = e(n) ?? "NonErrorThrown", r;
|
|
19
|
+
};
|
|
20
|
+
//#endregion
|
|
21
|
+
export { t as errorMessage, e as errorTag, n as reportableError };
|