@krak-stack/auth 0.1.40 → 0.1.42

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.
Files changed (40) hide show
  1. package/dist/admin/api.group.d.ts +197 -0
  2. package/dist/admin/api.group.js +159 -0
  3. package/dist/admin/schema.d.ts +128 -0
  4. package/dist/admin/schema.js +190 -0
  5. package/dist/api.d.ts +264 -11
  6. package/dist/api.js +14 -5
  7. package/dist/better-auth/{index.d.ts → api.group.d.ts} +6 -8
  8. package/dist/better-auth/{api.js → api.group.js} +2 -4
  9. package/dist/components/admin-organization-form.d.ts +3 -3
  10. package/dist/components/admin-organization-form.js +9 -19
  11. package/dist/components/admin-organizations.js +16 -12
  12. package/dist/components/admin-users.d.ts +1 -1
  13. package/dist/components/admin-users.js +35 -18
  14. package/dist/components/{auth-api-client.d.ts → auth-client-api.d.ts} +179 -209
  15. package/dist/components/auth-client-api.js +29 -0
  16. package/dist/components/auth-forms.js +3 -3
  17. package/dist/components/auth-provider.js +2 -2
  18. package/dist/components/organization-switcher.js +15 -16
  19. package/dist/components/user-button.js +3 -3
  20. package/dist/components/utils.d.ts +11 -0
  21. package/dist/components/utils.js +24 -0
  22. package/dist/extra/api.group.d.ts +68 -0
  23. package/dist/extra/{api.js → api.group.js} +5 -17
  24. package/dist/index.d.ts +5 -3
  25. package/dist/index.js +5 -3
  26. package/dist/query.d.ts +49 -0
  27. package/dist/query.js +114 -0
  28. package/dist/server/{api.d.ts → api.group.d.ts} +0 -196
  29. package/dist/server/{api.js → api.group.js} +1 -6
  30. package/dist/server/index.d.ts +2 -2
  31. package/dist/server/index.js +2 -1
  32. package/dist/service.d.ts +12 -24
  33. package/dist/service.js +2 -2
  34. package/package.json +13 -5
  35. package/dist/better-auth/api.d.ts +0 -55
  36. package/dist/better-auth/index.js +0 -12
  37. package/dist/components/auth-api-client.js +0 -29
  38. package/dist/extra/api.d.ts +0 -139
  39. package/dist/extra/index.d.ts +0 -76
  40. package/dist/extra/index.js +0 -14
@@ -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.",
@@ -271,11 +270,11 @@ const isOrganizationSlugConflict = (error) => {
271
270
  };
272
271
  const nullableString = (value) => typeof value === "string" && value.trim() ? value.trim() : null;
273
272
  const decodeUploadedAsset = Schema.decodeUnknownPromise(ExtraUploadedAsset);
