@krak-stack/auth 0.2.31 → 0.2.32
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 +11 -0
- package/README.md +79 -1
- package/dist/api.d.ts +1453 -1393
- package/dist/auth/api.group.d.ts +19 -1
- package/dist/auth/api.group.js +17 -1
- package/dist/auth/schema.d.ts +12 -0
- package/dist/auth/schema.js +12 -0
- package/dist/components/account-deletion-request.d.ts +5 -0
- package/dist/components/account-deletion-request.js +7 -0
- package/dist/components/account-deletion.d.ts +8 -0
- package/dist/components/account-deletion.js +59 -0
- package/dist/components/admin-organizations.js +3 -2
- package/dist/components/associated-projects-notice.js +1 -1
- package/dist/components/auth-client-api.d.ts +33 -0
- package/dist/components/deletion-visibility.d.ts +1 -0
- package/dist/components/deletion-visibility.js +3 -0
- package/dist/components/organization-deletion-request.d.ts +17 -0
- package/dist/components/organization-deletion-request.js +9 -0
- package/dist/components/organization-switcher.js +31 -2
- package/dist/components/user-button.d.ts +29 -1
- package/dist/components/user-button.js +39 -2
- package/dist/extra/api.group.d.ts +13 -1
- package/dist/extra/api.group.js +5 -1
- package/dist/extra/schema.d.ts +13 -0
- package/dist/extra/schema.js +13 -0
- package/dist/schema.d.ts +35 -0
- package/dist/schema.js +25 -0
- package/dist/server/index.d.ts +2 -1
- package/dist/server/index.js +1 -0
- package/dist/server/middleware.d.ts +10 -2
- package/dist/server/middleware.js +4 -1
- package/dist/server/webhook-layer.d.ts +6 -0
- package/dist/server/webhook-layer.js +37 -0
- package/dist/server/webhooks.d.ts +38 -0
- package/dist/server/webhooks.js +39 -0
- package/dist/service.d.ts +66 -0
- package/package.json +7 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# @krak-stack/auth
|
|
2
2
|
|
|
3
|
+
## 0.2.32
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Require published Registry `0.1.61` or later for signed webhook-ID deduplication and the shared delivery table. Remove local Registry archive dependencies.
|
|
8
|
+
- Remove empty project-notice padding beneath user and organization menu headers.
|
|
9
|
+
- b497b8f: Require onDeleteUser when calling AuthMiddleware.layer. Projects provide their SQL cleanup callback; the middleware reads signing configuration, mounts the endpoint, and uses registry WebhooksReceiver for transactional deduplication. No separate auth-webhook service is needed. The layer now requires SQL; the former bare-auth-layer argument must be passed as authLayer in the options object.
|
|
10
|
+
- Temporarily hide account and organization deletion controls and dialogs in production builds, including admin organization deletion. Development builds retain these controls. Backend deletion authorization and cleanup remain unchanged.
|
|
11
|
+
- a46fb60: Add owner-confirmed organization deletion to the organization switcher and validated `organization.deletion_requested` cleanup webhooks, routed through the required `onDeleteOrganization` callback alongside `onDeleteUser`. Account deletion lists blocking organizations without deleting them. Unshared personal organizations are cleaned up with account deletion; standalone deletion remains protected.
|
|
12
|
+
- a46fb60: Use Registry's signed webhook-id for receiver deduplication and remove requestId and version from Auth webhook data. Requires the matching Registry signature protocol update on both sender and receiver.
|
|
13
|
+
|
|
3
14
|
## 0.2.31
|
|
4
15
|
|
|
5
16
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -57,6 +57,84 @@ const program = Effect.gen(function* () {
|
|
|
57
57
|
|
|
58
58
|
Use `AuthMiddleware.layer()` to provide request headers and configuration in an Effect HttpApi application. See the [middleware guide](https://auth.krakstack.net/en/docs/middleware).
|
|
59
59
|
|
|
60
|
+
### Auth webhooks
|
|
61
|
+
|
|
62
|
+
`AuthMiddleware.layer({ onDeleteUser, onDeleteOrganization })` requires both cleanup callbacks; there is no opt-out or default
|
|
63
|
+
successful cleanup. The SDK automatically mounts `POST /api/webhooks/auth`.
|
|
64
|
+
Every consuming project supplies only its application-specific SQL cleanup:
|
|
65
|
+
|
|
66
|
+
```ts
|
|
67
|
+
import { AuthMiddleware } from "@krak-stack/auth/server";
|
|
68
|
+
import { Layer } from "effect";
|
|
69
|
+
|
|
70
|
+
const authentication = AuthMiddleware.layer({
|
|
71
|
+
onDeleteUser: ({ userId }) => eraseLocalUserData(userId),
|
|
72
|
+
onDeleteOrganization: ({ organizationId }) => eraseLocalOrganizationData(organizationId),
|
|
73
|
+
// Optional: handle other Auth events. Validate event-specific data here.
|
|
74
|
+
onWebhook: (webhook) => handleOtherAuthEvent(webhook),
|
|
75
|
+
}).pipe(Layer.provide(databaseLayer));
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Set server-only `KRAKSTACK_AUTH_WEBHOOK_SECRET` (at least 32 characters) and
|
|
79
|
+
`VITE_KRAKSTACK_AUTH_PROJECT_ID`, or pass explicit `webhookSecret: Redacted<string>` and
|
|
80
|
+
`projectId` options. Missing/invalid configuration fails setup. The cleanup must
|
|
81
|
+
use the same SQL pool as the receiver; it executes in the receipt transaction.
|
|
82
|
+
Do not perform external side effects or launch unawaited work in the callback.
|
|
83
|
+
|
|
84
|
+
The middleware uses `WebhooksReceiver` from `@krak-stack/registry/webhooks`.
|
|
85
|
+
Receiver migrations create only deduplication receipts, not delivery tables or
|
|
86
|
+
workers. Signed `user.deletion_requested` envelopes have data
|
|
87
|
+
fields `projectId`, `userId`, and `scope: "account"`. Requests are
|
|
88
|
+
HMAC-authenticated, project-validated, limited to 16 KiB, and acknowledged only
|
|
89
|
+
after commit. The timestamp window is five minutes. Duplicates return 204;
|
|
90
|
+
changed content under the same signed `webhook-id` returns 409.
|
|
91
|
+
`organization.deletion_requested` routes validated data (
|
|
92
|
+
`projectId`, `organizationId`, `scope: "organization"`) to `onDeleteOrganization`.
|
|
93
|
+
Neither deletion event routes to `onWebhook`. Other
|
|
94
|
+
events retain their event-specific JSON data and route to `onWebhook`; without a
|
|
95
|
+
handler they return 400, never a successful acknowledgement. Cleanup failures
|
|
96
|
+
roll back the receipt and return 500 so delivery can retry.
|
|
97
|
+
|
|
98
|
+
Signatures cover `${webhookId}.${timestamp}.${rawBody}`. Upgrade sender and receiver
|
|
99
|
+
together: legacy signatures over only timestamp/body are rejected. Neither `requestId`
|
|
100
|
+
nor `version` is required in webhook data.
|
|
101
|
+
|
|
102
|
+
Explicitly schedule `WebhooksReceiver.cleanup()` for receipts older than 30 days;
|
|
103
|
+
handlers must remain idempotent after expiry. Central Auth uses Better Auth's
|
|
104
|
+
native delete-user flow and durably notifies connected projects after the user
|
|
105
|
+
has been removed. Configure the project's **Webhook URL** and copy its **Signing
|
|
106
|
+
secret** into the receiving server. Platform admins and organization owners must
|
|
107
|
+
transfer their roles before self-deleting. This does not guarantee that a project's
|
|
108
|
+
callback covers all personal data. Inventory invitations, logs, exports,
|
|
109
|
+
processors, and backups before claiming complete erasure. Use
|
|
110
|
+
`@krak-stack/registry` `0.1.61` or later and upgrade sender and receiver together.
|
|
111
|
+
Account and organization deletion controls are temporarily hidden in production
|
|
112
|
+
builds, including admin organization deletion. Development controls remain available;
|
|
113
|
+
this UI rollout gate does not disable server endpoints or change authorization.
|
|
114
|
+
|
|
115
|
+
**Français :** `AuthMiddleware.layer({ onDeleteUser, onDeleteOrganization })` exige les deux fonctions de nettoyage et monte la route de
|
|
116
|
+
réception automatiquement. Chaque projet doit fournir son nettoyage SQL et le
|
|
117
|
+
secret de signature côté serveur ; une configuration absente empêche le
|
|
118
|
+
démarrage. Le reçu et le nettoyage sont validés dans la même transaction.
|
|
119
|
+
Un doublon retourne 204, un conflit de contenu 409 et un échec de nettoyage 500.
|
|
120
|
+
La réception seule ne démarre aucun travailleur d’envoi. Planifier le nettoyage
|
|
121
|
+
des reçus après 30 jours et conserver un traitement idempotent. Le parcours de
|
|
122
|
+
suppression central utilise Better Auth et notifie les projets après suppression
|
|
123
|
+
de l’utilisateur. Configurez l’URL du webhook et son secret de signature dans le
|
|
124
|
+
projet. Les administrateurs de plateforme et propriétaires d’organisation doivent
|
|
125
|
+
d’abord transférer leurs rôles. `onDeleteUser` reçoit les données validées de suppression du compte ;
|
|
126
|
+
`onDeleteOrganization` reçoit celles de suppression de l’organisation.
|
|
127
|
+
Le gestionnaire facultatif `onWebhook` reçoit les
|
|
128
|
+
autres événements avec leurs données JSON ; sans gestionnaire, ils retournent 400.
|
|
129
|
+
La déduplication utilise l’en-tête `webhook-id` signé. Aucun `requestId` n’est requis dans les données.
|
|
130
|
+
La signature couvre `${webhookId}.${timestamp}.${rawBody}`. Mettre à jour les deux côtés ensemble :
|
|
131
|
+
les anciennes signatures sont refusées. Aucun champ `version` n’est requis dans les données.
|
|
132
|
+
Ce mécanisme ne garantit pas, à lui seul, la conformité ou l’effacement complet.
|
|
133
|
+
Utilisez `@krak-stack/registry` `0.1.61` ou une version ultérieure et mettez à jour les deux côtés ensemble.
|
|
134
|
+
Les commandes de suppression de compte et d’organisation, y compris dans l’administration,
|
|
135
|
+
sont temporairement masquées en production. Elles restent disponibles en développement ;
|
|
136
|
+
ce masquage ne désactive pas les points d’entrée serveur ni leurs contrôles d’autorisation.
|
|
137
|
+
|
|
60
138
|
`AuthMiddleware` also annotates request logs and spans with verified user,
|
|
61
139
|
organization, and actor IDs using its existing session lookup. Missing sessions
|
|
62
140
|
are anonymous; auth service failures are not silently treated as anonymous.
|
|
@@ -87,7 +165,7 @@ as `AuthMiddleware.layer()`. It does not grant permissions or provide `CurrentAc
|
|
|
87
165
|
|
|
88
166
|
## React Components
|
|
89
167
|
|
|
90
|
-
The component bundle uses the optional peer dependencies declared in `package.json` and Krakstack/shadcn UI primitives from `@krak-stack/registry`. Install the component peers used by your application; server-only
|
|
168
|
+
The component bundle uses the optional peer dependencies declared in `package.json` and Krakstack/shadcn UI primitives from `@krak-stack/registry`. Install the component peers used by your application. Server middleware needs `effect`, the matching registry package, and an SQL pool; React component peers are not needed for server-only use.
|
|
91
169
|
|
|
92
170
|
When components are configured, register their Tailwind source:
|
|
93
171
|
|