@krak-stack/auth 0.2.24 → 0.2.26
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 +24 -0
- package/README.md +44 -15
- package/dist/api.d.ts +731 -695
- package/dist/auth/api.group.d.ts +16 -0
- package/dist/auth/schema.d.ts +11 -0
- package/dist/auth/schema.js +3 -1
- package/dist/components/auth-atoms.d.ts +66 -2
- package/dist/components/auth-atoms.js +12 -3
- package/dist/components/auth-client-api.d.ts +16 -0
- package/dist/components/auth-provider.d.ts +2 -1
- package/dist/components/auth-provider.js +29 -3
- package/dist/schema.d.ts +3 -0
- package/dist/schema.js +5 -0
- package/dist/server/actor.js +12 -1
- package/dist/server/api.group.d.ts +4 -0
- package/dist/server/attribution.d.ts +1 -1
- package/dist/server/attribution.js +4 -2
- package/dist/server/middleware.js +12 -5
- package/dist/server/schema.d.ts +2 -0
- package/dist/service.d.ts +40 -0
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# @krak-stack/auth
|
|
2
2
|
|
|
3
|
+
## 0.2.26
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Automatically synchronize the signed-in user's preferred locale from the existing KrakstackProvider context through KrakstackAuthProvider. Existing consumers need only update the SDK version after the auth server has been deployed with locale support; no selector wrapper, provider prop, or consumer database migration is required. Skip synchronization during impersonation, preserve optimistic session updates with rollback, and expose optional onLocaleSyncError handling. The current interface locale is authoritative, including on provider mount and after a page reload.
|
|
8
|
+
|
|
9
|
+
## 0.2.25
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Require `@krak-stack/registry` version `^0.1.52` for the coordinated audit attribution and telemetry integration.
|
|
14
|
+
|
|
15
|
+
- Actor authorization adds standard `user.roles` from the current organization membership for historical audit snapshots, without confusing global roles or organization API keys with human members. Auth emits IDs and roles only, not names/photos. Clear inherited profile/role annotations alongside other auth attribution. Audit display names/photos are resolved dynamically from current organization membership.
|
|
16
|
+
|
|
17
|
+
Separate the responsible principal (`app.actor.type/id`, user or organization) from authentication (`app.auth.method`, session or api_key) and API-key record identity (`app.auth.credential.id`). Replace inherited authentication annotations together with actor annotations; never emit credentials or session tokens.
|
|
18
|
+
|
|
19
|
+
Emit `app.auth.impersonator.id` from a verified session's `impersonatedBy`, preserving the effective user's actor ID. Keep organization impersonation route restrictions unchanged and clear stale impersonator annotations for ordinary or anonymous requests.
|
|
20
|
+
|
|
21
|
+
- 32213bb: Add verified actor type/ID and API-key owner type/ID to AuthMiddleware log and span annotations, preserving existing user and organization attribution. Distinguish API-key principals from their owners without emitting credentials or changing the authentication model. This enables audit recording through inherited telemetry context; MCP and AI context remain integration-owned.
|
|
22
|
+
|
|
23
|
+
Replace the complete auth-owned annotation set so organization keys cannot inherit stale user IDs and users cannot inherit API-key owners. Preserve unrelated annotations and restore scoped log/child-span context after the handler. Clear stale fields on the already-created current span using empty strings because the tracer interface does not expose attribute removal.
|
|
24
|
+
|
|
25
|
+
Provide the same optional authentication and attribution for plain HttpRouter routes through AuthMiddleware.routerLayer, with optional exact-path scoping. Anonymous requests clear inherited attribution; auth service failures remain explicit. ActorRequired continues to own project authorization and CurrentActor without reconstructing telemetry attribution.
|
|
26
|
+
|
|
3
27
|
## 0.2.24
|
|
4
28
|
|
|
5
29
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -74,7 +74,7 @@ import { Layer } from "effect";
|
|
|
74
74
|
|
|
75
75
|
const telemetry = HttpApiOtlp.layer.pipe(
|
|
76
76
|
Layer.provide(AuthMiddleware.routerLayer({ paths: ["/api/otel/v1/logs"] })),
|
|
77
|
-
Layer.provide(Events.
|
|
77
|
+
Layer.provide(Events.ingestionLayer),
|
|
78
78
|
Layer.provide(eventsLayer),
|
|
79
79
|
);
|
|
80
80
|
```
|
|
@@ -116,22 +116,49 @@ import { DropdownMenuItem } from "@/components/ui/dropdown-menu";
|
|
|
116
116
|
|
|
117
117
|
See [React components and CSS](https://auth.krakstack.net/en/docs/components) for the provider and component requirements.
|
|
118
118
|
|
|
119
|
+
### Locale syncing
|
|
120
|
+
|
|
121
|
+
Nest `KrakstackAuthProvider` inside `KrakstackProvider`. The auth provider reads
|
|
122
|
+
the registry locale context and saves it to the signed-in user's `locale` when
|
|
123
|
+
it differs. It does not accept a `locale` prop or restore the interface language
|
|
124
|
+
from the saved account preference. Use `LocaleSwitcher` directly from
|
|
125
|
+
`@krak-stack/registry/locale-switcher` with your application's language-change
|
|
126
|
+
callback; no auth-specific selector wrapper is needed.
|
|
127
|
+
|
|
128
|
+
The context is authoritative, including after a Paraglide reload. Public pages
|
|
129
|
+
outside the auth provider change only the browser locale; pages inside it can
|
|
130
|
+
update the account even when the language comes from a localized URL. Signed-out
|
|
131
|
+
visitors do not trigger user updates. An optional `onLocaleSyncError` callback
|
|
132
|
+
lets the application display a localized save error without a retry loop.
|
|
133
|
+
|
|
134
|
+
Existing consumers already nesting `KrakstackAuthProvider` inside
|
|
135
|
+
`KrakstackProvider` only need an SDK version update after the auth server is
|
|
136
|
+
deployed with locale support. No consumer database migration, new provider prop,
|
|
137
|
+
or selector change is required. Impersonated sessions do not sync preferences.
|
|
138
|
+
|
|
139
|
+
Krakstack Auth emails use the recipient's saved language, falling back to the
|
|
140
|
+
request locale and then English when no valid saved preference exists.
|
|
141
|
+
See [locale syncing](https://auth.krakstack.net/en/docs/components#locale-syncing)
|
|
142
|
+
for setup, lifecycle behavior, and background-notification guidance.
|
|
143
|
+
|
|
119
144
|
## Authorization
|
|
120
145
|
|
|
121
146
|
Define project permissions with `defineProjectAccess`, resolve actors with `ActorRequired`, and enforce backend policies with `withPolicy`. Frontend permission helpers control presentation only.
|
|
122
147
|
|
|
123
148
|
`AuthMiddleware` annotates the current span, child spans and handler logs with verified attribution:
|
|
124
149
|
|
|
125
|
-
| Attribute
|
|
126
|
-
|
|
|
127
|
-
| `app.actor.type`
|
|
128
|
-
| `app.actor.id`
|
|
129
|
-
| `app.
|
|
130
|
-
| `app.
|
|
131
|
-
| `
|
|
132
|
-
| `
|
|
150
|
+
| Attribute | User session | User-owned API key | Organization-owned API key |
|
|
151
|
+
| -------------------------- | -------------------------------------- | -------------------------- | -------------------------- |
|
|
152
|
+
| `app.actor.type` | `user` | `user` | `organization` |
|
|
153
|
+
| `app.actor.id` | User ID | Owner user ID | Owner organization ID |
|
|
154
|
+
| `app.auth.method` | `session` | `api_key` | `api_key` |
|
|
155
|
+
| `app.auth.credential.id` | Omitted | API-key record ID | API-key record ID |
|
|
156
|
+
| `app.auth.impersonator.id` | Initiating admin ID when impersonating | Omitted | Omitted |
|
|
157
|
+
| `user.id` | User ID | Owner user ID | Omitted |
|
|
158
|
+
| `user.roles` | Organization roles | Owner's organization roles | Empty array |
|
|
159
|
+
| `organization.id` | Active organization ID | Active organization ID | Owner organization ID |
|
|
133
160
|
|
|
134
|
-
The `app.actor.*`
|
|
161
|
+
`user.id` and `user.roles` follow OpenTelemetry user semantic conventions. Roles are added by `ActorRequired`, not session-only router middleware. Names, photos, email addresses, API-key values, and session tokens are not emitted. OTel defines `user.name` as login/username and `user.full_name` as full name; neither is needed for attribution here. The `app.actor.*`, `app.auth.*` and existing `organization.id` fields are application conventions. The public authorization model still uses `type: "apiKey"`, but telemetry identifies its owning user or organization as the responsible principal and records the key separately as a credential. This replaces the previous `app.actor.owner.*` fields and API-key actor IDs; telemetry consumers must migrate together with the SDK. Audit consumers resolve current names/photos from organization membership for display, rather than copying them into logs. MCP and AI execution context belongs to the respective integration layers and does not replace the authenticated actor.
|
|
135
162
|
|
|
136
163
|
Auth-owned user, organization and actor annotations replace the inherited set,
|
|
137
164
|
preventing stale user/API-key owner attribution. Unrelated request, MCP and agent
|
|
@@ -140,10 +167,12 @@ Stale fields on an already-created current span are cleared to empty strings
|
|
|
140
167
|
because the tracer interface has no attribute-removal method; handler logs and
|
|
141
168
|
new child spans omit those fields entirely.
|
|
142
169
|
|
|
143
|
-
`ActorRequired`
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
170
|
+
`ActorRequired` resolves the project actor, enforces actor constraints, and provides
|
|
171
|
+
`CurrentActor`. It adds `user.roles` to logs and spans from the verified active
|
|
172
|
+
organization membership, not the global user role. Events recorded in the handler
|
|
173
|
+
retain that role snapshot even after membership changes. Session-only router
|
|
174
|
+
middleware does not look up roles. When supplying `AuthService` directly without
|
|
175
|
+
`AuthMiddleware`, only the verified roles are added; session profile/actor
|
|
176
|
+
attribution still requires `AuthMiddleware`.
|
|
148
177
|
|
|
149
178
|
See the [RBAC guide](https://auth.krakstack.net/en/docs/rbac).
|