@krak-stack/auth 0.1.70 → 0.2.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.
- package/README.md +4 -3
- package/dist/access.d.ts +4 -4
- package/dist/access.js +10 -4
- package/dist/admin/api.group.d.ts +17 -17
- package/dist/admin/api.group.js +2 -2
- package/dist/admin/schema.d.ts +18 -18
- package/dist/admin/schema.js +3 -3
- package/dist/api.d.ts +2093 -631
- package/dist/api.js +7 -7
- package/dist/auth/api.group.d.ts +793 -0
- package/dist/auth/api.group.js +241 -0
- package/dist/auth/schema.d.ts +800 -0
- package/dist/auth/schema.js +625 -0
- package/dist/components/admin-organization-form.d.ts +1 -1
- package/dist/components/admin-organization-form.js +16 -18
- package/dist/components/admin-organizations.js +52 -46
- package/dist/components/admin-users.js +115 -138
- package/dist/components/api-key-edit-form.d.ts +4 -3
- package/dist/components/api-key-edit-form.js +32 -27
- package/dist/components/api-key-permissions.d.ts +1 -1
- package/dist/components/api-key-rate-limit.d.ts +1 -1
- package/dist/components/api-key-referrers.d.ts +3 -2
- package/dist/components/api-key-referrers.js +2 -3
- package/dist/components/api-key.d.ts +0 -9
- package/dist/components/api-key.js +0 -39
- package/dist/components/auth-atoms.d.ts +178 -0
- package/dist/components/auth-atoms.js +46 -0
- package/dist/components/auth-client-api.d.ts +2474 -142
- package/dist/components/auth-client-api.js +14 -10
- package/dist/components/auth-forms.d.ts +1 -3
- package/dist/components/auth-forms.js +168 -195
- package/dist/components/auth-provider.d.ts +3 -7
- package/dist/components/auth-provider.js +56 -30
- package/dist/components/has-permission.js +1 -1
- package/dist/components/index.d.ts +19 -20
- package/dist/components/index.js +13 -13
- package/dist/components/member-required.d.ts +1 -3
- package/dist/components/member-required.js +102 -78
- package/dist/components/organization-switcher.d.ts +4 -6
- package/dist/components/organization-switcher.js +469 -324
- package/dist/components/project-access-matrix.d.ts +1 -1
- package/dist/components/project-access-matrix.js +9 -13
- package/dist/components/user-button.d.ts +5 -3
- package/dist/components/user-button.js +265 -316
- package/dist/components/utils.d.ts +3 -1
- package/dist/components/utils.js +4 -11
- package/dist/extra/api.group.d.ts +3 -3
- package/dist/extra/api.group.js +6 -6
- package/dist/extra/schema.js +1 -1
- package/dist/index.d.ts +11 -12
- package/dist/index.js +11 -12
- package/dist/query.d.ts +2 -2
- package/dist/roles.d.ts +5 -4
- package/dist/roles.js +11 -7
- package/dist/schema.d.ts +1 -1
- package/dist/schema.js +26 -19
- package/dist/server/actor.d.ts +30 -32
- package/dist/server/actor.js +39 -22
- package/dist/server/api.group.js +2 -2
- package/dist/server/index.d.ts +14 -14
- package/dist/server/index.js +8 -8
- package/dist/server/middleware.d.ts +3 -3
- package/dist/server/middleware.js +10 -5
- package/dist/server/schema.js +1 -1
- package/dist/service.d.ts +2053 -201
- package/dist/service.js +32 -21
- package/package.json +10 -9
- package/dist/better-auth/api.group.d.ts +0 -62
- package/dist/better-auth/api.group.js +0 -39
- package/dist/better-auth/schema.d.ts +0 -72
- package/dist/better-auth/schema.js +0 -110
- package/dist/components/auth-client.d.ts +0 -50
- package/dist/components/auth-client.js +0 -46
package/README.md
CHANGED
|
@@ -17,6 +17,7 @@ Choose a narrow package subpath for the runtime boundary:
|
|
|
17
17
|
| `@krak-stack/auth/access` | Typed project access definitions |
|
|
18
18
|
| `@krak-stack/auth/access/matrix` | Generated permission matrix |
|
|
19
19
|
| `@krak-stack/auth/api` | Combined Effect HttpApi contracts |
|
|
20
|
+
| `@krak-stack/auth/auth` | Browser authentication HttpApi group and schemas |
|
|
20
21
|
| `@krak-stack/auth/schema` | Shared schemas |
|
|
21
22
|
| `@krak-stack/auth/admin` | Administrative API contract |
|
|
22
23
|
| `@krak-stack/auth/extra` | Browser-facing extra API contract |
|
|
@@ -48,7 +49,7 @@ Use `AuthMiddleware.layer()` to provide request headers and configuration in an
|
|
|
48
49
|
|
|
49
50
|
## React Components
|
|
50
51
|
|
|
51
|
-
The
|
|
52
|
+
The component bundle uses the peer dependencies declared in `package.json` and Krakstack/shadcn UI primitives from `@krak-stack/registry`. The server-only entry points have a smaller integration boundary.
|
|
52
53
|
|
|
53
54
|
When components are configured, register their Tailwind source:
|
|
54
55
|
|
|
@@ -57,12 +58,12 @@ When components are configured, register their Tailwind source:
|
|
|
57
58
|
@import "@krak-stack/auth/tailwind.css";
|
|
58
59
|
```
|
|
59
60
|
|
|
60
|
-
|
|
61
|
+
The React components use the exported Effect query atoms and the owned authentication HTTP group. Browser requests include credentials so hosted components can resolve sessions across configured origins.
|
|
61
62
|
|
|
62
63
|
`UserButton` accepts `menuActions` for app-owned menu items such as dashboard or workspace links:
|
|
63
64
|
|
|
64
65
|
```tsx
|
|
65
|
-
import { UserButton } from "@krak-stack/auth";
|
|
66
|
+
import { UserButton } from "@krak-stack/auth/components";
|
|
66
67
|
import { DropdownMenuItem } from "@/components/ui/dropdown-menu";
|
|
67
68
|
|
|
68
69
|
<UserButton
|
package/dist/access.d.ts
CHANGED
|
@@ -51,13 +51,13 @@ export type ProjectAccessDefinition<Project extends string = string, Action exte
|
|
|
51
51
|
};
|
|
52
52
|
readonly qualify: (action: Action) => ProjectPermission<Project, Action>;
|
|
53
53
|
readonly permission: (action: Action) => Policy;
|
|
54
|
-
readonly permissionsForRoles: (roles:
|
|
54
|
+
readonly permissionsForRoles: (roles: typeof Schema.Unknown.Type) => ReadonlySet<ProjectPermission<Project, Action>>;
|
|
55
55
|
readonly permissionsForGrant: (grant: ApiKeyPermissionGrant | null | undefined) => ReadonlySet<ProjectPermission<Project, Action>>;
|
|
56
56
|
readonly permissionsForUserKey: (input: {
|
|
57
57
|
readonly grant: ApiKeyPermissionGrant | null | undefined;
|
|
58
|
-
readonly roles:
|
|
58
|
+
readonly roles: typeof Schema.Unknown.Type;
|
|
59
59
|
}) => ReadonlySet<ProjectPermission<Project, Action>>;
|
|
60
|
-
readonly decodeGrant: (input:
|
|
60
|
+
readonly decodeGrant: (input: typeof Schema.Unknown.Type) => Effect.Effect<ReadonlySet<ProjectPermission<Project, Action>>, Schema.SchemaError>;
|
|
61
61
|
readonly encodeGrant: (actions: ReadonlyArray<Action>) => ApiKeyPermissionGrant;
|
|
62
62
|
readonly apiKeyPermissions: {
|
|
63
63
|
readonly user: ApiKeyPermissionGrant;
|
|
@@ -66,7 +66,7 @@ export type ProjectAccessDefinition<Project extends string = string, Action exte
|
|
|
66
66
|
readonly actorForUser: (input: {
|
|
67
67
|
readonly userId: string;
|
|
68
68
|
readonly organizationId: string | null;
|
|
69
|
-
readonly roles:
|
|
69
|
+
readonly roles: typeof Schema.Unknown.Type;
|
|
70
70
|
}) => CurrentActor;
|
|
71
71
|
readonly actorForApiKey: (input: {
|
|
72
72
|
readonly apiKeyId: string;
|
package/dist/access.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Context, Effect, Schema } from "effect";
|
|
2
|
-
import { parseRoleList } from "./roles";
|
|
2
|
+
import { parseRoleList } from "./roles.js";
|
|
3
3
|
export const ApiKeyPermissionGrant = Schema.Record(Schema.String, Schema.Array(Schema.String)).annotate({
|
|
4
4
|
identifier: "ApiKeyPermissionGrant",
|
|
5
5
|
title: "API key permission grant",
|
|
6
|
-
description: "
|
|
6
|
+
description: "Resource and action permissions assigned to an API key.",
|
|
7
7
|
});
|
|
8
8
|
export const CurrentActor = Context.Service("@krak-stack/auth/CurrentActor");
|
|
9
9
|
export class Forbidden extends Schema.ErrorClass("Forbidden")({
|
|
@@ -33,7 +33,13 @@ const roleList = (input) => Array.isArray(input)
|
|
|
33
33
|
: parseRoleList(input);
|
|
34
34
|
export const defineProjectAccess = (config) => {
|
|
35
35
|
const allowedActions = new Set(config.permissions);
|
|
36
|
-
const
|
|
36
|
+
const isAction = (action) => config.permissions.some((allowed) => allowed === action);
|
|
37
|
+
const QualifiedPermissionSchema = Schema.TemplateLiteral([
|
|
38
|
+
Schema.Literal(config.project),
|
|
39
|
+
Schema.Literal(":"),
|
|
40
|
+
Schema.Literals(config.permissions),
|
|
41
|
+
]);
|
|
42
|
+
const qualify = (action) => Schema.decodeUnknownSync(QualifiedPermissionSchema)(`${config.project}:${action}`);
|
|
37
43
|
const permissionsForActions = (actions) => new Set(Array.from(actions, (action) => qualify(action)));
|
|
38
44
|
const permissionsForRoles = (input) => {
|
|
39
45
|
const actions = new Set();
|
|
@@ -46,7 +52,7 @@ export const defineProjectAccess = (config) => {
|
|
|
46
52
|
return permissionsForActions(actions);
|
|
47
53
|
};
|
|
48
54
|
const permissionsForGrant = (grant) => {
|
|
49
|
-
const actions = (grant?.[config.project] ?? []).filter(
|
|
55
|
+
const actions = (grant?.[config.project] ?? []).filter(isAction);
|
|
50
56
|
return permissionsForActions(actions);
|
|
51
57
|
};
|
|
52
58
|
const encodeGrant = (actions) => ({
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { HttpApiEndpoint, HttpApiError, HttpApiGroup } from "effect/unstable/httpapi";
|
|
2
2
|
import { Schema } from "effect";
|
|
3
|
-
export * from "./schema";
|
|
3
|
+
export * from "./schema.js";
|
|
4
4
|
export declare const AdminApiGroup: HttpApiGroup.HttpApiGroup<"admin", HttpApiEndpoint.HttpApiEndpoint<"createDomain", "POST", "/admin/domains", HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<Schema.Struct<{
|
|
5
5
|
readonly hostname: Schema.NonEmptyString;
|
|
6
6
|
readonly rootHostname: Schema.NonEmptyString;
|
|
@@ -221,26 +221,26 @@ export declare const AdminApiGroup: HttpApiGroup.HttpApiGroup<"admin", HttpApiEn
|
|
|
221
221
|
}>>, Schema.String, never, never>, never, never>>;
|
|
222
222
|
readonly projectId: Schema.optional<Schema.String>;
|
|
223
223
|
}>>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<Schema.Struct<{
|
|
224
|
-
readonly data: Schema.$Array<Schema.
|
|
225
|
-
readonly id:
|
|
226
|
-
readonly name:
|
|
227
|
-
readonly slug:
|
|
228
|
-
readonly logo
|
|
229
|
-
readonly metadata
|
|
230
|
-
readonly userId
|
|
231
|
-
readonly parentId
|
|
232
|
-
readonly memberCount
|
|
233
|
-
readonly memberPreviews
|
|
224
|
+
readonly data: Schema.$Array<Schema.Struct<{
|
|
225
|
+
readonly id: Schema.String;
|
|
226
|
+
readonly name: Schema.String;
|
|
227
|
+
readonly slug: Schema.String;
|
|
228
|
+
readonly logo: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
229
|
+
readonly metadata: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
230
|
+
readonly userId: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
231
|
+
readonly parentId: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
232
|
+
readonly memberCount: Schema.optional<Schema.Number>;
|
|
233
|
+
readonly memberPreviews: Schema.optional<Schema.$Array<Schema.Struct<{
|
|
234
234
|
readonly id: Schema.String;
|
|
235
235
|
readonly name: Schema.String;
|
|
236
236
|
readonly image: Schema.NullOr<Schema.String>;
|
|
237
|
-
}
|
|
238
|
-
readonly projects
|
|
237
|
+
}>>>;
|
|
238
|
+
readonly projects: Schema.optional<Schema.$Array<Schema.Struct<{
|
|
239
239
|
readonly id: Schema.String;
|
|
240
240
|
readonly name: Schema.String;
|
|
241
241
|
readonly logo: Schema.NullOr<Schema.String>;
|
|
242
|
-
}
|
|
243
|
-
readonly createdAt: Date;
|
|
242
|
+
}>>>;
|
|
243
|
+
readonly createdAt: Schema.Date;
|
|
244
244
|
}>>;
|
|
245
245
|
readonly meta: Schema.Struct<{
|
|
246
246
|
readonly page: Schema.Int;
|
|
@@ -258,7 +258,7 @@ export declare const AdminApiGroup: HttpApiGroup.HttpApiGroup<"admin", HttpApiEn
|
|
|
258
258
|
}>>, Schema.String, never, never>, never, never>>;
|
|
259
259
|
readonly projectId: Schema.optional<Schema.String>;
|
|
260
260
|
}>>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<Schema.Struct<{
|
|
261
|
-
readonly data: Schema.$Array<Schema.
|
|
261
|
+
readonly data: Schema.$Array<Schema.Struct<{
|
|
262
262
|
readonly id: Schema.String;
|
|
263
263
|
readonly name: Schema.String;
|
|
264
264
|
readonly email: Schema.String;
|
|
@@ -280,7 +280,7 @@ export declare const AdminApiGroup: HttpApiGroup.HttpApiGroup<"admin", HttpApiEn
|
|
|
280
280
|
readonly name: Schema.String;
|
|
281
281
|
readonly logo: Schema.NullOr<Schema.String>;
|
|
282
282
|
}>>;
|
|
283
|
-
}
|
|
283
|
+
}>>;
|
|
284
284
|
readonly meta: Schema.Struct<{
|
|
285
285
|
readonly page: Schema.Int;
|
|
286
286
|
readonly pageSize: Schema.Int;
|
package/dist/admin/api.group.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { HttpApiEndpoint, HttpApiError, HttpApiGroup, OpenApi, } from "effect/unstable/httpapi";
|
|
2
2
|
import { Schema } from "effect";
|
|
3
|
-
import { AdminCreateOrganizationPayload, AdminApiKey, AdminApiKeyIdParams, AdminListQuery, AdminOrganization, AdminOrganizationIdParams, AdminUpdateApiKeyPayload, AdminUpdateOrganizationPayload, DashboardStatsQuery, DashboardStatsResponse, PaginatedAdminOrganizations, PaginatedAdminUsers, ServerCreateDomainPayload, ServerDomain, ServerDomainIdParams, ServerDomainRecordsResponse, ServerUpdateDomainPayload, } from "./schema";
|
|
4
|
-
export * from "./schema";
|
|
3
|
+
import { AdminCreateOrganizationPayload, AdminApiKey, AdminApiKeyIdParams, AdminListQuery, AdminOrganization, AdminOrganizationIdParams, AdminUpdateApiKeyPayload, AdminUpdateOrganizationPayload, DashboardStatsQuery, DashboardStatsResponse, PaginatedAdminOrganizations, PaginatedAdminUsers, ServerCreateDomainPayload, ServerDomain, ServerDomainIdParams, ServerDomainRecordsResponse, ServerUpdateDomainPayload, } from "./schema.js";
|
|
4
|
+
export * from "./schema.js";
|
|
5
5
|
export const AdminApiGroup = HttpApiGroup.make("admin")
|
|
6
6
|
.add(HttpApiEndpoint.get("dashboardStats", "/admin/dashboard-stats", {
|
|
7
7
|
query: DashboardStatsQuery,
|
package/dist/admin/schema.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Schema } from "effect";
|
|
2
|
-
import { ServerCreateDomainPayload, ServerDomain, ServerDomainIdParams, ServerDomainRecordsResponse, ServerUpdateDomainPayload } from "../server/schema";
|
|
2
|
+
import { ServerCreateDomainPayload, ServerDomain, ServerDomainIdParams, ServerDomainRecordsResponse, ServerUpdateDomainPayload } from "../server/schema.js";
|
|
3
3
|
export declare const AdminListQuery: Schema.Struct<{
|
|
4
4
|
readonly page: Schema.Int;
|
|
5
5
|
readonly pageSize: Schema.Int;
|
|
@@ -155,7 +155,7 @@ export declare const DashboardStatsResponse: Schema.Struct<{
|
|
|
155
155
|
}>>;
|
|
156
156
|
}>;
|
|
157
157
|
export declare const PaginatedAdminUsers: Schema.Struct<{
|
|
158
|
-
readonly data: Schema.$Array<Schema.
|
|
158
|
+
readonly data: Schema.$Array<Schema.Struct<{
|
|
159
159
|
readonly id: Schema.String;
|
|
160
160
|
readonly name: Schema.String;
|
|
161
161
|
readonly email: Schema.String;
|
|
@@ -177,7 +177,7 @@ export declare const PaginatedAdminUsers: Schema.Struct<{
|
|
|
177
177
|
readonly name: Schema.String;
|
|
178
178
|
readonly logo: Schema.NullOr<Schema.String>;
|
|
179
179
|
}>>;
|
|
180
|
-
}
|
|
180
|
+
}>>;
|
|
181
181
|
readonly meta: Schema.Struct<{
|
|
182
182
|
readonly page: Schema.Int;
|
|
183
183
|
readonly pageSize: Schema.Int;
|
|
@@ -186,26 +186,26 @@ export declare const PaginatedAdminUsers: Schema.Struct<{
|
|
|
186
186
|
}>;
|
|
187
187
|
}>;
|
|
188
188
|
export declare const PaginatedAdminOrganizations: Schema.Struct<{
|
|
189
|
-
readonly data: Schema.$Array<Schema.
|
|
190
|
-
readonly id:
|
|
191
|
-
readonly name:
|
|
192
|
-
readonly slug:
|
|
193
|
-
readonly logo
|
|
194
|
-
readonly metadata
|
|
195
|
-
readonly userId
|
|
196
|
-
readonly parentId
|
|
197
|
-
readonly memberCount
|
|
198
|
-
readonly memberPreviews
|
|
189
|
+
readonly data: Schema.$Array<Schema.Struct<{
|
|
190
|
+
readonly id: Schema.String;
|
|
191
|
+
readonly name: Schema.String;
|
|
192
|
+
readonly slug: Schema.String;
|
|
193
|
+
readonly logo: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
194
|
+
readonly metadata: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
195
|
+
readonly userId: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
196
|
+
readonly parentId: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
197
|
+
readonly memberCount: Schema.optional<Schema.Number>;
|
|
198
|
+
readonly memberPreviews: Schema.optional<Schema.$Array<Schema.Struct<{
|
|
199
199
|
readonly id: Schema.String;
|
|
200
200
|
readonly name: Schema.String;
|
|
201
201
|
readonly image: Schema.NullOr<Schema.String>;
|
|
202
|
-
}
|
|
203
|
-
readonly projects
|
|
202
|
+
}>>>;
|
|
203
|
+
readonly projects: Schema.optional<Schema.$Array<Schema.Struct<{
|
|
204
204
|
readonly id: Schema.String;
|
|
205
205
|
readonly name: Schema.String;
|
|
206
206
|
readonly logo: Schema.NullOr<Schema.String>;
|
|
207
|
-
}
|
|
208
|
-
readonly createdAt: Date;
|
|
207
|
+
}>>>;
|
|
208
|
+
readonly createdAt: Schema.Date;
|
|
209
209
|
}>>;
|
|
210
210
|
readonly meta: Schema.Struct<{
|
|
211
211
|
readonly page: Schema.Int;
|
|
@@ -225,4 +225,4 @@ export type AdminUpdateApiKeyPayload = typeof AdminUpdateApiKeyPayload.Type;
|
|
|
225
225
|
export type AdminCreateOrganizationPayload = typeof AdminCreateOrganizationPayload.Type;
|
|
226
226
|
export type AdminUpdateOrganizationPayload = typeof AdminUpdateOrganizationPayload.Type;
|
|
227
227
|
export { ServerCreateDomainPayload, ServerDomain, ServerDomainIdParams, ServerDomainRecordsResponse, ServerUpdateDomainPayload, };
|
|
228
|
-
export { SortParamsFromString } from "../query";
|
|
228
|
+
export { SortParamsFromString } from "../query.js";
|
package/dist/admin/schema.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Schema } from "effect";
|
|
2
|
-
import { PaginatedResponse, Query } from "../query";
|
|
3
|
-
import { ServerCreateDomainPayload, ServerDomain, ServerDomainIdParams, ServerDomainRecordsResponse, ServerUpdateDomainPayload, } from "../server/schema";
|
|
2
|
+
import { PaginatedResponse, Query } from "../query.js";
|
|
3
|
+
import { ServerCreateDomainPayload, ServerDomain, ServerDomainIdParams, ServerDomainRecordsResponse, ServerUpdateDomainPayload, } from "../server/schema.js";
|
|
4
4
|
export const AdminListQuery = Schema.Struct({
|
|
5
5
|
...Query.fields,
|
|
6
6
|
projectId: Schema.optional(Schema.String),
|
|
@@ -306,4 +306,4 @@ export const PaginatedAdminOrganizations = PaginatedResponse(AdminOrganization).
|
|
|
306
306
|
description: "Paginated administrative organization list response.",
|
|
307
307
|
});
|
|
308
308
|
export { ServerCreateDomainPayload, ServerDomain, ServerDomainIdParams, ServerDomainRecordsResponse, ServerUpdateDomainPayload, };
|
|
309
|
-
export { SortParamsFromString } from "../query";
|
|
309
|
+
export { SortParamsFromString } from "../query.js";
|