@voltro/protocol 0.1.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.
@@ -0,0 +1,64 @@
1
+ import { Context as e, Schema as t } from "effect";
2
+ import { RpcMiddleware as n } from "@effect/rpc";
3
+ //#region src/auth.ts
4
+ var r = t.Record({
5
+ key: t.String,
6
+ value: t.Unknown
7
+ }), i = t.optional(t.Array(t.String)), a = t.Struct({
8
+ type: t.Literal("user"),
9
+ id: t.String,
10
+ tenantId: t.String,
11
+ scopes: i,
12
+ metadata: t.optional(r)
13
+ }), o = t.Struct({
14
+ type: t.Literal("apiKey"),
15
+ id: t.String,
16
+ tenantId: t.String,
17
+ scopes: i,
18
+ metadata: t.optional(r)
19
+ }), s = t.Struct({
20
+ type: t.Literal("serviceAccount"),
21
+ id: t.String,
22
+ tenantId: t.String,
23
+ scopes: i,
24
+ metadata: t.optional(r)
25
+ }), c = t.Struct({
26
+ type: t.Literal("anonymous"),
27
+ id: t.Null,
28
+ tenantId: t.NullOr(t.String)
29
+ }), l = t.Struct({
30
+ type: t.Literal("system"),
31
+ id: t.String,
32
+ tenantId: t.Null,
33
+ scopes: i,
34
+ metadata: t.optional(r)
35
+ }), u = t.Union(a, o, s, c, l), d = (e) => ({
36
+ type: "anonymous",
37
+ id: null,
38
+ tenantId: e
39
+ }), f = (e, t = ["admin:full"]) => ({
40
+ type: "system",
41
+ id: e,
42
+ tenantId: null,
43
+ scopes: t
44
+ }), p = (e) => e.type === "system", m = class extends e.Tag("@voltro/Subject")() {}, h = class extends e.Tag("@voltro/ConnectionInfo")() {}, g = class extends n.Tag()("@voltro/AuthMiddleware", { provides: m }) {}, _ = class extends n.Tag()("@voltro/ConnectionInfoMiddleware", { provides: h }) {}, v = (e) => typeof e.mountRoutes == "function", y = (e, t) => async (n) => {
45
+ for (let r of e) {
46
+ let e = await r.resolve(n);
47
+ if (e.kind === "matched") return e.subject;
48
+ if (e.kind === "failed") {
49
+ t?.onStrategyFailed?.({
50
+ strategyId: r.id,
51
+ reason: e.reason
52
+ });
53
+ break;
54
+ }
55
+ }
56
+ if (t?.fallback) return t.fallback(n);
57
+ let r = n.headers["x-tenant"] ?? null;
58
+ if (r === null && t?.anonymousTenantRequired === !0) throw new b({ reason: "tenant required (x-tenant header missing)" });
59
+ return d(r);
60
+ }, b = class extends t.TaggedError()("Unauthenticated", { reason: t.optional(t.String) }) {}, x = (e, t) => {
61
+ if (e.type === "anonymous") throw new b(t === void 0 ? {} : { reason: t });
62
+ };
63
+ //#endregion
64
+ export { m as a, x as c, p as d, f, u as i, y as l, h as n, b as o, _ as r, d as s, g as t, v as u };