@krak-stack/auth 0.1.61 → 0.1.62
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/README.md +45 -65
- package/dist/access.d.ts +0 -6
- package/dist/access.js +1 -7
- package/dist/api.d.ts +332 -332
- package/dist/components/api-key-edit-form.js +7 -9
- package/dist/components/auth-client-api.d.ts +185 -185
- package/dist/components/auth-forms.d.ts +1 -0
- package/dist/components/auth-forms.js +50 -6
- package/dist/components/index.d.ts +1 -1
- package/dist/components/index.js +1 -1
- package/dist/components/project-access-matrix.d.ts +0 -2
- package/dist/components/project-access-matrix.js +0 -7
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/server/actor.d.ts +2 -16
- package/dist/server/actor.js +0 -16
- package/dist/server/middleware.js +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,86 +1,66 @@
|
|
|
1
1
|
# @krak-stack/auth
|
|
2
2
|
|
|
3
|
-
Effect
|
|
3
|
+
Typed Effect contracts, server authentication middleware, project authorization primitives, and React authentication components for Krakstack Auth.
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
7
|
-
```
|
|
7
|
+
```bash
|
|
8
8
|
bun add @krak-stack/auth effect
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
Choose a narrow package subpath for the runtime boundary:
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
| Entry point | Purpose |
|
|
14
|
+
| -------------------------------- | --------------------------------------------------------------------- |
|
|
15
|
+
| `@krak-stack/auth/server` | Proxy, `AuthMiddleware`, `AuthService`, `ActorRequired`, and policies |
|
|
16
|
+
| `@krak-stack/auth/components` | React provider, forms, account controls, and UI permission helpers |
|
|
17
|
+
| `@krak-stack/auth/access` | Typed project access definitions |
|
|
18
|
+
| `@krak-stack/auth/access/matrix` | Generated permission matrix |
|
|
19
|
+
| `@krak-stack/auth/api` | Combined Effect HttpApi contracts |
|
|
20
|
+
| `@krak-stack/auth/schema` | Shared schemas |
|
|
21
|
+
| `@krak-stack/auth/admin` | Administrative API contract |
|
|
22
|
+
| `@krak-stack/auth/extra` | Browser-facing extra API contract |
|
|
15
23
|
|
|
16
|
-
|
|
24
|
+
The complete export map is defined in `package.json` and documented at [auth.krakstack.net/en/docs/sdk](https://auth.krakstack.net/en/docs/sdk).
|
|
17
25
|
|
|
18
|
-
|
|
26
|
+
## Server Configuration
|
|
19
27
|
|
|
20
|
-
|
|
28
|
+
Server clients use:
|
|
21
29
|
|
|
22
|
-
|
|
30
|
+
```env
|
|
31
|
+
KRAKSTACK_AUTH_URL=https://auth.example.com
|
|
32
|
+
KRAKSTACK_AUTH_SERVICE_API_KEY=server_only_secret
|
|
33
|
+
```
|
|
23
34
|
|
|
24
|
-
|
|
25
|
-
- `server.getUser({ params: { id } })` - returns one user by ID.
|
|
35
|
+
`AuthClientConfig` accepts explicit `baseUrl` and redacted `apiKey` overrides. Never expose the service key through a `VITE_*` variable.
|
|
26
36
|
|
|
27
|
-
|
|
37
|
+
```ts
|
|
38
|
+
import { AuthService } from "@krak-stack/auth/server";
|
|
39
|
+
import { Effect } from "effect";
|
|
28
40
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
41
|
+
const program = Effect.gen(function* () {
|
|
42
|
+
const auth = yield* AuthService;
|
|
43
|
+
return yield* auth.requireUserOrganization();
|
|
44
|
+
});
|
|
45
|
+
```
|
|
34
46
|
|
|
35
|
-
|
|
47
|
+
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).
|
|
36
48
|
|
|
37
|
-
|
|
38
|
-
- `server.listOrganizationMembers({ params: { organizationId } })` - returns organization members with user contact details.
|
|
49
|
+
## React Components
|
|
39
50
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
const users = await Effect.runPromise(
|
|
45
|
-
Effect.gen(function* () {
|
|
46
|
-
const auth = yield* AuthClient;
|
|
47
|
-
return yield* auth.server.listUsersByIds({
|
|
48
|
-
query: { ids: "user_1,user_2" },
|
|
49
|
-
});
|
|
50
|
-
}).pipe(Effect.provide(AuthClient.layer)),
|
|
51
|
-
);
|
|
52
|
-
|
|
53
|
-
const organizations = await Effect.runPromise(
|
|
54
|
-
Effect.gen(function* () {
|
|
55
|
-
const auth = yield* AuthClient;
|
|
56
|
-
return yield* auth.server.listOrganizations({
|
|
57
|
-
query: { userId: "user_1" },
|
|
58
|
-
});
|
|
59
|
-
}).pipe(Effect.provide(AuthClient.layer)),
|
|
60
|
-
);
|
|
61
|
-
```
|
|
51
|
+
The current emitted component bundle expects Krakstack/shadcn UI aliases and additional consumer runtime packages. Validate the packed package in the target application before adopting the UI surface. The server-only entry points have a smaller integration boundary.
|
|
52
|
+
|
|
53
|
+
When components are configured, register their Tailwind source:
|
|
62
54
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
```tsx
|
|
68
|
-
import { OrganizationSwitcher, UserButton } from "@krak-stack/auth";
|
|
69
|
-
import { DropdownMenuItem } from "@/components/ui/dropdown-menu";
|
|
70
|
-
|
|
71
|
-
<OrganizationSwitcher
|
|
72
|
-
allowedOrganizationIds={["organization-id"]}
|
|
73
|
-
features={{
|
|
74
|
-
organizationCreation: false,
|
|
75
|
-
organizationSwitching: false,
|
|
76
|
-
userInvitations: false,
|
|
77
|
-
}}
|
|
78
|
-
menuActions={
|
|
79
|
-
<DropdownMenuItem render={<a href="/organization" />}>
|
|
80
|
-
Dashboard
|
|
81
|
-
</DropdownMenuItem>
|
|
82
|
-
}
|
|
83
|
-
side="bottom"
|
|
84
|
-
/>
|
|
85
|
-
<UserButton signOutRedirect="/" side="bottom" />
|
|
55
|
+
```css
|
|
56
|
+
@import "tailwindcss";
|
|
57
|
+
@import "@krak-stack/auth/tailwind.css";
|
|
86
58
|
```
|
|
59
|
+
|
|
60
|
+
See [React components and CSS](https://auth.krakstack.net/en/docs/components) for the provider and component requirements.
|
|
61
|
+
|
|
62
|
+
## Authorization
|
|
63
|
+
|
|
64
|
+
Define project permissions with `defineProjectAccess`, resolve actors with `ActorRequired`, and enforce backend policies with `withPolicy`. Frontend permission helpers control presentation only.
|
|
65
|
+
|
|
66
|
+
See the [RBAC guide](https://auth.krakstack.net/en/docs/rbac).
|
package/dist/access.d.ts
CHANGED
|
@@ -15,9 +15,6 @@ export type ApiKeyOwner = {
|
|
|
15
15
|
} | {
|
|
16
16
|
readonly type: "organization";
|
|
17
17
|
readonly organizationId: string;
|
|
18
|
-
} | {
|
|
19
|
-
readonly type: "service";
|
|
20
|
-
readonly serviceId: string;
|
|
21
18
|
};
|
|
22
19
|
export type ApiKeyActor = {
|
|
23
20
|
readonly type: "apiKey";
|
|
@@ -51,7 +48,6 @@ export type ProjectAccessDefinition<Project extends string = string, Action exte
|
|
|
51
48
|
readonly apiKeys: {
|
|
52
49
|
readonly user: ReadonlyArray<Action>;
|
|
53
50
|
readonly organization: ReadonlyArray<Action>;
|
|
54
|
-
readonly service: ReadonlyArray<Action>;
|
|
55
51
|
};
|
|
56
52
|
readonly qualify: (action: Action) => ProjectPermission<Project, Action>;
|
|
57
53
|
readonly permission: (action: Action) => Policy;
|
|
@@ -66,7 +62,6 @@ export type ProjectAccessDefinition<Project extends string = string, Action exte
|
|
|
66
62
|
readonly apiKeyPermissions: {
|
|
67
63
|
readonly user: ApiKeyPermissionGrant;
|
|
68
64
|
readonly organization: ApiKeyPermissionGrant;
|
|
69
|
-
readonly service: ApiKeyPermissionGrant;
|
|
70
65
|
};
|
|
71
66
|
readonly actorForUser: (input: {
|
|
72
67
|
readonly userId: string;
|
|
@@ -107,7 +102,6 @@ export type ProjectAccessConfig<Project extends string, Permissions extends Read
|
|
|
107
102
|
readonly apiKeys?: {
|
|
108
103
|
readonly user?: ReadonlyArray<Permissions[number]>;
|
|
109
104
|
readonly organization?: ReadonlyArray<Permissions[number]>;
|
|
110
|
-
readonly service?: ReadonlyArray<Permissions[number]>;
|
|
111
105
|
};
|
|
112
106
|
};
|
|
113
107
|
export declare const defineProjectAccess: <const Project extends string, const Permissions extends ReadonlyArray<string>>(config: ProjectAccessConfig<Project, Permissions>) => ProjectAccessDefinition<Project, Permissions[number]>;
|
package/dist/access.js
CHANGED
|
@@ -54,7 +54,6 @@ export const defineProjectAccess = (config) => {
|
|
|
54
54
|
});
|
|
55
55
|
const userApiKeyActions = (config.apiKeys?.user ?? []).filter((action) => allowedActions.has(action));
|
|
56
56
|
const organizationApiKeyActions = (config.apiKeys?.organization ?? []).filter((action) => allowedActions.has(action));
|
|
57
|
-
const serviceApiKeyActions = (config.apiKeys?.service ?? []).filter((action) => allowedActions.has(action));
|
|
58
57
|
const actorForUser = (input) => {
|
|
59
58
|
const roles = roleList(input.roles);
|
|
60
59
|
return {
|
|
@@ -76,18 +75,15 @@ export const defineProjectAccess = (config) => {
|
|
|
76
75
|
return intersection(intersection(permissionsForRoles(input.owner.roles), permissionsForActions(userApiKeyActions)), keyPermissions);
|
|
77
76
|
case "organization":
|
|
78
77
|
return intersection(permissionsForActions(organizationApiKeyActions), keyPermissions);
|
|
79
|
-
case "service":
|
|
80
|
-
return intersection(permissionsForActions(serviceApiKeyActions), keyPermissions);
|
|
81
78
|
}
|
|
82
79
|
})();
|
|
83
|
-
const organizationId = input.owner.type === "service" ? null : input.owner.organizationId;
|
|
84
80
|
return {
|
|
85
81
|
actor: {
|
|
86
82
|
type: "apiKey",
|
|
87
83
|
apiKeyId: input.apiKeyId,
|
|
88
84
|
owner: input.owner,
|
|
89
85
|
},
|
|
90
|
-
organizationId,
|
|
86
|
+
organizationId: input.owner.organizationId,
|
|
91
87
|
permissions,
|
|
92
88
|
};
|
|
93
89
|
};
|
|
@@ -98,7 +94,6 @@ export const defineProjectAccess = (config) => {
|
|
|
98
94
|
apiKeys: {
|
|
99
95
|
user: userApiKeyActions,
|
|
100
96
|
organization: organizationApiKeyActions,
|
|
101
|
-
service: serviceApiKeyActions,
|
|
102
97
|
},
|
|
103
98
|
qualify,
|
|
104
99
|
permission: (action) => permission(qualify(action)),
|
|
@@ -110,7 +105,6 @@ export const defineProjectAccess = (config) => {
|
|
|
110
105
|
apiKeyPermissions: {
|
|
111
106
|
user: encodeGrant(userApiKeyActions),
|
|
112
107
|
organization: encodeGrant(organizationApiKeyActions),
|
|
113
|
-
service: encodeGrant(serviceApiKeyActions),
|
|
114
108
|
},
|
|
115
109
|
actorForUser,
|
|
116
110
|
actorForApiKey,
|