@krak-stack/auth 0.1.40 → 0.1.41

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.
@@ -16,13 +16,12 @@ import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, }
16
16
  import { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu";
17
17
  import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select";
18
18
  import { Separator } from "@/components/ui/separator";
19
- import { cn } from "@/lib/utils";
20
19
  import { OrganizationMetadata, } from "@krak-stack/auth/schema";
21
- import { authApiClient } from "./auth-api-client";
20
+ import { authClientApi } from "./auth-client-api";
22
21
  import { createApiKey } from "./api-key";
23
22
  import { useOpenedOnce } from "./hooks";
24
23
  import { ExtraUploadedAsset } from "../extra/schema";
25
- import { assetPath, assetUrl } from "./utils";
24
+ import { assetPath, assetUrl, cn } from "./utils";
26
25
  const messages = {
27
26
  en: {
28
27
  api_key_rate_limit_notice: "API keys are subject to the same rate limits as your account.",
@@ -563,7 +562,7 @@ const userInvitationRowActions = ({ m, actingInvitationId, onAccept, onReject, }
563
562
  ];
564
563
  function EditOrganizationSection({ authClient, baseUrl, organization, onUpdated, }) {
565
564
  const m = useOrganizationMessages();
566
- const uploadOrganizationLogo = useAtomSet(authApiClient(baseUrl).mutation("authExtra", "uploadOrganizationLogo"), { mode: "promise" });
565
+ const uploadOrganizationLogo = useAtomSet(authClientApi(baseUrl).mutation("authExtra", "uploadOrganizationLogo"), { mode: "promise" });
567
566
  const [editingLocale, setEditingLocale] = useState(currentOrganizationLocale());
568
567
  const defaultValues = organizationFormDefaults(organization, baseUrl);
569
568
  const form = useAppForm({
@@ -639,7 +638,7 @@ function CreateOrganizationSlugAutoFill({ form, }) {
639
638
  }
640
639
  function CreateOrganizationSection({ authClient, baseUrl, onCreated, }) {
641
640
  const m = useOrganizationMessages();
642
- const uploadOrganizationLogo = useAtomSet(authApiClient(baseUrl).mutation("authExtra", "uploadOrganizationLogo"), { mode: "promise" });
641
+ const uploadOrganizationLogo = useAtomSet(authClientApi(baseUrl).mutation("authExtra", "uploadOrganizationLogo"), { mode: "promise" });
643
642
  const [editingLocale, setEditingLocale] = useState(currentOrganizationLocale());
644
643
  const defaultValues = organizationFormDefaults(undefined, baseUrl);
645
644
  const form = useAppForm({
@@ -17,7 +17,7 @@ import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, }
17
17
  import { Field, FieldContent, FieldDescription, FieldGroup, FieldLabel, FieldLegend, FieldSet, } from "@/components/ui/field";
18
18
  import { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu";
19
19
  import { Separator } from "@/components/ui/separator";
20
- import { authApiClient } from "./auth-api-client";
20
+ import { authClientApi } from "./auth-client-api";
21
21
  import { useKrakstackAuthProjectConfig } from "./auth-provider";
22
22
  import { createApiKey } from "./api-key";
23
23
  import { useOpenedOnce } from "./hooks";
@@ -294,7 +294,7 @@ export const UserButton = ({ authClient, baseUrl, signOutRedirect = "/", side =
294
294
  : emptyAccountsAtom;
295
295
  const accountsResult = useAtomValue(accountsAtom);
296
296
  const refreshAccounts = useAtomRefresh(accountsAtom);
297
- const uploadUserImage = useAtomSet(authApiClient(baseUrl).mutation("authExtra", "uploadUserImage"), { mode: "promise" });
297
+ const uploadUserImage = useAtomSet(authClientApi(baseUrl).mutation("authExtra", "uploadUserImage"), { mode: "promise" });
298
298
  const accountCache = {
299
299
  accounts: AsyncResult.match(accountsResult, {
300
300
  onInitial: () => null,
@@ -532,7 +532,7 @@ function SetPasswordForm({ authClient, onSaved, }) {
532
532
  }
533
533
  function RevokeAccountForm({ baseUrl, account, requirePassword, onCancel, onRevoke, }) {
534
534
  const m = useUserButtonMessages();
535
- const verifyPassword = useAtomSet(authApiClient(baseUrl).mutation("authExtra", "verifyPassword"), { mode: "promise" });
535
+ const verifyPassword = useAtomSet(authClientApi(baseUrl).mutation("authExtra", "verifyPassword"), { mode: "promise" });
536
536
  const form = useAppForm({
537
537
  defaultValues: { password: "" },
538
538
  onSubmit: async ({ value, formApi }) => {
@@ -1,3 +1,14 @@
1
1
  export declare const isRecord: (value: unknown) => value is Record<string, unknown>;
2
+ export declare const cn: (...inputs: ReadonlyArray<string | false | null | undefined>) => string;
3
+ export type OrganizationBrandingLocale = "en" | "fr";
4
+ export interface OrganizationBrandingSource {
5
+ readonly name: string;
6
+ readonly logo?: string | null | undefined;
7
+ readonly metadata?: unknown;
8
+ }
9
+ export declare const organizationBranding: (organization: OrganizationBrandingSource | null | undefined, locale?: OrganizationBrandingLocale) => {
10
+ name: string;
11
+ logo: string | null | undefined;
12
+ } | null;
2
13
  export declare const assetPath: (value: string | null | undefined) => string | null;
3
14
  export declare const assetUrl: (value: string | null | undefined, baseUrl?: string) => string;
@@ -1,4 +1,28 @@
1
+ import { Schema } from "effect";
2
+ import { OrganizationMetadata } from "../schema";
1
3
  export const isRecord = (value) => typeof value === "object" && value !== null;
4
+ export const cn = (...inputs) => inputs.filter(Boolean).join(" ");
5
+ const parseOrganizationMetadata = (metadata) => {
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
+ };
14
+ export const organizationBranding = (organization, locale = "en") => {
15
+ if (!organization)
16
+ return null;
17
+ const translations = parseOrganizationMetadata(organization.metadata).translations;
18
+ const translation = translations.find((item) => item.locale === locale) ??
19
+ translations.find((item) => item.locale === "en") ??
20
+ translations[0];
21
+ return {
22
+ name: translation?.name || organization.name,
23
+ logo: translation?.icon || translation?.logo || organization.logo,
24
+ };
25
+ };
2
26
  const assetRoutePrefix = "/api/auth/assets/";
3
27
  const legacyAssetRoutePrefix = "/api/assets/";
4
28
  const assetKey = (value) => {
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from "./schema";
2
- export { AuthApi } from "./api";
2
+ export * as Query from "./query";
3
+ export { AuthClientApi, AuthServiceApi } from "./api";
3
4
  export { AuthService, type AuthServiceLayerOptions } from "./service";
4
5
  export { AuthClientConfig } from "./config";
5
6
  export { proxyAuthRequest } from "./server/proxy";
@@ -7,3 +8,4 @@ export { OrganizationSwitcher, KrakstackAuthProvider, ResetPassword, Signin, Sig
7
8
  export * as BetterAuth from "./better-auth";
8
9
  export * as Extra from "./extra";
9
10
  export * as Server from "./server";
11
+ export * as Admin from "./admin";
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from "./schema";
2
- export { AuthApi } from "./api";
2
+ export * as Query from "./query";
3
+ export { AuthClientApi, AuthServiceApi } from "./api";
3
4
  export { AuthService } from "./service";
4
5
  export { AuthClientConfig } from "./config";
5
6
  export { proxyAuthRequest } from "./server/proxy";
@@ -7,3 +8,4 @@ export { OrganizationSwitcher, KrakstackAuthProvider, ResetPassword, Signin, Sig
7
8
  export * as BetterAuth from "./better-auth";
8
9
  export * as Extra from "./extra";
9
10
  export * as Server from "./server";
11
+ export * as Admin from "./admin";
@@ -0,0 +1,49 @@
1
+ import { Schema } from "effect";
2
+ export type SortDirection = "asc" | "desc";
3
+ export interface SortState {
4
+ readonly id: string;
5
+ readonly desc: boolean;
6
+ }
7
+ export interface SortParam {
8
+ readonly id: string;
9
+ readonly direction: SortDirection;
10
+ }
11
+ export declare const SortDirection: Schema.Union<readonly [Schema.Literal<"asc">, Schema.Literal<"desc">]>;
12
+ export declare const SortParam: Schema.Struct<{
13
+ readonly id: Schema.NonEmptyString;
14
+ readonly direction: Schema.Union<readonly [Schema.Literal<"asc">, Schema.Literal<"desc">]>;
15
+ }>;
16
+ export declare const SortParamFromString: Schema.decodeTo<Schema.Struct<{
17
+ readonly id: Schema.NonEmptyString;
18
+ readonly direction: Schema.Union<readonly [Schema.Literal<"asc">, Schema.Literal<"desc">]>;
19
+ }>, Schema.String, never, never>;
20
+ export declare const SortParamsFromString: Schema.decodeTo<Schema.$Array<Schema.Struct<{
21
+ readonly id: Schema.NonEmptyString;
22
+ readonly direction: Schema.Union<readonly [Schema.Literal<"asc">, Schema.Literal<"desc">]>;
23
+ }>>, Schema.String, never, never>;
24
+ export declare const Query: Schema.Struct<{
25
+ readonly page: Schema.Int;
26
+ readonly pageSize: Schema.Int;
27
+ readonly globalFilter: Schema.optional<Schema.String>;
28
+ readonly sort: Schema.optional<Schema.decodeTo<Schema.String, Schema.decodeTo<Schema.$Array<Schema.Struct<{
29
+ readonly id: Schema.NonEmptyString;
30
+ readonly direction: Schema.Union<readonly [Schema.Literal<"asc">, Schema.Literal<"desc">]>;
31
+ }>>, Schema.String, never, never>, never, never>>;
32
+ }>;
33
+ export type QueryType = typeof Query.Type;
34
+ export declare const PaginationMeta: Schema.Struct<{
35
+ readonly page: Schema.Int;
36
+ readonly pageSize: Schema.Int;
37
+ readonly total: Schema.Int;
38
+ readonly pageCount: Schema.Int;
39
+ }>;
40
+ export type PaginationMetaType = typeof PaginationMeta.Type;
41
+ export declare const PaginatedResponse: <A>(items: Schema.Schema<A>) => Schema.Struct<{
42
+ readonly data: Schema.$Array<Schema.Schema<A>>;
43
+ readonly meta: Schema.Struct<{
44
+ readonly page: Schema.Int;
45
+ readonly pageSize: Schema.Int;
46
+ readonly total: Schema.Int;
47
+ readonly pageCount: Schema.Int;
48
+ }>;
49
+ }>;
package/dist/query.js ADDED
@@ -0,0 +1,114 @@
1
+ import { Effect, Option, Schema, SchemaIssue, SchemaTransformation, } from "effect";
2
+ const parseSortParam = (sort) => {
3
+ const id = sort.startsWith("-") ? sort.slice(1) : sort;
4
+ if (!id || id.includes(",") || id.includes(":")) {
5
+ return null;
6
+ }
7
+ return { id, direction: sort.startsWith("-") ? "desc" : "asc" };
8
+ };
9
+ export const SortDirection = Schema.Union([
10
+ Schema.Literal("asc"),
11
+ Schema.Literal("desc"),
12
+ ]).annotate({
13
+ identifier: "SortDirection",
14
+ title: "Sort Direction",
15
+ description: "Sort direction for list query results.",
16
+ examples: ["asc", "desc"],
17
+ });
18
+ export const SortParam = Schema.Struct({
19
+ id: Schema.NonEmptyString,
20
+ direction: SortDirection,
21
+ }).annotate({
22
+ identifier: "SortParam",
23
+ title: "Sort Parameter",
24
+ description: "Decoded sort parameter with a field id and direction.",
25
+ examples: [{ id: "name", direction: "asc" }],
26
+ });
27
+ export const SortParamFromString = Schema.String.pipe(Schema.decodeTo(SortParam, SchemaTransformation.transformOrFail({
28
+ decode: (sort) => {
29
+ const sortParam = parseSortParam(sort);
30
+ if (!sortParam) {
31
+ return Effect.fail(new SchemaIssue.InvalidValue(Option.some(sort), {
32
+ message: 'Expected sort in the format "field" or "-field"',
33
+ }));
34
+ }
35
+ return Effect.succeed(sortParam);
36
+ },
37
+ encode: (sort) => Effect.succeed(sort.direction === "desc" ? `-${sort.id}` : sort.id),
38
+ })), Schema.annotate({
39
+ identifier: "SortParamFromString",
40
+ title: "Sort Parameter From String",
41
+ description: 'URL encoded single sort parameter where descending fields are prefixed with "-".',
42
+ examples: [{ id: "name", direction: "asc" }],
43
+ }));
44
+ export const SortParamsFromString = Schema.String.pipe(Schema.decodeTo(Schema.Array(SortParam), SchemaTransformation.transformOrFail({
45
+ decode: (sort) => {
46
+ const parts = sort.split(",");
47
+ const sortParams = [];
48
+ for (const part of parts) {
49
+ const sortParam = parseSortParam(part);
50
+ if (!sortParam) {
51
+ return Effect.fail(new SchemaIssue.InvalidValue(Option.some(sort), {
52
+ message: 'Expected sort in the format "field,-otherField"',
53
+ }));
54
+ }
55
+ sortParams.push(sortParam);
56
+ }
57
+ return Effect.succeed(sortParams);
58
+ },
59
+ encode: (sort) => Effect.succeed(sort
60
+ .map((part) => Schema.encodeSync(SortParamFromString)(part))
61
+ .join(",")),
62
+ })), Schema.annotate({
63
+ identifier: "SortParamsFromString",
64
+ title: "Sort Parameters From String",
65
+ description: 'URL encoded sort parameters where descending fields are prefixed with "-" and multiple fields are comma-separated.',
66
+ examples: [
67
+ [
68
+ { id: "name", direction: "desc" },
69
+ { id: "createdAt", direction: "asc" },
70
+ ],
71
+ ],
72
+ }));
73
+ const SortParamSearch = SortParamsFromString.pipe(Schema.decodeTo(Schema.String, SchemaTransformation.transform({
74
+ decode: (sort) => Schema.encodeSync(SortParamsFromString)(sort),
75
+ encode: (sort) => Schema.decodeUnknownSync(SortParamsFromString)(sort),
76
+ })), Schema.annotate({
77
+ identifier: "SortParamSearch",
78
+ title: "Sort Search Parameter",
79
+ description: 'Search parameter sort value normalized to the compact "-field,otherField" URL format.',
80
+ examples: ["-name,createdAt"],
81
+ }));
82
+ export const Query = Schema.Struct({
83
+ page: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)),
84
+ pageSize: Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 100 })),
85
+ globalFilter: Schema.optional(Schema.String),
86
+ sort: Schema.optional(SortParamSearch),
87
+ }).annotate({
88
+ identifier: "Query",
89
+ title: "Query",
90
+ description: "Zero-based page request parameters with optional filtering and sorting for list endpoints.",
91
+ examples: [
92
+ {
93
+ page: 0,
94
+ pageSize: 10,
95
+ globalFilter: "housing",
96
+ sort: "-name,createdAt",
97
+ },
98
+ ],
99
+ });
100
+ export const PaginationMeta = Schema.Struct({
101
+ page: Schema.Int,
102
+ pageSize: Schema.Int,
103
+ total: Schema.Int,
104
+ pageCount: Schema.Int,
105
+ }).annotate({
106
+ identifier: "PaginationMeta",
107
+ title: "Pagination Metadata",
108
+ description: "Pagination metadata returned with a paginated list response.",
109
+ examples: [{ page: 0, pageSize: 10, total: 125, pageCount: 13 }],
110
+ });
111
+ export const PaginatedResponse = (items) => Schema.Struct({
112
+ data: Schema.Array(items),
113
+ meta: PaginationMeta,
114
+ });
@@ -1,9 +1,9 @@
1
1
  export { AuthService } from "../service";
2
2
  export type { AuthSession, AuthSessionWithOrganization, AuthSessionWithUser, AuthSessionWithUserAndOrganization, } from "../service";
3
3
  export { AuthClientConfig } from "../config";
4
- export { ServerApi, ServerOrganizationsApiGroup, ServerUsersApiGroup, } from "./api";
4
+ export { ServerApi, ServerDomainsApiGroup, ServerOrganizationsApiGroup, ServerUsersApiGroup, } from "./api";
5
5
  export { proxyAuthRequest } from "./proxy";
6
6
  export { ApiKeySecurity, AuthMiddleware, makeAuthenticationLive, } from "./middleware";
7
7
  export type { AuthenticationLiveOptions } from "./middleware";
8
- export type { ServerActiveOrganization, ServerMembersResponse, ServerOrganizationsResponse, ServerUsersResponse, } from "./schema";
8
+ export { ServerActiveOrganization, ServerCreateDomainPayload, ServerDomain, ServerDomainHostParams, ServerDomainIdParams, ServerDomainRecordsResponse, ServerMembersResponse, ServerOrganizationsResponse, ServerUpdateDomainPayload, ServerUsersResponse, } from "./schema";
9
9
  export type { Member, Organization, OrganizationMetadata, User, } from "../schema";
@@ -1,5 +1,6 @@
1
1
  export { AuthService } from "../service";
2
2
  export { AuthClientConfig } from "../config";
3
- export { ServerApi, ServerOrganizationsApiGroup, ServerUsersApiGroup, } from "./api";
3
+ export { ServerApi, ServerDomainsApiGroup, ServerOrganizationsApiGroup, ServerUsersApiGroup, } from "./api";
4
4
  export { proxyAuthRequest } from "./proxy";
5
5
  export { ApiKeySecurity, AuthMiddleware, makeAuthenticationLive, } from "./middleware";
6
+ export { ServerActiveOrganization, ServerCreateDomainPayload, ServerDomain, ServerDomainHostParams, ServerDomainIdParams, ServerDomainRecordsResponse, ServerMembersResponse, ServerOrganizationsResponse, ServerUpdateDomainPayload, ServerUsersResponse, } from "./schema";
package/dist/service.js CHANGED
@@ -2,7 +2,7 @@ import { Cache, Context, Duration, Effect, Exit, Layer, Redacted, } from "effect
2
2
  import { FetchHttpClient, HttpClient, HttpClientRequest, } from "effect/unstable/http";
3
3
  import { HttpApiClient } from "effect/unstable/httpapi";
4
4
  import { HttpApiError } from "effect/unstable/httpapi";
5
- import { AuthApi } from "./api";
5
+ import { AuthServiceApi } from "./api";
6
6
  import { AuthClientConfig } from "./config";
7
7
  import { ExtraVerifiedApiKey } from "./extra/schema";
8
8
  const forwardedAuthHeaderNames = [
@@ -65,7 +65,7 @@ export class AuthService extends Context.Service()("@krak-stack/auth/AuthService
65
65
  const httpClient = HttpClient.mapRequest(http, (request) => isBetterAuthSessionRequest(request)
66
66
  ? request
67
67
  : HttpClientRequest.bearerToken(request, Redacted.value(config.apiKey)));
68
- const api = yield* HttpApiClient.makeWith(AuthApi, {
68
+ const api = yield* HttpApiClient.makeWith(AuthServiceApi, {
69
69
  baseUrl: config.baseUrl,
70
70
  httpClient,
71
71
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@krak-stack/auth",
3
- "version": "0.1.40",
3
+ "version": "0.1.41",
4
4
  "description": "Effect HttpApi clients and schemas for KrakStack Auth.",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -26,6 +26,10 @@
26
26
  "types": "./dist/schema.d.ts",
27
27
  "default": "./dist/schema.js"
28
28
  },
29
+ "./query": {
30
+ "types": "./dist/query.d.ts",
31
+ "default": "./dist/query.js"
32
+ },
29
33
  "./components": {
30
34
  "types": "./dist/components/index.d.ts",
31
35
  "default": "./dist/components/index.js"
@@ -42,6 +46,10 @@
42
46
  "./server": {
43
47
  "types": "./dist/server/index.d.ts",
44
48
  "default": "./dist/server/index.js"
49
+ },
50
+ "./admin": {
51
+ "types": "./dist/admin/index.d.ts",
52
+ "default": "./dist/admin/index.js"
45
53
  }
46
54
  },
47
55
  "publishConfig": {
@@ -1,29 +0,0 @@
1
- import { Effect } from "effect";
2
- import { FetchHttpClient, HttpClient } from "effect/unstable/http";
3
- import { AtomHttpApi } from "effect/unstable/reactivity";
4
- import { AuthApi } from "../api";
5
- const authApiUrl = (baseUrl) => {
6
- const url = baseUrl?.trim() ||
7
- (typeof window === "undefined"
8
- ? "http://localhost:3000"
9
- : window.location.origin);
10
- return url.replace(/\/$/, "");
11
- };
12
- const createAuthApiClient = (key) => AtomHttpApi.Service()(`AuthApi:${key}`, {
13
- api: AuthApi,
14
- baseUrl: key,
15
- httpClient: FetchHttpClient.layer,
16
- transformClient: (client) => HttpClient.makeWith((request) => client.postprocess(request).pipe(Effect.provideService(FetchHttpClient.RequestInit, {
17
- credentials: "include",
18
- })), client.preprocess),
19
- });
20
- const authApiClients = new Map();
21
- export const authApiClient = (baseUrl) => {
22
- const key = authApiUrl(baseUrl);
23
- const existing = authApiClients.get(key);
24
- if (existing)
25
- return existing;
26
- const client = createAuthApiClient(key);
27
- authApiClients.set(key, client);
28
- return client;
29
- };