@krak-stack/auth 0.1.71 → 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 -45
- package/dist/components/admin-users.js +115 -137
- 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 -323
- 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 +264 -314
- 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 +20 -22
- package/dist/server/actor.js +14 -17
- 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 +1 -1
- package/dist/server/middleware.js +1 -1
- package/dist/server/schema.js +1 -1
- package/dist/service.d.ts +2043 -191
- package/dist/service.js +23 -16
- package/package.json +8 -7
- 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
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
export declare const isRecord: (
|
|
1
|
+
export declare const isRecord: <I>(input: I) => input is I & {
|
|
2
|
+
readonly [x: string]: unknown;
|
|
3
|
+
};
|
|
2
4
|
export declare const cn: (...inputs: ReadonlyArray<string | false | null | undefined>) => string;
|
|
3
5
|
export type OrganizationBrandingLocale = "en" | "fr";
|
|
4
6
|
export interface OrganizationBrandingSource {
|
package/dist/components/utils.js
CHANGED
|
@@ -1,16 +1,9 @@
|
|
|
1
1
|
import { Schema } from "effect";
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import { decodeOrganizationMetadata } from "../schema.js";
|
|
3
|
+
const UnknownRecord = Schema.Record(Schema.String, Schema.Unknown);
|
|
4
|
+
export const isRecord = Schema.is(UnknownRecord);
|
|
4
5
|
export const cn = (...inputs) => inputs.filter(Boolean).join(" ");
|
|
5
|
-
const parseOrganizationMetadata =
|
|
6
|
-
try {
|
|
7
|
-
const value = typeof metadata === "string" ? JSON.parse(metadata) : metadata;
|
|
8
|
-
return Schema.decodeUnknownSync(OrganizationMetadata)(value);
|
|
9
|
-
}
|
|
10
|
-
catch {
|
|
11
|
-
return { translations: [] };
|
|
12
|
-
}
|
|
13
|
-
};
|
|
6
|
+
const parseOrganizationMetadata = decodeOrganizationMetadata;
|
|
14
7
|
export const organizationBranding = (organization, locale = "en") => {
|
|
15
8
|
if (!organization)
|
|
16
9
|
return null;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Schema } from "effect";
|
|
2
2
|
import { HttpApiEndpoint, HttpApiError, HttpApiGroup } from "effect/unstable/httpapi";
|
|
3
|
-
import { ExtraBadRequest } from "./schema";
|
|
4
|
-
export * from "./schema";
|
|
5
|
-
export type { Organization, OrganizationMetadata } from "../schema";
|
|
3
|
+
import { ExtraBadRequest } from "./schema.js";
|
|
4
|
+
export * from "./schema.js";
|
|
5
|
+
export type { Organization, OrganizationMetadata } from "../schema.js";
|
|
6
6
|
export declare const ExtraApiGroup: HttpApiGroup.HttpApiGroup<"authExtra", HttpApiEndpoint.HttpApiEndpoint<"createApiKey", "POST", "/auth/create-api-key", HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<Schema.Struct<{
|
|
7
7
|
readonly configId: Schema.Union<readonly [Schema.Literal<"user">, Schema.Literal<"organization">, Schema.Literal<"service">]>;
|
|
8
8
|
readonly name: Schema.optional<Schema.NonEmptyString>;
|
package/dist/extra/api.group.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Schema } from "effect";
|
|
2
2
|
import { OpenApi } from "effect/unstable/httpapi";
|
|
3
3
|
import { HttpApiEndpoint, HttpApiError, HttpApiGroup, } from "effect/unstable/httpapi";
|
|
4
|
-
import { ExtraBadRequest, ExtraCreateApiKeyPayload, ExtraCreateApiKeyResponse, ExtraImageUploadMultipartPayload, ExtraOkResponse, ExtraOrganizationPublicProfile, ExtraOrganizationPublicProfileQuery, ExtraProjectPublicConfig, ExtraProjectPublicConfigQuery, ExtraSetPasswordPayload, ExtraUpdateApiKeyPayload, ExtraUploadedAsset, ExtraVerifyApiKeyPayload, ExtraVerifyApiKeyResponse, ExtraVerifyPasswordPayload, } from "./schema";
|
|
5
|
-
export * from "./schema";
|
|
4
|
+
import { ExtraBadRequest, ExtraCreateApiKeyPayload, ExtraCreateApiKeyResponse, ExtraImageUploadMultipartPayload, ExtraOkResponse, ExtraOrganizationPublicProfile, ExtraOrganizationPublicProfileQuery, ExtraProjectPublicConfig, ExtraProjectPublicConfigQuery, ExtraSetPasswordPayload, ExtraUpdateApiKeyPayload, ExtraUploadedAsset, ExtraVerifyApiKeyPayload, ExtraVerifyApiKeyResponse, ExtraVerifyPasswordPayload, } from "./schema.js";
|
|
5
|
+
export * from "./schema.js";
|
|
6
6
|
export const ExtraApiGroup = HttpApiGroup.make("authExtra")
|
|
7
7
|
.add(HttpApiEndpoint.get("getProjectPublicConfig", "/auth/project-config", {
|
|
8
8
|
query: ExtraProjectPublicConfigQuery,
|
|
@@ -32,7 +32,7 @@ export const ExtraApiGroup = HttpApiGroup.make("authExtra")
|
|
|
32
32
|
}).annotateMerge(OpenApi.annotations({
|
|
33
33
|
title: "Update API key",
|
|
34
34
|
summary: "Update an API key",
|
|
35
|
-
description: "Updates API key details and server-only permissions after
|
|
35
|
+
description: "Updates API key details and server-only permissions after verifying user ownership or organization key-management access.",
|
|
36
36
|
})))
|
|
37
37
|
.add(HttpApiEndpoint.get("getOrganizationPublicProfile", "/auth/organization-profile", {
|
|
38
38
|
query: ExtraOrganizationPublicProfileQuery,
|
|
@@ -83,7 +83,7 @@ export const ExtraApiGroup = HttpApiGroup.make("authExtra")
|
|
|
83
83
|
}).annotateMerge(OpenApi.annotations({
|
|
84
84
|
title: "Create API key",
|
|
85
85
|
summary: "Create an API key with optional permissions",
|
|
86
|
-
description: "Creates a user or organization API key through
|
|
86
|
+
description: "Creates a user or organization API key through the server API so server-only fields like permissions can be set.",
|
|
87
87
|
})))
|
|
88
88
|
.add(HttpApiEndpoint.post("verifyApiKey", "/auth/verify-api-key", {
|
|
89
89
|
payload: ExtraVerifyApiKeyPayload,
|
|
@@ -92,7 +92,7 @@ export const ExtraApiGroup = HttpApiGroup.make("authExtra")
|
|
|
92
92
|
}).annotateMerge(OpenApi.annotations({
|
|
93
93
|
title: "Verify API key",
|
|
94
94
|
summary: "Verify a remote API key",
|
|
95
|
-
description: "Verifies a user or organization API key and optional permissions
|
|
95
|
+
description: "Verifies a user or organization API key and optional permissions.",
|
|
96
96
|
})))
|
|
97
97
|
.add(HttpApiEndpoint.post("uploadUserImage", "/auth/image/upload", {
|
|
98
98
|
payload: ExtraImageUploadMultipartPayload,
|
|
@@ -110,5 +110,5 @@ export const ExtraApiGroup = HttpApiGroup.make("authExtra")
|
|
|
110
110
|
})))
|
|
111
111
|
.annotateMerge(OpenApi.annotations({
|
|
112
112
|
title: "Extra",
|
|
113
|
-
description: "KrakStack-specific endpoints
|
|
113
|
+
description: "KrakStack-specific authentication endpoints.",
|
|
114
114
|
}));
|
package/dist/extra/schema.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Schema } from "effect";
|
|
2
2
|
import { Multipart } from "effect/unstable/http";
|
|
3
3
|
import { HttpApiSchema } from "effect/unstable/httpapi";
|
|
4
|
-
import { OrganizationEmail, OrganizationLocale, OrganizationPhone, OrganizationSocial, OrganizationWebsite, FormattedOrganizationAddress, } from "../schema";
|
|
4
|
+
import { OrganizationEmail, OrganizationLocale, OrganizationPhone, OrganizationSocial, OrganizationWebsite, FormattedOrganizationAddress, } from "../schema.js";
|
|
5
5
|
export const ExtraImageUploadPayload = Schema.Struct({
|
|
6
6
|
file: Multipart.SingleFileSchema,
|
|
7
7
|
}).annotate({
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
export * from "./schema";
|
|
2
|
-
export * as Query from "./query";
|
|
3
|
-
export * as Roles from "./roles";
|
|
4
|
-
export { AuthClientApi, AuthServiceApi } from "./api";
|
|
5
|
-
export { AuthService, type AuthServiceLayerOptions } from "./service";
|
|
6
|
-
export { AuthClientConfig } from "./config";
|
|
7
|
-
export { proxyAuthRequest } from "./server/proxy";
|
|
8
|
-
export
|
|
9
|
-
export * as
|
|
10
|
-
export * as
|
|
11
|
-
export * as
|
|
12
|
-
export * as Admin from "./admin/api.group";
|
|
1
|
+
export * from "./schema.js";
|
|
2
|
+
export * as Query from "./query.js";
|
|
3
|
+
export * as Roles from "./roles.js";
|
|
4
|
+
export { AuthClientApi, AuthServiceApi } from "./api.js";
|
|
5
|
+
export { AuthService, type AuthServiceLayerOptions } from "./service.js";
|
|
6
|
+
export { AuthClientConfig } from "./config.js";
|
|
7
|
+
export { proxyAuthRequest } from "./server/proxy.js";
|
|
8
|
+
export * as Auth from "./auth/api.group.js";
|
|
9
|
+
export * as Extra from "./extra/api.group.js";
|
|
10
|
+
export * as Server from "./server/index.js";
|
|
11
|
+
export * as Admin from "./admin/api.group.js";
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
export * from "./schema";
|
|
2
|
-
export * as Query from "./query";
|
|
3
|
-
export * as Roles from "./roles";
|
|
4
|
-
export { AuthClientApi, AuthServiceApi } from "./api";
|
|
5
|
-
export { AuthService } from "./service";
|
|
6
|
-
export { AuthClientConfig } from "./config";
|
|
7
|
-
export { proxyAuthRequest } from "./server/proxy";
|
|
8
|
-
export
|
|
9
|
-
export * as
|
|
10
|
-
export * as
|
|
11
|
-
export * as
|
|
12
|
-
export * as Admin from "./admin/api.group";
|
|
1
|
+
export * from "./schema.js";
|
|
2
|
+
export * as Query from "./query.js";
|
|
3
|
+
export * as Roles from "./roles.js";
|
|
4
|
+
export { AuthClientApi, AuthServiceApi } from "./api.js";
|
|
5
|
+
export { AuthService } from "./service.js";
|
|
6
|
+
export { AuthClientConfig } from "./config.js";
|
|
7
|
+
export { proxyAuthRequest } from "./server/proxy.js";
|
|
8
|
+
export * as Auth from "./auth/api.group.js";
|
|
9
|
+
export * as Extra from "./extra/api.group.js";
|
|
10
|
+
export * as Server from "./server/index.js";
|
|
11
|
+
export * as Admin from "./admin/api.group.js";
|
package/dist/query.d.ts
CHANGED
|
@@ -38,8 +38,8 @@ export declare const PaginationMeta: Schema.Struct<{
|
|
|
38
38
|
readonly pageCount: Schema.Int;
|
|
39
39
|
}>;
|
|
40
40
|
export type PaginationMetaType = typeof PaginationMeta.Type;
|
|
41
|
-
export declare const PaginatedResponse: <
|
|
42
|
-
readonly data: Schema.$Array<
|
|
41
|
+
export declare const PaginatedResponse: <S extends Schema.Top>(items: S) => Schema.Struct<{
|
|
42
|
+
readonly data: Schema.$Array<S>;
|
|
43
43
|
readonly meta: Schema.Struct<{
|
|
44
44
|
readonly page: Schema.Int;
|
|
45
45
|
readonly pageSize: Schema.Int;
|
package/dist/roles.d.ts
CHANGED
|
@@ -3,8 +3,9 @@ export type OrganizationRole = (typeof organizationRoles)[number];
|
|
|
3
3
|
export declare const organizationImpersonationRoles: readonly ["owner", "admin", "support"];
|
|
4
4
|
export declare const globalAdminRoles: readonly ["admin"];
|
|
5
5
|
export type GlobalAdminRole = (typeof globalAdminRoles)[number];
|
|
6
|
-
export declare const parseRoleList: (role:
|
|
7
|
-
export declare const hasAnyRole: (role:
|
|
6
|
+
export declare const parseRoleList: (role: typeof Schema.Unknown.Type) => string[];
|
|
7
|
+
export declare const hasAnyRole: (role: typeof Schema.Unknown.Type, roles: readonly string[]) => boolean;
|
|
8
8
|
export declare const isOrganizationRole: (role: string) => role is OrganizationRole;
|
|
9
|
-
export declare const normalizeOrganizationRole: (role:
|
|
10
|
-
export declare const normalizeOrganizationRoles: (role:
|
|
9
|
+
export declare const normalizeOrganizationRole: (role: typeof Schema.Unknown.Type) => OrganizationRole;
|
|
10
|
+
export declare const normalizeOrganizationRoles: (role: typeof Schema.Unknown.Type) => OrganizationRole[];
|
|
11
|
+
import { Schema } from "effect";
|
package/dist/roles.js
CHANGED
|
@@ -10,17 +10,20 @@ export const organizationImpersonationRoles = [
|
|
|
10
10
|
"support",
|
|
11
11
|
];
|
|
12
12
|
export const globalAdminRoles = ["admin"];
|
|
13
|
-
export const parseRoleList = (role) =>
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
export const parseRoleList = (role) => {
|
|
14
|
+
const decoded = Schema.decodeUnknownOption(Schema.String)(role);
|
|
15
|
+
return Option.isSome(decoded)
|
|
16
|
+
? decoded.value
|
|
17
|
+
.split(",")
|
|
18
|
+
.map((item) => item.trim())
|
|
19
|
+
.filter(Boolean)
|
|
20
|
+
: [];
|
|
21
|
+
};
|
|
19
22
|
export const hasAnyRole = (role, roles) => {
|
|
20
23
|
const allowed = new Set(roles);
|
|
21
24
|
return parseRoleList(role).some((item) => allowed.has(item));
|
|
22
25
|
};
|
|
23
|
-
export const isOrganizationRole = (role) => organizationRoles.
|
|
26
|
+
export const isOrganizationRole = (role) => organizationRoles.some((organizationRole) => organizationRole === role);
|
|
24
27
|
export const normalizeOrganizationRole = (role) => {
|
|
25
28
|
const [firstRole] = parseRoleList(role).filter(isOrganizationRole);
|
|
26
29
|
return firstRole ?? "member";
|
|
@@ -29,3 +32,4 @@ export const normalizeOrganizationRoles = (role) => {
|
|
|
29
32
|
const roles = parseRoleList(role).filter(isOrganizationRole);
|
|
30
33
|
return roles.length > 0 ? Array.from(new Set(roles)) : ["member"];
|
|
31
34
|
};
|
|
35
|
+
import { Option, Schema } from "effect";
|
package/dist/schema.d.ts
CHANGED
|
@@ -152,7 +152,7 @@ export declare const OrganizationMetadata: Schema.Struct<{
|
|
|
152
152
|
}>>;
|
|
153
153
|
}>>>;
|
|
154
154
|
}>;
|
|
155
|
-
export declare const decodeOrganizationMetadata: (metadata:
|
|
155
|
+
export declare const decodeOrganizationMetadata: (metadata: typeof Schema.Unknown.Type) => OrganizationMetadata;
|
|
156
156
|
export declare const Organization: Schema.Struct<{
|
|
157
157
|
readonly id: Schema.String;
|
|
158
158
|
readonly name: Schema.String;
|
package/dist/schema.js
CHANGED
|
@@ -44,7 +44,7 @@ export const Session = Schema.Struct({
|
|
|
44
44
|
}).annotate({
|
|
45
45
|
identifier: "Session",
|
|
46
46
|
title: "Session",
|
|
47
|
-
description: "Current
|
|
47
|
+
description: "Current browser session record.",
|
|
48
48
|
examples: [
|
|
49
49
|
{
|
|
50
50
|
id: "session_1",
|
|
@@ -247,28 +247,35 @@ export const OrganizationMetadata = Schema.Struct({
|
|
|
247
247
|
},
|
|
248
248
|
],
|
|
249
249
|
});
|
|
250
|
-
const
|
|
250
|
+
const OrganizationMetadataRecord = Schema.Record(Schema.String, Schema.Unknown);
|
|
251
|
+
const OrganizationMetadataInput = Schema.Union([
|
|
252
|
+
OrganizationMetadataRecord,
|
|
253
|
+
Schema.fromJsonString(OrganizationMetadataRecord),
|
|
254
|
+
]);
|
|
251
255
|
export const decodeOrganizationMetadata = (metadata) => {
|
|
252
|
-
const value =
|
|
253
|
-
|
|
254
|
-
: metadata;
|
|
255
|
-
if (typeof value !== "object" || value === null) {
|
|
256
|
+
const value = Schema.decodeUnknownOption(OrganizationMetadataInput)(metadata);
|
|
257
|
+
if (Option.isNone(value))
|
|
256
258
|
return { translations: [] };
|
|
257
|
-
|
|
258
|
-
const
|
|
259
|
-
const
|
|
260
|
-
const
|
|
261
|
-
const
|
|
262
|
-
const
|
|
263
|
-
|
|
264
|
-
return {
|
|
259
|
+
const translations = Schema.decodeUnknownOption(Schema.Array(OrganizationTranslation))(value.value.translations);
|
|
260
|
+
const emails = Schema.decodeUnknownOption(Schema.Array(OrganizationEmail))(value.value.emails);
|
|
261
|
+
const phones = Schema.decodeUnknownOption(Schema.Array(OrganizationPhone))(value.value.phones);
|
|
262
|
+
const websites = Schema.decodeUnknownOption(Schema.Array(OrganizationWebsite))(value.value.websites);
|
|
263
|
+
const socials = Schema.decodeUnknownOption(Schema.Array(OrganizationSocial))(value.value.socials);
|
|
264
|
+
const addresses = Schema.decodeUnknownOption(Schema.Array(OrganizationAddress))(value.value.addresses);
|
|
265
|
+
let result = {
|
|
265
266
|
translations: Option.getOrElse(translations, () => []),
|
|
266
|
-
...(Option.isSome(emails) ? { emails: emails.value } : {}),
|
|
267
|
-
...(Option.isSome(phones) ? { phones: phones.value } : {}),
|
|
268
|
-
...(Option.isSome(websites) ? { websites: websites.value } : {}),
|
|
269
|
-
...(Option.isSome(socials) ? { socials: socials.value } : {}),
|
|
270
|
-
...(Option.isSome(addresses) ? { addresses: addresses.value } : {}),
|
|
271
267
|
};
|
|
268
|
+
if (Option.isSome(emails))
|
|
269
|
+
result = { ...result, emails: emails.value };
|
|
270
|
+
if (Option.isSome(phones))
|
|
271
|
+
result = { ...result, phones: phones.value };
|
|
272
|
+
if (Option.isSome(websites))
|
|
273
|
+
result = { ...result, websites: websites.value };
|
|
274
|
+
if (Option.isSome(socials))
|
|
275
|
+
result = { ...result, socials: socials.value };
|
|
276
|
+
if (Option.isSome(addresses))
|
|
277
|
+
result = { ...result, addresses: addresses.value };
|
|
278
|
+
return result;
|
|
272
279
|
};
|
|
273
280
|
const CompatibleOrganizationMetadata = Schema.Unknown.pipe(Schema.decodeTo(OrganizationMetadata, {
|
|
274
281
|
decode: SchemaGetter.transform(decodeOrganizationMetadata),
|
package/dist/server/actor.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Layer } from "effect";
|
|
2
2
|
import { HttpApiError, HttpApiMiddleware } from "effect/unstable/httpapi";
|
|
3
|
-
import { CurrentActor, type ProjectAccessDefinition } from "../access";
|
|
4
|
-
import { AuthService } from "../service";
|
|
3
|
+
import { CurrentActor, type ProjectAccessDefinition } from "../access.js";
|
|
4
|
+
import { AuthService } from "../service.js";
|
|
5
5
|
declare const AnyActorRequired_base: HttpApiMiddleware.ServiceClass<AnyActorRequired, "@krak-stack/auth/ActorRequired", {
|
|
6
6
|
requires: AuthService;
|
|
7
7
|
provides: CurrentActor;
|
|
@@ -58,24 +58,22 @@ export type ActorConstraint = {
|
|
|
58
58
|
readonly type: "apiKey";
|
|
59
59
|
readonly ownerType?: "user" | "organization" | undefined;
|
|
60
60
|
};
|
|
61
|
-
declare
|
|
62
|
-
|
|
63
|
-
(
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
};
|
|
80
|
-
export declare const ActorRequired: ActorRequiredFactory;
|
|
61
|
+
export declare function ActorRequired(): typeof AnyActorRequired;
|
|
62
|
+
export declare namespace ActorRequired {
|
|
63
|
+
var layer: <Project extends string, Action extends string>(access: ProjectAccessDefinition<Project, Action>) => Layer.Layer<AnyActorRequired | ApiKeyActorRequired | OrganizationApiKeyActorRequired | UserActorRequired | UserApiKeyActorRequired, never, never>;
|
|
64
|
+
}
|
|
65
|
+
export declare function ActorRequired(constraint: {
|
|
66
|
+
readonly type: "user";
|
|
67
|
+
}): typeof UserActorRequired;
|
|
68
|
+
export declare function ActorRequired(constraint: {
|
|
69
|
+
readonly type: "apiKey";
|
|
70
|
+
readonly ownerType: "user";
|
|
71
|
+
}): typeof UserApiKeyActorRequired;
|
|
72
|
+
export declare function ActorRequired(constraint: {
|
|
73
|
+
readonly type: "apiKey";
|
|
74
|
+
readonly ownerType: "organization";
|
|
75
|
+
}): typeof OrganizationApiKeyActorRequired;
|
|
76
|
+
export declare function ActorRequired(constraint: {
|
|
77
|
+
readonly type: "apiKey";
|
|
78
|
+
}): typeof ApiKeyActorRequired;
|
|
81
79
|
export {};
|
package/dist/server/actor.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { Effect, Layer, Schema } from "effect";
|
|
2
2
|
import { HttpApiError, HttpApiMiddleware } from "effect/unstable/httpapi";
|
|
3
|
-
import { ApiKeyPermissionGrant, CurrentActor, } from "../access";
|
|
4
|
-
import { parseRoleList } from "../roles";
|
|
5
|
-
import { AuthService } from "../service";
|
|
3
|
+
import { ApiKeyPermissionGrant, CurrentActor, } from "../access.js";
|
|
4
|
+
import { parseRoleList } from "../roles.js";
|
|
5
|
+
import { AuthService } from "../service.js";
|
|
6
6
|
const activeMemberRoles = ({ organizationId, userId, }) => Effect.gen(function* () {
|
|
7
7
|
const auth = yield* AuthService;
|
|
8
|
-
const
|
|
9
|
-
.
|
|
8
|
+
const role = yield* auth
|
|
9
|
+
.getActiveMemberRole({ organizationId, userId })
|
|
10
10
|
.pipe(Effect.mapError(() => new HttpApiError.Forbidden({})));
|
|
11
|
-
return parseRoleList(
|
|
11
|
+
return parseRoleList(role);
|
|
12
12
|
});
|
|
13
13
|
const resolveCurrentActor = (access) => Effect.gen(function* () {
|
|
14
14
|
const auth = yield* AuthService;
|
|
@@ -116,15 +116,14 @@ const withCurrentActor = (httpEffect, actor) => {
|
|
|
116
116
|
: actor.actor.owner.type === "user"
|
|
117
117
|
? actor.actor.owner.userId
|
|
118
118
|
: undefined;
|
|
119
|
-
const attributes = {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
};
|
|
119
|
+
const attributes = {};
|
|
120
|
+
if (actor.organizationId)
|
|
121
|
+
attributes["organization.id"] = actor.organizationId;
|
|
122
|
+
if (userId)
|
|
123
|
+
attributes["user.id"] = userId;
|
|
125
124
|
return Effect.annotateCurrentSpan(attributes).pipe(Effect.andThen(httpEffect.pipe(Effect.provideService(CurrentActor, actor), Effect.annotateSpans(attributes), Effect.annotateLogs(attributes))));
|
|
126
125
|
};
|
|
127
|
-
|
|
126
|
+
export function ActorRequired(constraint) {
|
|
128
127
|
if (!constraint)
|
|
129
128
|
return AnyActorRequired;
|
|
130
129
|
if (constraint.type === "user")
|
|
@@ -135,11 +134,9 @@ const actorRequired = (constraint) => {
|
|
|
135
134
|
return OrganizationApiKeyActorRequired;
|
|
136
135
|
}
|
|
137
136
|
return ApiKeyActorRequired;
|
|
138
|
-
}
|
|
137
|
+
}
|
|
139
138
|
const actorRequiredLayer = (access) => Layer.mergeAll(Layer.succeed(AnyActorRequired, (httpEffect) => requiredActor(access).pipe(Effect.flatMap((actor) => withCurrentActor(httpEffect, actor)))), Layer.succeed(UserActorRequired, (httpEffect) => requiredActor(access, { type: "user" }).pipe(Effect.flatMap((actor) => withCurrentActor(httpEffect, actor)))), Layer.succeed(ApiKeyActorRequired, (httpEffect) => requiredActor(access, { type: "apiKey" }).pipe(Effect.flatMap((actor) => withCurrentActor(httpEffect, actor)))), Layer.succeed(UserApiKeyActorRequired, (httpEffect) => requiredActor(access, { type: "apiKey", ownerType: "user" }).pipe(Effect.flatMap((actor) => withCurrentActor(httpEffect, actor)))), Layer.succeed(OrganizationApiKeyActorRequired, (httpEffect) => requiredActor(access, {
|
|
140
139
|
type: "apiKey",
|
|
141
140
|
ownerType: "organization",
|
|
142
141
|
}).pipe(Effect.flatMap((actor) => withCurrentActor(httpEffect, actor)))));
|
|
143
|
-
|
|
144
|
-
layer: actorRequiredLayer,
|
|
145
|
-
});
|
|
142
|
+
ActorRequired.layer = actorRequiredLayer;
|
package/dist/server/api.group.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { OpenApi } from "effect/unstable/httpapi";
|
|
2
2
|
import { HttpApiEndpoint, HttpApiError, HttpApiGroup, } from "effect/unstable/httpapi";
|
|
3
|
-
import { Member, Organization, User } from "../schema";
|
|
4
|
-
import { ServerActiveOrganization, ServerCreateDomainPayload, ServerDomain, ServerDomainHostParams, ServerDomainIdParams, ServerDomainRecordsResponse, ServerIdParams, ServerIdsQuery, ServerMemberParams, ServerMembersResponse, ServerOrganizationChildrenResponse, ServerOrganizationIdParams, ServerOrganizationsQuery, ServerOrganizationsResponse, ServerUserIdParams, ServerUsersResponse, } from "./schema";
|
|
3
|
+
import { Member, Organization, User } from "../schema.js";
|
|
4
|
+
import { ServerActiveOrganization, ServerCreateDomainPayload, ServerDomain, ServerDomainHostParams, ServerDomainIdParams, ServerDomainRecordsResponse, ServerIdParams, ServerIdsQuery, ServerMemberParams, ServerMembersResponse, ServerOrganizationChildrenResponse, ServerOrganizationIdParams, ServerOrganizationsQuery, ServerOrganizationsResponse, ServerUserIdParams, ServerUsersResponse, } from "./schema.js";
|
|
5
5
|
export const ServerUsersApiGroup = HttpApiGroup.make("users")
|
|
6
6
|
.add(HttpApiEndpoint.get("listUsersByIds", "/users", {
|
|
7
7
|
query: ServerIdsQuery,
|
package/dist/server/index.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
export { AuthService } from "../service";
|
|
2
|
-
export type { AuthSession, AuthSessionWithOrganization, AuthSessionWithUser, AuthSessionWithUserAndOrganization, } from "../service";
|
|
3
|
-
export { AuthClientConfig } from "../config";
|
|
4
|
-
export { ServerDomainsApiGroup, ServerOrganizationsApiGroup, ServerUsersApiGroup, } from "./api.group";
|
|
5
|
-
export { proxyAuthRequest } from "./proxy";
|
|
6
|
-
export type { ProxyAuthRequestOptions } from "./proxy";
|
|
7
|
-
export { ActorRequired } from "./actor";
|
|
8
|
-
export type { ActorConstraint } from "./actor";
|
|
9
|
-
export { ApiKeySecurity, AuthMiddleware, makeAuthenticationLive, } from "./middleware";
|
|
10
|
-
export type { AuthenticationLiveOptions } from "./middleware";
|
|
11
|
-
export { ServerActiveOrganization, ServerCreateDomainPayload, ServerDomain, ServerDomainHostParams, ServerDomainIdParams, ServerDomainRecordsResponse, ServerMembersResponse, ServerOrganizationChildrenResponse, ServerOrganizationsResponse, ServerUpdateDomainPayload, ServerUsersResponse, } from "./schema";
|
|
12
|
-
export type { Member, Organization, OrganizationMetadata, User, } from "../schema";
|
|
13
|
-
export { ApiKeyPermissionGrant, CurrentActor, Forbidden, all, actorUserId, any, defineProjectAccess, permission, policy, withPolicy, } from "../access";
|
|
14
|
-
export type { ApiKeyOwner, ApiKeyActor, Actor, Policy, ProjectAccessConfig, ProjectAccessCatalog, ProjectAccessDefinition, UserActor, } from "../access";
|
|
1
|
+
export { AuthService } from "../service.js";
|
|
2
|
+
export type { AuthSession, AuthSessionWithOrganization, AuthSessionWithUser, AuthSessionWithUserAndOrganization, } from "../service.js";
|
|
3
|
+
export { AuthClientConfig } from "../config.js";
|
|
4
|
+
export { ServerDomainsApiGroup, ServerOrganizationsApiGroup, ServerUsersApiGroup, } from "./api.group.js";
|
|
5
|
+
export { proxyAuthRequest } from "./proxy.js";
|
|
6
|
+
export type { ProxyAuthRequestOptions } from "./proxy.js";
|
|
7
|
+
export { ActorRequired } from "./actor.js";
|
|
8
|
+
export type { ActorConstraint } from "./actor.js";
|
|
9
|
+
export { ApiKeySecurity, AuthMiddleware, makeAuthenticationLive, } from "./middleware.js";
|
|
10
|
+
export type { AuthenticationLiveOptions } from "./middleware.js";
|
|
11
|
+
export { ServerActiveOrganization, ServerCreateDomainPayload, ServerDomain, ServerDomainHostParams, ServerDomainIdParams, ServerDomainRecordsResponse, ServerMembersResponse, ServerOrganizationChildrenResponse, ServerOrganizationsResponse, ServerUpdateDomainPayload, ServerUsersResponse, } from "./schema.js";
|
|
12
|
+
export type { Member, Organization, OrganizationMetadata, User, } from "../schema.js";
|
|
13
|
+
export { ApiKeyPermissionGrant, CurrentActor, Forbidden, all, actorUserId, any, defineProjectAccess, permission, policy, withPolicy, } from "../access.js";
|
|
14
|
+
export type { ApiKeyOwner, ApiKeyActor, Actor, Policy, ProjectAccessConfig, ProjectAccessCatalog, ProjectAccessDefinition, UserActor, } from "../access.js";
|
package/dist/server/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export { AuthService } from "../service";
|
|
2
|
-
export { AuthClientConfig } from "../config";
|
|
3
|
-
export { ServerDomainsApiGroup, ServerOrganizationsApiGroup, ServerUsersApiGroup, } from "./api.group";
|
|
4
|
-
export { proxyAuthRequest } from "./proxy";
|
|
5
|
-
export { ActorRequired } from "./actor";
|
|
6
|
-
export { ApiKeySecurity, AuthMiddleware, makeAuthenticationLive, } from "./middleware";
|
|
7
|
-
export { ServerActiveOrganization, ServerCreateDomainPayload, ServerDomain, ServerDomainHostParams, ServerDomainIdParams, ServerDomainRecordsResponse, ServerMembersResponse, ServerOrganizationChildrenResponse, ServerOrganizationsResponse, ServerUpdateDomainPayload, ServerUsersResponse, } from "./schema";
|
|
8
|
-
export { ApiKeyPermissionGrant, CurrentActor, Forbidden, all, actorUserId, any, defineProjectAccess, permission, policy, withPolicy, } from "../access";
|
|
1
|
+
export { AuthService } from "../service.js";
|
|
2
|
+
export { AuthClientConfig } from "../config.js";
|
|
3
|
+
export { ServerDomainsApiGroup, ServerOrganizationsApiGroup, ServerUsersApiGroup, } from "./api.group.js";
|
|
4
|
+
export { proxyAuthRequest } from "./proxy.js";
|
|
5
|
+
export { ActorRequired } from "./actor.js";
|
|
6
|
+
export { ApiKeySecurity, AuthMiddleware, makeAuthenticationLive, } from "./middleware.js";
|
|
7
|
+
export { ServerActiveOrganization, ServerCreateDomainPayload, ServerDomain, ServerDomainHostParams, ServerDomainIdParams, ServerDomainRecordsResponse, ServerMembersResponse, ServerOrganizationChildrenResponse, ServerOrganizationsResponse, ServerUpdateDomainPayload, ServerUsersResponse, } from "./schema.js";
|
|
8
|
+
export { ApiKeyPermissionGrant, CurrentActor, Forbidden, all, actorUserId, any, defineProjectAccess, permission, policy, withPolicy, } from "../access.js";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Layer } from "effect";
|
|
2
2
|
import { HttpServerRequest } from "effect/unstable/http";
|
|
3
3
|
import { HttpApiError, HttpApiMiddleware, HttpApiSecurity } from "effect/unstable/httpapi";
|
|
4
|
-
import { AuthService, type AuthServiceLayerOptions } from "../service";
|
|
4
|
+
import { AuthService, type AuthServiceLayerOptions } from "../service.js";
|
|
5
5
|
export declare const ApiKeySecurity: HttpApiSecurity.ApiKey;
|
|
6
6
|
declare const AuthMiddleware_base: HttpApiMiddleware.ServiceClass<AuthMiddleware, "@krak-stack/auth/AuthMiddleware", {
|
|
7
7
|
requires: never;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Cause, Effect, Layer, Redacted } from "effect";
|
|
2
2
|
import { HttpServerRequest } from "effect/unstable/http";
|
|
3
3
|
import { HttpApiError, HttpApiMiddleware, HttpApiSecurity, } from "effect/unstable/httpapi";
|
|
4
|
-
import { AuthService } from "../service";
|
|
4
|
+
import { AuthService } from "../service.js";
|
|
5
5
|
export const ApiKeySecurity = HttpApiSecurity.apiKey({
|
|
6
6
|
key: "x-api-key",
|
|
7
7
|
in: "header",
|
package/dist/server/schema.js
CHANGED