@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,5 +1,4 @@
1
1
  import { Option, Schema } from "effect";
2
- import { ExtraCreateApiKeyPayload, ExtraCreateApiKeyResponse, ExtraOkResponse, ExtraUpdateApiKeyPayload, } from "../extra/schema";
3
2
  const decodeUrl = Schema.decodeUnknownOption(Schema.URLFromString);
4
3
  export const parseApiKeyReferrers = (value, errorMessage) => {
5
4
  const referrers = value
@@ -19,41 +18,3 @@ export const parseApiKeyReferrers = (value, errorMessage) => {
19
18
  });
20
19
  return Array.from(new Set(referrers));
21
20
  };
22
- const ErrorResponse = Schema.Struct({ message: Schema.String });
23
- const errorMessage = async (value, fallback) => Schema.decodeUnknownPromise(ErrorResponse)(value)
24
- .then((error) => error.message)
25
- .catch(() => fallback);
26
- export const createApiKey = async (payload, fallbackError) => {
27
- const body = await Schema.decodeUnknownPromise(ExtraCreateApiKeyPayload)(payload);
28
- const response = await fetch("/api/auth/create-api-key", {
29
- method: "POST",
30
- credentials: "include",
31
- headers: { "Content-Type": "application/json" },
32
- body: JSON.stringify(body),
33
- });
34
- const data = await response.json().catch(() => null);
35
- if (!response.ok) {
36
- throw new Error(await errorMessage(data, fallbackError));
37
- }
38
- return await Schema.decodeUnknownPromise(ExtraCreateApiKeyResponse)(data);
39
- };
40
- export const updateApiKey = async (payload, fallbackError) => {
41
- const decoded = await Schema.decodeUnknownPromise(ExtraUpdateApiKeyPayload)(payload);
42
- const response = await fetch(`/api/auth/api-key/${encodeURIComponent(decoded.keyId)}`, {
43
- method: "PATCH",
44
- credentials: "include",
45
- headers: { "Content-Type": "application/json" },
46
- body: JSON.stringify({
47
- configId: decoded.configId,
48
- name: decoded.name,
49
- enabled: decoded.enabled,
50
- permissions: decoded.permissions,
51
- referrers: decoded.referrers,
52
- }),
53
- });
54
- const data = await response.json().catch(() => null);
55
- if (!response.ok) {
56
- throw new Error(await errorMessage(data, fallbackError));
57
- }
58
- return await Schema.decodeUnknownPromise(ExtraOkResponse)(data);
59
- };
@@ -0,0 +1,178 @@
1
+ import { Atom } from "effect/unstable/reactivity";
2
+ export declare const AUTH_CLIENT_CHANGE_EVENT = "krakstack-auth:change";
3
+ export declare const authSessionAtom: (arg: string | undefined) => Atom.Writable<import("effect/unstable/reactivity/AsyncResult").AsyncResult<{
4
+ readonly session: {
5
+ readonly id: string;
6
+ readonly expiresAt: Date;
7
+ readonly token: string;
8
+ readonly createdAt: Date;
9
+ readonly updatedAt: Date;
10
+ readonly ipAddress?: string | null | undefined;
11
+ readonly userAgent?: string | null | undefined;
12
+ readonly userId: string;
13
+ readonly impersonatedBy?: string | null | undefined;
14
+ readonly impersonatedByOrganizationId?: string | null | undefined;
15
+ readonly activeOrganizationId?: string | null | undefined;
16
+ };
17
+ readonly user: {
18
+ readonly id: string;
19
+ readonly name: string;
20
+ readonly email: string;
21
+ readonly emailVerified: boolean;
22
+ readonly image: string | null;
23
+ readonly role: string | null;
24
+ readonly banned: boolean | null;
25
+ readonly banReason?: string | null | undefined;
26
+ readonly banExpires?: Date | null | undefined;
27
+ readonly twoFactorEnabled?: boolean | undefined;
28
+ readonly lastLoginMethod?: string | null | undefined;
29
+ readonly createdAt: Date;
30
+ readonly updatedAt: Date;
31
+ };
32
+ } | null, import("../auth/schema.js").AuthBadRequest>, Atom.Atom<import("effect/unstable/reactivity/AsyncResult").AsyncResult<import("effect/unstable/reactivity/AsyncResult").AsyncResult<{
33
+ readonly session: {
34
+ readonly id: string;
35
+ readonly expiresAt: Date;
36
+ readonly token: string;
37
+ readonly createdAt: Date;
38
+ readonly updatedAt: Date;
39
+ readonly ipAddress?: string | null | undefined;
40
+ readonly userAgent?: string | null | undefined;
41
+ readonly userId: string;
42
+ readonly impersonatedBy?: string | null | undefined;
43
+ readonly impersonatedByOrganizationId?: string | null | undefined;
44
+ readonly activeOrganizationId?: string | null | undefined;
45
+ };
46
+ readonly user: {
47
+ readonly id: string;
48
+ readonly name: string;
49
+ readonly email: string;
50
+ readonly emailVerified: boolean;
51
+ readonly image: string | null;
52
+ readonly role: string | null;
53
+ readonly banned: boolean | null;
54
+ readonly banReason?: string | null | undefined;
55
+ readonly banExpires?: Date | null | undefined;
56
+ readonly twoFactorEnabled?: boolean | undefined;
57
+ readonly lastLoginMethod?: string | null | undefined;
58
+ readonly createdAt: Date;
59
+ readonly updatedAt: Date;
60
+ };
61
+ } | null, import("../auth/schema.js").AuthBadRequest>, unknown>>>;
62
+ export declare const authOrganizationsAtom: (arg: string | undefined) => Atom.Writable<import("effect/unstable/reactivity/AsyncResult").AsyncResult<readonly {
63
+ readonly id: string;
64
+ readonly name: string;
65
+ readonly slug: string;
66
+ readonly logo?: string | null | undefined;
67
+ readonly metadata?: string | {
68
+ readonly [x: string]: import("effect/Schema").Json;
69
+ } | null | undefined;
70
+ readonly userId?: string | null | undefined;
71
+ readonly parentId?: string | null | undefined;
72
+ readonly createdAt: Date;
73
+ }[], import("../auth/schema.js").AuthBadRequest>, Atom.Atom<import("effect/unstable/reactivity/AsyncResult").AsyncResult<import("effect/unstable/reactivity/AsyncResult").AsyncResult<readonly {
74
+ readonly id: string;
75
+ readonly name: string;
76
+ readonly slug: string;
77
+ readonly logo?: string | null | undefined;
78
+ readonly metadata?: string | {
79
+ readonly [x: string]: import("effect/Schema").Json;
80
+ } | null | undefined;
81
+ readonly userId?: string | null | undefined;
82
+ readonly parentId?: string | null | undefined;
83
+ readonly createdAt: Date;
84
+ }[], import("../auth/schema.js").AuthBadRequest>, unknown>>>;
85
+ export declare const activeAuthOrganizationAtom: (arg: string | undefined) => (arg: string | null) => Atom.Writable<import("effect/unstable/reactivity/AsyncResult").AsyncResult<{
86
+ readonly id: string;
87
+ readonly name: string;
88
+ readonly slug: string;
89
+ readonly logo?: string | null | undefined;
90
+ readonly metadata?: string | {
91
+ readonly [x: string]: import("effect/Schema").Json;
92
+ } | null | undefined;
93
+ readonly userId?: string | null | undefined;
94
+ readonly parentId?: string | null | undefined;
95
+ readonly createdAt: Date;
96
+ readonly members: readonly {
97
+ readonly id: string;
98
+ readonly organizationId: string;
99
+ readonly userId: string;
100
+ readonly role: string;
101
+ readonly createdAt: Date;
102
+ readonly user: {
103
+ readonly id: string;
104
+ readonly name: string;
105
+ readonly email: string;
106
+ readonly emailVerified: boolean;
107
+ readonly image: string | null;
108
+ readonly role: string | null;
109
+ readonly banned: boolean | null;
110
+ readonly banReason?: string | null | undefined;
111
+ readonly banExpires?: Date | null | undefined;
112
+ readonly twoFactorEnabled?: boolean | undefined;
113
+ readonly lastLoginMethod?: string | null | undefined;
114
+ readonly createdAt: Date;
115
+ readonly updatedAt: Date;
116
+ };
117
+ }[];
118
+ readonly invitations: readonly {
119
+ readonly id: string;
120
+ readonly email: string;
121
+ readonly role: string;
122
+ readonly organizationId: string;
123
+ readonly organizationName?: string | null | undefined;
124
+ readonly inviterId: string;
125
+ readonly teamId?: string | null | undefined;
126
+ readonly status: string;
127
+ readonly expiresAt: Date;
128
+ readonly createdAt?: Date | undefined;
129
+ }[];
130
+ } | null, import("../auth/schema.js").AuthBadRequest>, Atom.Atom<import("effect/unstable/reactivity/AsyncResult").AsyncResult<import("effect/unstable/reactivity/AsyncResult").AsyncResult<{
131
+ readonly id: string;
132
+ readonly name: string;
133
+ readonly slug: string;
134
+ readonly logo?: string | null | undefined;
135
+ readonly metadata?: string | {
136
+ readonly [x: string]: import("effect/Schema").Json;
137
+ } | null | undefined;
138
+ readonly userId?: string | null | undefined;
139
+ readonly parentId?: string | null | undefined;
140
+ readonly createdAt: Date;
141
+ readonly members: readonly {
142
+ readonly id: string;
143
+ readonly organizationId: string;
144
+ readonly userId: string;
145
+ readonly role: string;
146
+ readonly createdAt: Date;
147
+ readonly user: {
148
+ readonly id: string;
149
+ readonly name: string;
150
+ readonly email: string;
151
+ readonly emailVerified: boolean;
152
+ readonly image: string | null;
153
+ readonly role: string | null;
154
+ readonly banned: boolean | null;
155
+ readonly banReason?: string | null | undefined;
156
+ readonly banExpires?: Date | null | undefined;
157
+ readonly twoFactorEnabled?: boolean | undefined;
158
+ readonly lastLoginMethod?: string | null | undefined;
159
+ readonly createdAt: Date;
160
+ readonly updatedAt: Date;
161
+ };
162
+ }[];
163
+ readonly invitations: readonly {
164
+ readonly id: string;
165
+ readonly email: string;
166
+ readonly role: string;
167
+ readonly organizationId: string;
168
+ readonly organizationName?: string | null | undefined;
169
+ readonly inviterId: string;
170
+ readonly teamId?: string | null | undefined;
171
+ readonly status: string;
172
+ readonly expiresAt: Date;
173
+ readonly createdAt?: Date | undefined;
174
+ }[];
175
+ } | null, import("../auth/schema.js").AuthBadRequest>, unknown>>>;
176
+ export declare const getLastUsedLoginMethod: () => string | null;
177
+ export declare const notifyAuthChange: () => void;
178
+ export declare const isAuthClientStorageEvent: (event: StorageEvent) => boolean;
@@ -0,0 +1,46 @@
1
+ import { Atom } from "effect/unstable/reactivity";
2
+ import { authClientApi } from "./auth-client-api.js";
3
+ const LAST_LOGIN_METHOD_COOKIE = "krakstack-auth.last_used_login_method";
4
+ export const AUTH_CLIENT_CHANGE_EVENT = "krakstack-auth:change";
5
+ const AUTH_CLIENT_CHANGE_STORAGE_KEY = "krakstack-auth.change";
6
+ export const authSessionAtom = Atom.family((baseUrl) => Atom.optimistic(authClientApi(baseUrl).query("auth", "getSession", {
7
+ query: {},
8
+ timeToLive: "1 minute",
9
+ reactivityKeys: ["auth-session"],
10
+ })));
11
+ export const authOrganizationsAtom = Atom.family((baseUrl) => Atom.optimistic(authClientApi(baseUrl).query("auth", "organizationList", {
12
+ timeToLive: "1 minute",
13
+ reactivityKeys: ["auth-organizations"],
14
+ })));
15
+ export const activeAuthOrganizationAtom = Atom.family((baseUrl) => Atom.family((organizationId) => Atom.optimistic(authClientApi(baseUrl).query("auth", "organizationGetFull", {
16
+ query: organizationId ? { organizationId } : {},
17
+ timeToLive: "1 minute",
18
+ reactivityKeys: ["auth-active-organization", organizationId ?? "none"],
19
+ }))));
20
+ export const getLastUsedLoginMethod = () => {
21
+ const cookies = globalThis.document?.cookie;
22
+ if (!cookies)
23
+ return null;
24
+ for (const cookie of cookies.split(";")) {
25
+ const [name, ...parts] = cookie.trim().split("=");
26
+ if (name !== LAST_LOGIN_METHOD_COOKIE)
27
+ continue;
28
+ try {
29
+ return decodeURIComponent(parts.join("=")) || null;
30
+ }
31
+ catch {
32
+ return parts.join("=") || null;
33
+ }
34
+ }
35
+ return null;
36
+ };
37
+ export const notifyAuthChange = () => {
38
+ globalThis.window?.dispatchEvent(new Event(AUTH_CLIENT_CHANGE_EVENT));
39
+ try {
40
+ globalThis.localStorage?.setItem(AUTH_CLIENT_CHANGE_STORAGE_KEY, String(Date.now()));
41
+ }
42
+ catch {
43
+ // Storage may be unavailable in privacy-restricted browser contexts.
44
+ }
45
+ };
46
+ export const isAuthClientStorageEvent = (event) => event.key === AUTH_CLIENT_CHANGE_STORAGE_KEY;