@krak-stack/auth 0.2.24 → 0.2.25
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 +18 -0
- package/README.md +19 -15
- package/dist/api.d.ts +695 -695
- package/dist/server/actor.js +12 -1
- package/dist/server/attribution.d.ts +1 -1
- package/dist/server/attribution.js +4 -2
- package/dist/server/middleware.js +12 -5
- package/package.json +3 -3
package/dist/server/actor.js
CHANGED
|
@@ -110,7 +110,18 @@ const matchesConstraint = (actor, constraint) => {
|
|
|
110
110
|
const requiredActor = (access, constraint) => resolveCurrentActor(access).pipe(Effect.flatMap((actor) => matchesConstraint(actor, constraint)
|
|
111
111
|
? Effect.succeed(actor)
|
|
112
112
|
: Effect.fail(new HttpApiError.Forbidden({}))));
|
|
113
|
-
const withCurrentActor = (httpEffect, actor) =>
|
|
113
|
+
const withCurrentActor = (httpEffect, actor) => {
|
|
114
|
+
const roles = actor.actor.type === "user"
|
|
115
|
+
? actor.actor.roles
|
|
116
|
+
: actor.actor.owner.type === "user"
|
|
117
|
+
? actor.actor.owner.roles
|
|
118
|
+
: [];
|
|
119
|
+
// These are verified active-organization roles, never the global user.role.
|
|
120
|
+
return Effect.gen(function* () {
|
|
121
|
+
yield* Effect.annotateCurrentSpan({ "user.roles": roles });
|
|
122
|
+
return yield* httpEffect.pipe(Effect.provideService(CurrentActor, actor), Effect.annotateLogs({ "user.roles": roles }), Effect.annotateSpans({ "user.roles": roles }));
|
|
123
|
+
});
|
|
124
|
+
};
|
|
114
125
|
export function ActorRequired(constraint) {
|
|
115
126
|
if (!constraint)
|
|
116
127
|
return AnyActorRequired;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
2
|
/** Replace auth-owned attribution rather than merging it with an outer actor. */
|
|
3
|
-
export declare const withAuthAnnotations: <A, E, R>(effect: Effect.Effect<A, E, R>, attributes: Readonly<Record<string, string
|
|
3
|
+
export declare const withAuthAnnotations: <A, E, R>(effect: Effect.Effect<A, E, R>, attributes: Readonly<Record<string, string | ReadonlyArray<string>>>) => Effect.Effect<A, E, Exclude<Exclude<R, never>, never>>;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { Effect, Option, References } from "effect";
|
|
2
2
|
/** Replace auth-owned attribution rather than merging it with an outer actor. */
|
|
3
3
|
export const withAuthAnnotations = (effect, attributes) => {
|
|
4
|
-
const ownedAttribute = (key) => key
|
|
4
|
+
const ownedAttribute = (key) => key.startsWith("user.") ||
|
|
5
|
+
key.startsWith("app.user.") ||
|
|
5
6
|
key === "organization.id" ||
|
|
6
|
-
key.startsWith("app.actor.")
|
|
7
|
+
key.startsWith("app.actor.") ||
|
|
8
|
+
key.startsWith("app.auth.");
|
|
7
9
|
const replaceAttribution = (annotations) => ({
|
|
8
10
|
...Object.fromEntries(Object.entries(annotations).filter(([key]) => !ownedAttribute(key))),
|
|
9
11
|
...attributes,
|
|
@@ -68,21 +68,28 @@ const sessionAnnotations = (session) => {
|
|
|
68
68
|
const attributes = {};
|
|
69
69
|
if (!session)
|
|
70
70
|
return attributes;
|
|
71
|
-
if (session.user
|
|
71
|
+
if (session.user &&
|
|
72
|
+
(session.authMethod.type === "cookie" ||
|
|
73
|
+
session.authMethod.apiKey.configId === "user")) {
|
|
72
74
|
attributes["user.id"] = session.user.id;
|
|
75
|
+
}
|
|
73
76
|
if (session.session.activeOrganizationId) {
|
|
74
77
|
attributes["organization.id"] = session.session.activeOrganizationId;
|
|
75
78
|
}
|
|
76
79
|
if (session.authMethod.type === "cookie" && session.user) {
|
|
77
80
|
attributes["app.actor.type"] = "user";
|
|
78
81
|
attributes["app.actor.id"] = session.user.id;
|
|
82
|
+
attributes["app.auth.method"] = "session";
|
|
83
|
+
if (session.session.impersonatedBy) {
|
|
84
|
+
attributes["app.auth.impersonator.id"] = session.session.impersonatedBy;
|
|
85
|
+
}
|
|
79
86
|
}
|
|
80
87
|
else if (session.authMethod.type === "apiKey") {
|
|
81
88
|
const key = session.authMethod.apiKey;
|
|
82
|
-
attributes["app.actor.type"] =
|
|
83
|
-
attributes["app.actor.id"] = key.
|
|
84
|
-
attributes["app.
|
|
85
|
-
attributes["app.
|
|
89
|
+
attributes["app.actor.type"] = key.configId;
|
|
90
|
+
attributes["app.actor.id"] = key.referenceId;
|
|
91
|
+
attributes["app.auth.method"] = "api_key";
|
|
92
|
+
attributes["app.auth.credential.id"] = key.id;
|
|
86
93
|
}
|
|
87
94
|
return attributes;
|
|
88
95
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@krak-stack/auth",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.25",
|
|
4
4
|
"description": "Effect HttpApi clients and schemas for KrakStack Auth.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"files": [
|
|
@@ -76,10 +76,10 @@
|
|
|
76
76
|
"react-qr-code": "^2.2.0"
|
|
77
77
|
},
|
|
78
78
|
"devDependencies": {
|
|
79
|
-
"@krak-stack/registry": "0.1.
|
|
79
|
+
"@krak-stack/registry": "0.1.52"
|
|
80
80
|
},
|
|
81
81
|
"peerDependencies": {
|
|
82
|
-
"@krak-stack/registry": "^0.1.
|
|
82
|
+
"@krak-stack/registry": "^0.1.52",
|
|
83
83
|
"@tanstack/react-router": "^1.170.15",
|
|
84
84
|
"effect": "^4.0.0",
|
|
85
85
|
"input-otp": "^1.5.0",
|