@krak-stack/auth 0.1.71 → 0.2.1

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 (78) hide show
  1. package/README.md +4 -3
  2. package/dist/access.d.ts +5 -7
  3. package/dist/access.js +11 -7
  4. package/dist/admin/api.group.d.ts +53 -53
  5. package/dist/admin/api.group.js +15 -15
  6. package/dist/admin/schema.d.ts +18 -18
  7. package/dist/admin/schema.js +3 -3
  8. package/dist/api.d.ts +1995 -533
  9. package/dist/api.js +7 -7
  10. package/dist/auth/api.group.d.ts +793 -0
  11. package/dist/auth/api.group.js +241 -0
  12. package/dist/auth/schema.d.ts +808 -0
  13. package/dist/auth/schema.js +628 -0
  14. package/dist/components/admin-organization-form.d.ts +1 -1
  15. package/dist/components/admin-organization-form.js +17 -18
  16. package/dist/components/admin-organizations.d.ts +4 -5
  17. package/dist/components/admin-organizations.js +83 -73
  18. package/dist/components/admin-users.d.ts +5 -6
  19. package/dist/components/admin-users.js +160 -181
  20. package/dist/components/api-key-edit-form.d.ts +4 -3
  21. package/dist/components/api-key-edit-form.js +33 -27
  22. package/dist/components/api-key-permissions.d.ts +1 -1
  23. package/dist/components/api-key-rate-limit.d.ts +1 -1
  24. package/dist/components/api-key-referrers.d.ts +3 -2
  25. package/dist/components/api-key-referrers.js +2 -3
  26. package/dist/components/api-key.d.ts +0 -9
  27. package/dist/components/api-key.js +0 -39
  28. package/dist/components/auth-atoms.d.ts +178 -0
  29. package/dist/components/auth-atoms.js +46 -0
  30. package/dist/components/auth-client-api.d.ts +1371 -556
  31. package/dist/components/auth-client-api.js +22 -14
  32. package/dist/components/auth-forms.d.ts +1 -3
  33. package/dist/components/auth-forms.js +173 -195
  34. package/dist/components/auth-provider.d.ts +16 -20
  35. package/dist/components/auth-provider.js +56 -30
  36. package/dist/components/has-permission.js +1 -1
  37. package/dist/components/index.d.ts +19 -20
  38. package/dist/components/index.js +13 -13
  39. package/dist/components/member-required.d.ts +1 -3
  40. package/dist/components/member-required.js +102 -78
  41. package/dist/components/organization-switcher.d.ts +4 -6
  42. package/dist/components/organization-switcher.js +539 -390
  43. package/dist/components/project-access-matrix.d.ts +1 -1
  44. package/dist/components/project-access-matrix.js +9 -13
  45. package/dist/components/user-button.d.ts +5 -3
  46. package/dist/components/user-button.js +291 -336
  47. package/dist/components/utils.d.ts +3 -1
  48. package/dist/components/utils.js +4 -11
  49. package/dist/extra/api.group.d.ts +22 -22
  50. package/dist/extra/api.group.js +9 -9
  51. package/dist/extra/schema.d.ts +1 -2
  52. package/dist/extra/schema.js +2 -3
  53. package/dist/index.d.ts +11 -12
  54. package/dist/index.js +11 -12
  55. package/dist/query.d.ts +2 -2
  56. package/dist/query.js +5 -5
  57. package/dist/roles.d.ts +5 -4
  58. package/dist/roles.js +11 -7
  59. package/dist/schema.d.ts +1 -1
  60. package/dist/schema.js +26 -19
  61. package/dist/server/actor.d.ts +20 -22
  62. package/dist/server/actor.js +14 -17
  63. package/dist/server/api.group.d.ts +29 -29
  64. package/dist/server/api.group.js +14 -14
  65. package/dist/server/index.d.ts +14 -14
  66. package/dist/server/index.js +8 -8
  67. package/dist/server/middleware.d.ts +1 -1
  68. package/dist/server/middleware.js +1 -1
  69. package/dist/server/schema.js +1 -1
  70. package/dist/service.d.ts +1997 -583
  71. package/dist/service.js +23 -16
  72. package/package.json +10 -9
  73. package/dist/better-auth/api.group.d.ts +0 -62
  74. package/dist/better-auth/api.group.js +0 -39
  75. package/dist/better-auth/schema.d.ts +0 -72
  76. package/dist/better-auth/schema.js +0 -110
  77. package/dist/components/auth-client.d.ts +0 -50
  78. package/dist/components/auth-client.js +0 -46