274
- const uploadOrganizationLogoAsset = async (file, m, uploadOrganizationLogo) => {
273
+ const uploadImageAsset = async (file, m, uploadImage) => {
275
274
  const payload = new FormData();
276
275
  payload.append("file", file);
277
276
  try {
278
- const uploaded = await decodeUploadedAsset(await uploadOrganizationLogo({ payload }));
277
+ const uploaded = await decodeUploadedAsset(await uploadImage({ payload }));
279
278
  return assetPath(uploaded.url);
280
279
  }
281
280
  catch {
@@ -329,9 +328,9 @@ const organizationFormDefaults = (organization, baseUrl) => {
329
328
  frLocation: fr?.location ?? "",
330
329
  };
331
330
  };
332
- const organizationLogoFromForm = async (value, m, uploadOrganizationLogo) => {
331
+ const organizationLogoFromForm = async (value, m, uploadImage) => {
333
332
  if (value instanceof File)
334
- return await uploadOrganizationLogoAsset(value, m, uploadOrganizationLogo);
333
+ return await uploadImageAsset(value, m, uploadImage);
335
334
  if (typeof value === "string")
336
335
  return assetPath(value);
337
336
  return null;
@@ -349,14 +348,14 @@ const organizationRoleLabel = (role, m) => {
349
348
  }
350
349
  };
351
350
  const formatOrganizationDate = (date) => new Intl.DateTimeFormat(getLocale(), { dateStyle: "medium" }).format(new Date(date));
352
- const organizationMetadataFromForm = async (value, m, uploadOrganizationLogo) => {
351
+ const organizationMetadataFromForm = async (value, m, uploadImage) => {
353
352
  const translations = [];
354
353
  const enName = value.enName.trim() || value.name.trim();
355
354
  const frName = value.frName.trim();
356
- const enLogo = await organizationLogoFromForm(value.enLogo, m, uploadOrganizationLogo);
357
- const enIcon = await organizationLogoFromForm(value.enIcon, m, uploadOrganizationLogo);
358
- const frLogo = await organizationLogoFromForm(value.frLogo, m, uploadOrganizationLogo);
359
- const frIcon = await organizationLogoFromForm(value.frIcon, m, uploadOrganizationLogo);
355
+ const enLogo = await organizationLogoFromForm(value.enLogo, m, uploadImage);
356
+ const enIcon = await organizationLogoFromForm(value.enIcon, m, uploadImage);
357
+ const frLogo = await organizationLogoFromForm(value.frLogo, m, uploadImage);
358
+ const frIcon = await organizationLogoFromForm(value.frIcon, m, uploadImage);
360
359
  if (enName) {
361
360
  translations.push({
362
361
  locale: "en",
@@ -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 uploadImage = useAtomSet(authClientApi(baseUrl).mutation("authExtra", "uploadUserImage"), { mode: "promise" });
567
566
  const [editingLocale, setEditingLocale] = useState(currentOrganizationLocale());
568
567
  const defaultValues = organizationFormDefaults(organization, baseUrl);
569
568
  const form = useAppForm({
@@ -573,7 +572,7 @@ function EditOrganizationSection({ authClient, baseUrl, organization, onUpdated,
573
572
  try {
574
573
  const name = value.name.trim();
575
574
  const slug = value.slug.trim().toLowerCase();
576
- const metadata = await organizationMetadataFromForm(value, m, uploadOrganizationLogo);
575
+ const metadata = await organizationMetadataFromForm(value, m, uploadImage);
577
576
  const result = await authClient.organization.update({
578
577
  organizationId: organization.id,
579
578
  data: { name, slug, metadata },
@@ -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 uploadImage = useAtomSet(authClientApi(baseUrl).mutation("authExtra", "uploadUserImage"), { mode: "promise" });
643
642
  const [editingLocale, setEditingLocale] = useState(currentOrganizationLocale());
644
643
  const defaultValues = organizationFormDefaults(undefined, baseUrl);
645
644
  const form = useAppForm({
@@ -653,7 +652,7 @@ function CreateOrganizationSection({ authClient, baseUrl, onCreated, }) {
653
652
  ...value,
654
653
  name,
655
654
  slug,
656
- }, m, uploadOrganizationLogo);
655
+ }, m, uploadImage);
657
656
  const result = await authClient.organization.create({
658
657
  name,
659
658
  slug,
@@ -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) => {
@@ -0,0 +1,68 @@
1
+ import { HttpApiEndpoint, HttpApiError, HttpApiGroup } from "effect/unstable/httpapi";
2
+ import { ExtraBadRequest } from "./schema";
3
+ export * from "./schema";
4
+ export type { Organization, OrganizationMetadata } from "../schema";
5
+ export declare const ExtraApiGroup: HttpApiGroup.HttpApiGroup<"authExtra", HttpApiEndpoint.HttpApiEndpoint<"createApiKey", "POST", "/auth/create-api-key", HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<import("effect/Schema").Struct<{
6
+ readonly configId: import("effect/Schema").Union<readonly [import("effect/Schema").Literal<"user">, import("effect/Schema").Literal<"organization">, import("effect/Schema").Literal<"service">]>;
7
+ readonly name: import("effect/Schema").optional<import("effect/Schema").NonEmptyString>;
8
+ readonly organizationId: import("effect/Schema").optional<import("effect/Schema").String>;
9
+ readonly permissions: import("effect/Schema").optional<import("effect/Schema").$Record<import("effect/Schema").String, import("effect/Schema").$Array<import("effect/Schema").String>>>;
10
+ }>>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<import("effect/Schema").Struct<{
11
+ readonly id: import("effect/Schema").String;
12
+ readonly key: import("effect/Schema").String;
13
+ }>>, HttpApiEndpoint.Json<typeof ExtraBadRequest>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"getProjectPublicConfig", "GET", "/auth/project-config", HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<import("effect/Schema").Struct<{
14
+ readonly projectId: import("effect/Schema").optional<import("effect/Schema").String>;
15
+ readonly clientId: import("effect/Schema").optional<import("effect/Schema").String>;
16
+ readonly host: import("effect/Schema").optional<import("effect/Schema").String>;
17
+ readonly rootHost: import("effect/Schema").optional<import("effect/Schema").String>;
18
+ }>>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<import("effect/Schema").Struct<{
19
+ readonly projectKey: import("effect/Schema").String;
20
+ readonly name: import("effect/Schema").NullOr<import("effect/Schema").String>;
21
+ readonly logoUrl: import("effect/Schema").NullOr<import("effect/Schema").String>;
22
+ readonly authDomain: import("effect/Schema").NullOr<import("effect/Schema").String>;
23
+ readonly rootDomain: import("effect/Schema").NullOr<import("effect/Schema").String>;
24
+ readonly themeCss: import("effect/Schema").NullOr<import("effect/Schema").String>;
25
+ readonly authOptions: import("effect/Schema").Struct<{
26
+ readonly emailPassword: import("effect/Schema").Boolean;
27
+ readonly emailOtp: import("effect/Schema").Boolean;
28
+ readonly google: import("effect/Schema").Boolean;
29
+ readonly signUp: import("effect/Schema").Boolean;
30
+ readonly signUpName: import("effect/Schema").Boolean;
31
+ }>;
32
+ }>>, HttpApiEndpoint.Json<typeof HttpApiError.InternalServerError>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"setPassword", "POST", "/auth/set-password", HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<import("effect/Schema").Struct<{
33
+ readonly newPassword: import("effect/Schema").NonEmptyString;
34
+ }>>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<import("effect/Schema").Struct<{
35
+ readonly ok: import("effect/Schema").Boolean;
36
+ }>>, HttpApiEndpoint.Json<typeof ExtraBadRequest>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"uploadUserImage", "POST", "/auth/image/upload", HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<import("effect/unstable/httpapi/HttpApiSchema").asMultipartStream<import("effect/Schema").Struct<{
37
+ readonly file: import("effect/Schema").decodeTo<import("effect/unstable/http/Multipart").PersistedFileSchema, import("effect/Schema").$Array<import("effect/unstable/http/Multipart").PersistedFileSchema>, never, never>;
38
+ }>>>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<import("effect/Schema").Struct<{
39
+ readonly url: import("effect/Schema").String;
40
+ }>>, HttpApiEndpoint.Json<typeof HttpApiError.Unauthorized | typeof HttpApiError.InternalServerError | typeof ExtraBadRequest>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"verifyApiKey", "POST", "/auth/verify-api-key", HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<import("effect/Schema").Struct<{
41
+ readonly key: import("effect/Schema").NonEmptyString;
42
+ readonly configId: import("effect/Schema").optional<import("effect/Schema").Union<readonly [import("effect/Schema").Literal<"user">, import("effect/Schema").Literal<"organization">, import("effect/Schema").Literal<"service">]>>;
43
+ readonly permissions: import("effect/Schema").optional<import("effect/Schema").$Record<import("effect/Schema").String, import("effect/Schema").$Array<import("effect/Schema").String>>>;
44
+ }>>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<import("effect/Schema").Struct<{
45
+ readonly valid: import("effect/Schema").Boolean;
46
+ readonly error: import("effect/Schema").NullOr<import("effect/Schema").Struct<{
47
+ readonly message: import("effect/Schema").String;
48
+ readonly code: import("effect/Schema").String;
49
+ }>>;
50
+ readonly key: import("effect/Schema").NullOr<import("effect/Schema").Struct<{
51
+ readonly id: import("effect/Schema").String;
52
+ readonly configId: import("effect/Schema").String;
53
+ readonly name: import("effect/Schema").NullOr<import("effect/Schema").String>;
54
+ readonly start: import("effect/Schema").NullOr<import("effect/Schema").String>;
55
+ readonly prefix: import("effect/Schema").NullOr<import("effect/Schema").String>;
56
+ readonly referenceId: import("effect/Schema").String;
57
+ readonly enabled: import("effect/Schema").NullOr<import("effect/Schema").Boolean>;
58
+ readonly expiresAt: import("effect/Schema").NullOr<import("effect/Schema").Date>;
59
+ readonly createdAt: import("effect/Schema").Date;
60
+ readonly updatedAt: import("effect/Schema").Date;
61
+ readonly permissions: import("effect/Schema").NullOr<import("effect/Schema").$Record<import("effect/Schema").String, import("effect/Schema").$Array<import("effect/Schema").String>>>;
62
+ readonly metadata: import("effect/Schema").NullOr<import("effect/Schema").Unknown>;
63
+ }>>;
64
+ }>>, HttpApiEndpoint.Json<typeof ExtraBadRequest>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"verifyPassword", "POST", "/auth/verify-password", HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<import("effect/Schema").Struct<{
65
+ readonly password: import("effect/Schema").NonEmptyString;
66
+ }>>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<import("effect/Schema").Struct<{
67
+ readonly ok: import("effect/Schema").Boolean;
68
+ }>>, HttpApiEndpoint.Json<typeof ExtraBadRequest>, never, never>, false>;
@@ -1,6 +1,7 @@
1
- import { HttpApi, OpenApi } from "effect/unstable/httpapi";
1
+ import { OpenApi } from "effect/unstable/httpapi";
2
2
  import { HttpApiEndpoint, HttpApiError, HttpApiGroup, } from "effect/unstable/httpapi";
3
3
  import { ExtraBadRequest, ExtraCreateApiKeyPayload, ExtraCreateApiKeyResponse, ExtraImageUploadMultipartPayload, ExtraOkResponse, ExtraProjectPublicConfig, ExtraProjectPublicConfigQuery, ExtraSetPasswordPayload, ExtraUploadedAsset, ExtraVerifyApiKeyPayload, ExtraVerifyApiKeyResponse, ExtraVerifyPasswordPayload, } from "./schema";
4
+ export * from "./schema";
4
5
  export const ExtraApiGroup = HttpApiGroup.make("authExtra")
5
6
  .add(HttpApiEndpoint.get("getProjectPublicConfig", "/auth/project-config", {
6
7
  query: ExtraProjectPublicConfigQuery,
@@ -56,24 +57,11 @@ export const ExtraApiGroup = HttpApiGroup.make("authExtra")
56
57
  HttpApiError.InternalServerError,
57
58
  ],
58
59
  }).annotateMerge(OpenApi.annotations({
59
- title: "Upload user image",
60
- summary: "Upload a user profile image",
61
- description: "Accepts a multipart image upload and stores it as the current user's profile image asset.",
60
+ title: "Upload image",
61
+ summary: "Upload an authenticated image asset",
62
+ description: "Accepts a multipart image upload and stores it as an authenticated image asset for profiles, organizations, and branding.",
62
63
  })))
63
- .add(HttpApiEndpoint.post("uploadOrganizationLogo", "/organizations/logo/upload", {
64
- payload: ExtraImageUploadMultipartPayload,
65
- success: ExtraUploadedAsset,
66
- error: [
67
- HttpApiError.BadRequest,
68
- HttpApiError.Unauthorized,
69
- HttpApiError.Forbidden,
70
- HttpApiError.InternalServerError,
71
- ],
72
- }))
73
64
  .annotateMerge(OpenApi.annotations({
74
65
  title: "Extra",
75
66
  description: "KrakStack-specific endpoints layered on top of Better Auth.",
76
67
  }));
77
- export const ExtraApi = HttpApi.make("ExtraApi")
78
- .add(ExtraApiGroup)
79
- .prefix("/api");
package/dist/index.d.ts CHANGED
@@ -1,9 +1,11 @@
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";
6
7
  export { OrganizationSwitcher, KrakstackAuthProvider, ResetPassword, Signin, Signup, TwoFactor, AdminOrganizationForm, AdminOrganizationsTable, AdminUsersTable, UserButton, type AuthUiClient, type KrakstackAuthContextValue, type KrakstackAuthLocale, type KrakstackAuthProviderProps, type OrganizationSwitcherDialog, type UserButtonDialog, useAdminUsersTotal, } from "./components";
7
- export * as BetterAuth from "./better-auth";
8
- export * as Extra from "./extra";
8
+ export * as BetterAuth from "./better-auth/api.group";
9
+ export * as Extra from "./extra/api.group";
9
10
  export * as Server from "./server";
11
+ export * as Admin from "./admin/api.group";
package/dist/index.js CHANGED
@@ -1,9 +1,11 @@
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";
6
7
  export { OrganizationSwitcher, KrakstackAuthProvider, ResetPassword, Signin, Signup, TwoFactor, AdminOrganizationForm, AdminOrganizationsTable, AdminUsersTable, UserButton, useAdminUsersTotal, } from "./components";
7
- export * as BetterAuth from "./better-auth";
8
- export * as Extra from "./extra";
8
+ export * as BetterAuth from "./better-auth/api.group";
9
+ export * as Extra from "./extra/api.group";
9
10
  export * as Server from "./server";
11
+ export * as Admin from "./admin/api.group";
@@ -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
+ });