@@ -1,4 +1,6 @@
1
- export declare const isRecord: (value: unknown) => value is Record<string, unknown>;
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 {
@@ -1,16 +1,9 @@
1
1
  import { Schema } from "effect";
2
- import { OrganizationMetadata } from "../schema";
3
- export const isRecord = (value) => typeof value === "object" && value !== null;
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 = (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
- };
6
+ const parseOrganizationMetadata = decodeOrganizationMetadata;
14
7
  export const organizationBranding = (organization, locale = "en") => {
15
8
  if (!organization)
16
9
  return null;
@@ -1,21 +1,21 @@
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";
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<{
3
+ import { ExtraBadRequest } from "./schema.js";
4
+ export * from "./schema.js";
5
+ export type { Organization, OrganizationMetadata } from "../schema.js";
6
+ export declare const ExtraApiGroup: HttpApiGroup.HttpApiGroup<"authExtra", HttpApiEndpoint.HttpApiEndpoint<"createApiKey", "POST", "/auth/create-api-key", never, never, Schema.toCodecJson<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>;
9
9
  readonly organizationId: Schema.optional<Schema.String>;
10
10
  readonly permissions: Schema.optional<Schema.$Record<Schema.String, Schema.$Array<Schema.String>>>;
11
11
  readonly referrers: Schema.optional<Schema.$Array<Schema.String>>;
12
- }>>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<Schema.Struct<{
12
+ }>>, never, Schema.toCodecJson<Schema.Struct<{
13
13
  readonly id: Schema.String;
14
14
  readonly key: Schema.String;
15
- }>>, HttpApiEndpoint.Json<typeof HttpApiError.Unauthorized | typeof HttpApiError.Forbidden | typeof HttpApiError.InternalServerError | typeof ExtraBadRequest>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"getOrganizationPublicProfile", "GET", "/auth/organization-profile", HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<Schema.Struct<{
15
+ }>>, Schema.toCodecJson<typeof HttpApiError.Unauthorized | typeof HttpApiError.Forbidden | typeof HttpApiError.InternalServerError | typeof ExtraBadRequest>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"getOrganizationPublicProfile", "GET", "/auth/organization-profile", never, Schema.toCodecStringTree<Schema.Struct<{
16
16
  readonly organizationId: Schema.String;
17
17
  readonly locale: Schema.optional<Schema.Union<readonly [Schema.Literal<"en">, Schema.Literal<"fr">]>>;
18
- }>>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<Schema.Struct<{
18
+ }>>, never, never, Schema.toCodecJson<Schema.Struct<{
19
19
  readonly id: Schema.String;
20
20
  readonly name: Schema.String;
21
21
  readonly slug: Schema.String;
@@ -65,12 +65,12 @@ export declare const ExtraApiGroup: HttpApiGroup.HttpApiGroup<"authExtra", HttpA
65
65
  }>>>;
66
66
  readonly logo: Schema.NullOr<Schema.String>;
67
67
  readonly icon: Schema.NullOr<Schema.String>;
68
- }>>, HttpApiEndpoint.Json<typeof HttpApiError.NotFound | typeof HttpApiError.InternalServerError>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"getProjectPublicConfig", "GET", "/auth/project-config", HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<Schema.Struct<{
68
+ }>>, Schema.toCodecJson<typeof HttpApiError.NotFound | typeof HttpApiError.InternalServerError>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"getProjectPublicConfig", "GET", "/auth/project-config", never, Schema.toCodecStringTree<Schema.Struct<{
69
69
  readonly projectId: Schema.optional<Schema.String>;
70
70
  readonly clientId: Schema.optional<Schema.String>;
71
71
  readonly host: Schema.optional<Schema.String>;
72
72
  readonly rootHost: Schema.optional<Schema.String>;
73
- }>>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<Schema.Struct<{
73
+ }>>, never, never, Schema.toCodecJson<Schema.Struct<{
74
74
  readonly projectKey: Schema.String;
75
75
  readonly name: Schema.NullOr<Schema.String>;
76
76
  readonly logoUrl: Schema.NullOr<Schema.String>;
@@ -82,28 +82,28 @@ export declare const ExtraApiGroup: HttpApiGroup.HttpApiGroup<"authExtra", HttpA
82
82
  readonly emailOtp: Schema.Boolean;
83
83
  readonly google: Schema.Boolean;
84
84
  }>;
85
- }>>, HttpApiEndpoint.Json<typeof HttpApiError.InternalServerError>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"setPassword", "POST", "/auth/set-password", HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<Schema.Struct<{
85
+ }>>, Schema.toCodecJson<typeof HttpApiError.InternalServerError>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"setPassword", "POST", "/auth/set-password", never, never, Schema.toCodecJson<Schema.Struct<{
86
86
  readonly newPassword: Schema.NonEmptyString;
87
- }>>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<Schema.Struct<{
87
+ }>>, never, Schema.toCodecJson<Schema.Struct<{
88
88
  readonly ok: Schema.Boolean;
89
- }>>, HttpApiEndpoint.Json<typeof HttpApiError.Unauthorized | typeof HttpApiError.Forbidden | typeof HttpApiError.InternalServerError | typeof ExtraBadRequest>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"updateApiKey", "PATCH", "/auth/api-key/:keyId", HttpApiEndpoint.StringTree<Schema.Struct<{
90
- readonly keyId: Schema.NonEmptyString;
91
- }>>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<Schema.Struct<{
89
+ }>>, Schema.toCodecJson<typeof HttpApiError.Unauthorized | typeof HttpApiError.Forbidden | typeof HttpApiError.InternalServerError | typeof ExtraBadRequest>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"updateApiKey", "PATCH", "/auth/api-key/:keyId", Schema.toCodecStringTree<Schema.Struct<{
90
+ keyId: Schema.NonEmptyString;
91
+ }>>, never, Schema.toCodecJson<Schema.Struct<{
92
92
  readonly configId: Schema.Union<readonly [Schema.Literal<"user">, Schema.Literal<"organization">, Schema.Literal<"service">]>;
93
93
  readonly name: Schema.NonEmptyString;
94
94
  readonly enabled: Schema.Boolean;
95
95
  readonly permissions: Schema.optional<Schema.$Record<Schema.String, Schema.$Array<Schema.String>>>;
96
96
  readonly referrers: Schema.optional<Schema.$Array<Schema.String>>;
97
- }>>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<Schema.Struct<{
97
+ }>>, never, Schema.toCodecJson<Schema.Struct<{
98
98
  readonly ok: Schema.Boolean;
99
- }>>, HttpApiEndpoint.Json<typeof HttpApiError.Unauthorized | typeof HttpApiError.Forbidden | typeof HttpApiError.InternalServerError | 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<Schema.Struct<{
99
+ }>>, Schema.toCodecJson<typeof HttpApiError.Unauthorized | typeof HttpApiError.Forbidden | typeof HttpApiError.InternalServerError | typeof ExtraBadRequest>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"uploadUserImage", "POST", "/auth/image/upload", never, never, Schema.toCodecJson<import("effect/unstable/httpapi/HttpApiSchema").asMultipartStream<Schema.Struct<{
100
100
  readonly file: Schema.decodeTo<import("effect/unstable/http/Multipart").PersistedFileSchema, Schema.$Array<import("effect/unstable/http/Multipart").PersistedFileSchema>, never, never>;
101
- }>>>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<Schema.Struct<{
101
+ }>>>, never, Schema.toCodecJson<Schema.Struct<{
102
102
  readonly url: Schema.String;
103
- }>>, HttpApiEndpoint.Json<typeof HttpApiError.Unauthorized | typeof HttpApiError.Forbidden | typeof HttpApiError.InternalServerError | typeof ExtraBadRequest>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"verifyApiKey", "POST", "/auth/verify-api-key", HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<Schema.Struct<{
103
+ }>>, Schema.toCodecJson<typeof HttpApiError.Unauthorized | typeof HttpApiError.Forbidden | typeof HttpApiError.InternalServerError | typeof ExtraBadRequest>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"verifyApiKey", "POST", "/auth/verify-api-key", never, never, Schema.toCodecJson<Schema.Struct<{
104
104
  readonly key: Schema.NonEmptyString;
105
105
  readonly configId: Schema.optional<Schema.Union<readonly [Schema.Literal<"user">, Schema.Literal<"organization">, Schema.Literal<"service">]>>;
106
- }>>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<Schema.Struct<{
106
+ }>>, never, Schema.toCodecJson<Schema.Struct<{
107
107
  readonly valid: Schema.Boolean;
108
108
  readonly error: Schema.NullOr<Schema.Struct<{
109
109
  readonly message: Schema.String;
@@ -123,8 +123,8 @@ export declare const ExtraApiGroup: HttpApiGroup.HttpApiGroup<"authExtra", HttpA
123
123
  readonly permissions: Schema.NullOr<Schema.$Record<Schema.String, Schema.$Array<Schema.String>>>;
124
124
  readonly metadata: Schema.NullOr<Schema.Unknown>;
125
125
  }>>;
126
- }>>, HttpApiEndpoint.Json<typeof ExtraBadRequest>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"verifyPassword", "POST", "/auth/verify-password", HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<Schema.Struct<{
126
+ }>>, Schema.toCodecJson<typeof ExtraBadRequest>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"verifyPassword", "POST", "/auth/verify-password", never, never, Schema.toCodecJson<Schema.Struct<{
127
127
  readonly password: Schema.NonEmptyString;
128
- }>>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<Schema.Struct<{
128
+ }>>, never, Schema.toCodecJson<Schema.Struct<{
129
129
  readonly ok: Schema.Boolean;
130
- }>>, HttpApiEndpoint.Json<typeof HttpApiError.Unauthorized | typeof HttpApiError.Forbidden | typeof HttpApiError.InternalServerError | typeof ExtraBadRequest>, never, never>, false>;
130
+ }>>, Schema.toCodecJson<typeof HttpApiError.Unauthorized | typeof HttpApiError.Forbidden | typeof HttpApiError.InternalServerError | typeof ExtraBadRequest>, never, never>, false>;
@@ -1,11 +1,11 @@
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
- query: ExtraProjectPublicConfigQuery,
8
+ query: ExtraProjectPublicConfigQuery.fields,
9
9
  success: ExtraProjectPublicConfig,
10
10
  error: [HttpApiError.InternalServerError],
11
11
  }).annotateMerge(OpenApi.annotations({
@@ -14,7 +14,7 @@ export const ExtraApiGroup = HttpApiGroup.make("authExtra")
14
14
  description: "Returns resolved public branding and authentication options through the proxied auth API.",
15
15
  })))
16
16
  .add(HttpApiEndpoint.patch("updateApiKey", "/auth/api-key/:keyId", {
17
- params: Schema.Struct({ keyId: Schema.NonEmptyString }),
17
+ params: { keyId: Schema.NonEmptyString },
18
18
  payload: Schema.Struct({
19
19
  configId: ExtraUpdateApiKeyPayload.fields.configId,
20
20
  name: ExtraUpdateApiKeyPayload.fields.name,
@@ -32,10 +32,10 @@ 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 Better Auth verifies user ownership or organization key-management access.",
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
- query: ExtraOrganizationPublicProfileQuery,
38
+ query: ExtraOrganizationPublicProfileQuery.fields,
39
39
  success: ExtraOrganizationPublicProfile,
40
40
  error: [HttpApiError.NotFound, HttpApiError.InternalServerError],
41
41
  }).annotateMerge(OpenApi.annotations({
@@ -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 Better Auth's server-side API so server-only fields like permissions can be set.",
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 using Better Auth's server-side API key verifier.",
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 layered on top of Better Auth.",
113
+ description: "KrakStack-specific authentication endpoints.",
114
114
  }));
@@ -162,8 +162,7 @@ export declare const ExtraOkResponse: Schema.Struct<{
162
162
  export declare const ExtraUploadedAsset: Schema.Struct<{
163
163
  readonly url: Schema.String;
164
164
  }>;
165
- declare const ExtraBadRequest_base: Schema.Class<ExtraBadRequest, Schema.Struct<{
166
- readonly _tag: Schema.tag<"ExtraBadRequest">;
165
+ declare const ExtraBadRequest_base: Schema.Class<ExtraBadRequest, Schema.TaggedStruct<"ExtraBadRequest", {
167
166
  readonly message: Schema.String;
168
167
  }>, import("effect/Cause").YieldableError>;
169
168
  export declare class ExtraBadRequest extends ExtraBadRequest_base {
@@ -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({
@@ -283,8 +283,7 @@ export const ExtraUploadedAsset = Schema.Struct({
283
283
  },
284
284
  ],
285
285
  });
286
- export class ExtraBadRequest extends Schema.ErrorClass("ExtraBadRequest")({
287
- _tag: Schema.tag("ExtraBadRequest"),
286
+ export class ExtraBadRequest extends Schema.TaggedError()("ExtraBadRequest", {
288
287
  message: Schema.String,
289
288
  }, {
290
289
  identifier: "ExtraBadRequest",
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 { OrganizationSwitcher, MemberRequired, ProjectAccessMatrix, KrakstackAuthProvider, ForgotPassword, ResetPassword, Signin, TwoFactor, VerifyEmail, AdminOrganizationForm, AdminOrganizationsTable, AdminUsersTable, UserButton, assetUrl, createAuthUiClient, type AuthUiClient, type MemberRequiredMessages, type MemberRequiredProps, type ProjectAccessMatrixAccess, type ProjectAccessMatrixMessages, type ProjectAccessLabels, type ProjectAccessLabelCatalog, type KrakstackAuthContextValue, type KrakstackAuthLocale, type KrakstackAuthProviderProps, type OrganizationSwitcherDialog, type OrganizationSwitcherFeatures, type OrganizationSwitcherProps, type UserButtonDialog, type UserButtonProps, useAuthClient, useAdminUsersTotal, } from "./components";
9
- export * as BetterAuth from "./better-auth/api.group";
10
- export * as Extra from "./extra/api.group";
11
- export * as Server from "./server";
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 { OrganizationSwitcher, MemberRequired, ProjectAccessMatrix, KrakstackAuthProvider, ForgotPassword, ResetPassword, Signin, TwoFactor, VerifyEmail, AdminOrganizationForm, AdminOrganizationsTable, AdminUsersTable, UserButton, assetUrl, createAuthUiClient, useAuthClient, useAdminUsersTotal, } from "./components";
9
- export * as BetterAuth from "./better-auth/api.group";
10
- export * as Extra from "./extra/api.group";
11
- export * as Server from "./server";
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: <A>(items: Schema.Schema<A>) => Schema.Struct<{
42
- readonly data: Schema.$Array<Schema.Schema<A>>;
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/query.js CHANGED
@@ -1,4 +1,4 @@
1
- import { Effect, Option, Schema, SchemaIssue, SchemaTransformation, } from "effect";
1
+ import { Effect, Schema, SchemaIssue, SchemaTransformation } from "effect";
2
2
  const parseSortParam = (sort) => {
3
3
  const id = sort.startsWith("-") ? sort.slice(1) : sort;
4
4
  if (!id || id.includes(",") || id.includes(":")) {
@@ -28,9 +28,9 @@ export const SortParamFromString = Schema.String.pipe(Schema.decodeTo(SortParam,
28
28
  decode: (sort) => {
29
29
  const sortParam = parseSortParam(sort);
30
30
  if (!sortParam) {
31
- return Effect.fail(new SchemaIssue.InvalidValue(Option.some(sort), {
31
+ return Effect.fail(new SchemaIssue.InvalidValue({
32
32
  message: 'Expected sort in the format "field" or "-field"',
33
- }));
33
+ }, sort));
34
34
  }
35
35
  return Effect.succeed(sortParam);
36
36
  },
@@ -48,9 +48,9 @@ export const SortParamsFromString = Schema.String.pipe(Schema.decodeTo(Schema.Ar
48
48
  for (const part of parts) {
49
49
  const sortParam = parseSortParam(part);
50
50
  if (!sortParam) {
51
- return Effect.fail(new SchemaIssue.InvalidValue(Option.some(sort), {
51
+ return Effect.fail(new SchemaIssue.InvalidValue({
52
52
  message: 'Expected sort in the format "field,-otherField"',
53
- }));
53
+ }, sort));
54
54
  }
55
55
  sortParams.push(sortParam);
56
56
  }
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: unknown) => string[];
7
- export declare const hasAnyRole: (role: unknown, roles: readonly string[]) => boolean;
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: unknown) => OrganizationRole;
10
- export declare const normalizeOrganizationRoles: (role: unknown) => OrganizationRole[];
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) => typeof role === "string"
14
- ? role
15
- .split(",")
16
- .map((item) => item.trim())
17
- .filter(Boolean)
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.includes(role);
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: unknown) => OrganizationMetadata;
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 Better Auth browser session record.",
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 decodeOrganizationMetadataJson = Schema.decodeUnknownOption(Schema.fromJsonString(Schema.Unknown));
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 = typeof metadata === "string"
253
- ? Option.getOrNull(decodeOrganizationMetadataJson(metadata))
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 translations = Schema.decodeUnknownOption(Schema.Array(OrganizationTranslation))(Reflect.get(value, "translations"));
259
- const emails = Schema.decodeUnknownOption(Schema.Array(OrganizationEmail))(Reflect.get(value, "emails"));
260
- const phones = Schema.decodeUnknownOption(Schema.Array(OrganizationPhone))(Reflect.get(value, "phones"));
261
- const websites = Schema.decodeUnknownOption(Schema.Array(OrganizationWebsite))(Reflect.get(value, "websites"));
262
- const socials = Schema.decodeUnknownOption(Schema.Array(OrganizationSocial))(Reflect.get(value, "socials"));
263
- const addresses = Schema.decodeUnknownOption(Schema.Array(OrganizationAddress))(Reflect.get(value, "addresses"));
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),
@@ -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 const actorRequiredLayer: <Project extends string, Action extends string>(access: ProjectAccessDefinition<Project, Action>) => Layer.Layer<AnyActorRequired | ApiKeyActorRequired | OrganizationApiKeyActorRequired | UserActorRequired | UserApiKeyActorRequired, never, never>;
62
- type ActorRequiredFactory = {
63
- (): typeof AnyActorRequired;
64
- (constraint: {
65
- readonly type: "user";
66
- }): typeof UserActorRequired;
67
- (constraint: {
68
- readonly type: "apiKey";
69
- readonly ownerType: "user";
70
- }): typeof UserApiKeyActorRequired;
71
- (constraint: {
72
- readonly type: "apiKey";
73
- readonly ownerType: "organization";
74
- }): typeof OrganizationApiKeyActorRequired;
75
- (constraint: {
76
- readonly type: "apiKey";
77
- }): typeof ApiKeyActorRequired;
78
- readonly layer: typeof actorRequiredLayer;
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 {};
@@ -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 member = yield* auth.organizations
9
- .getActiveMember({ params: { organizationId, userId } })
8
+ const role = yield* auth
9
+ .getActiveMemberRole({ organizationId, userId })
10
10
  .pipe(Effect.mapError(() => new HttpApiError.Forbidden({})));
11
- return parseRoleList(member.role);
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
- ...(actor.organizationId
121
- ? { "organization.id": actor.organizationId }
122
- : {}),
123
- ...(userId ? { "user.id": userId } : {}),
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
- const actorRequired = (constraint) => {
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
- export const ActorRequired = Object.assign(actorRequired, {
144
- layer: actorRequiredLayer,
145
- });
142
+ ActorRequired.layer = actorRequiredLayer;