@krak-stack/auth 0.1.70 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -3
- package/dist/access.d.ts +4 -4
- package/dist/access.js +10 -4
- package/dist/admin/api.group.d.ts +17 -17
- package/dist/admin/api.group.js +2 -2
- package/dist/admin/schema.d.ts +18 -18
- package/dist/admin/schema.js +3 -3
- package/dist/api.d.ts +2093 -631
- package/dist/api.js +7 -7
- package/dist/auth/api.group.d.ts +793 -0
- package/dist/auth/api.group.js +241 -0
- package/dist/auth/schema.d.ts +800 -0
- package/dist/auth/schema.js +625 -0
- package/dist/components/admin-organization-form.d.ts +1 -1
- package/dist/components/admin-organization-form.js +16 -18
- package/dist/components/admin-organizations.js +52 -46
- package/dist/components/admin-users.js +115 -138
- package/dist/components/api-key-edit-form.d.ts +4 -3
- package/dist/components/api-key-edit-form.js +32 -27
- package/dist/components/api-key-permissions.d.ts +1 -1
- package/dist/components/api-key-rate-limit.d.ts +1 -1
- package/dist/components/api-key-referrers.d.ts +3 -2
- package/dist/components/api-key-referrers.js +2 -3
- package/dist/components/api-key.d.ts +0 -9
- package/dist/components/api-key.js +0 -39
- package/dist/components/auth-atoms.d.ts +178 -0
- package/dist/components/auth-atoms.js +46 -0
- package/dist/components/auth-client-api.d.ts +2474 -142
- package/dist/components/auth-client-api.js +14 -10
- package/dist/components/auth-forms.d.ts +1 -3
- package/dist/components/auth-forms.js +168 -195
- package/dist/components/auth-provider.d.ts +3 -7
- package/dist/components/auth-provider.js +56 -30
- package/dist/components/has-permission.js +1 -1
- package/dist/components/index.d.ts +19 -20
- package/dist/components/index.js +13 -13
- package/dist/components/member-required.d.ts +1 -3
- package/dist/components/member-required.js +102 -78
- package/dist/components/organization-switcher.d.ts +4 -6
- package/dist/components/organization-switcher.js +469 -324
- package/dist/components/project-access-matrix.d.ts +1 -1
- package/dist/components/project-access-matrix.js +9 -13
- package/dist/components/user-button.d.ts +5 -3
- package/dist/components/user-button.js +265 -316
- package/dist/components/utils.d.ts +3 -1
- package/dist/components/utils.js +4 -11
- package/dist/extra/api.group.d.ts +3 -3
- package/dist/extra/api.group.js +6 -6
- package/dist/extra/schema.js +1 -1
- package/dist/index.d.ts +11 -12
- package/dist/index.js +11 -12
- package/dist/query.d.ts +2 -2
- package/dist/roles.d.ts +5 -4
- package/dist/roles.js +11 -7
- package/dist/schema.d.ts +1 -1
- package/dist/schema.js +26 -19
- package/dist/server/actor.d.ts +30 -32
- package/dist/server/actor.js +39 -22
- package/dist/server/api.group.js +2 -2
- package/dist/server/index.d.ts +14 -14
- package/dist/server/index.js +8 -8
- package/dist/server/middleware.d.ts +3 -3
- package/dist/server/middleware.js +10 -5
- package/dist/server/schema.js +1 -1
- package/dist/service.d.ts +2053 -201
- package/dist/service.js +32 -21
- package/package.json +10 -9
- package/dist/better-auth/api.group.d.ts +0 -62
- package/dist/better-auth/api.group.js +0 -39
- package/dist/better-auth/schema.d.ts +0 -72
- package/dist/better-auth/schema.js +0 -110
- package/dist/components/auth-client.d.ts +0 -50
- package/dist/components/auth-client.js +0 -46
|
@@ -4,17 +4,18 @@ import { FormBuilder, FormReact } from "@lucas-barake/effect-form-react";
|
|
|
4
4
|
import { Effect, Schema } from "effect";
|
|
5
5
|
import { useRef, useState } from "react";
|
|
6
6
|
import { CheckboxField, SubmitButton, SubmitError, TextAreaField, TextField, } from "@krak-stack/registry/effect-form";
|
|
7
|
-
import { parseApiKeyReferrers
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
7
|
+
import { parseApiKeyReferrers } from "./api-key.js";
|
|
8
|
+
import { authHttpClient } from "./auth-client-api.js";
|
|
9
|
+
import { ApiKeyPermissions } from "./api-key-permissions.js";
|
|
10
|
+
import { apiKeyReferrers } from "./api-key-referrers.js";
|
|
11
|
+
import { ExtraApiKeyPermissions } from "../extra/schema.js";
|
|
11
12
|
const editApiKeyFormBuilder = FormBuilder.empty
|
|
12
13
|
.addField("name", Schema.NonEmptyString)
|
|
13
14
|
.addField("enabled", Schema.Boolean)
|
|
14
15
|
.addField("referrers", Schema.String)
|
|
15
16
|
.addField("permissions", Schema.Record(Schema.String, Schema.Boolean));
|
|
16
17
|
const ApiKeyPermissionsField = ({ field, props }) => (_jsx(ApiKeyPermissions, { description: props.description, idPrefix: props.idPrefix, permissions: props.permissions, labels: props.labels, selected: field.value, title: props.title, onChange: (id, checked) => field.onChange({ ...field.value, [id]: checked }) }));
|
|
17
|
-
export const ApiKeyEditForm = ({ configId, keyData, messages, permissions, permissionLabels, onSaved, }) => {
|
|
18
|
+
export const ApiKeyEditForm = ({ baseUrl, configId, keyData, messages, permissions, permissionLabels, onSaved, }) => {
|
|
18
19
|
const permissionOptions = Object.entries(permissions).flatMap(([project, actions]) => actions.map((action) => ({
|
|
19
20
|
id: `${project}:${action}`,
|
|
20
21
|
project,
|
|
@@ -38,33 +39,37 @@ export const ApiKeyEditForm = ({ configId, keyData, messages, permissions, permi
|
|
|
38
39
|
permissions: ApiKeyPermissionsField,
|
|
39
40
|
},
|
|
40
41
|
mode: { validation: "onSubmit" },
|
|
41
|
-
onSubmit: (_, { decoded }) => Effect.
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
]
|
|
55
|
-
|
|
56
|
-
|
|
42
|
+
onSubmit: (_, { decoded }) => Effect.gen(function* () {
|
|
43
|
+
const referrers = yield* Effect.try({
|
|
44
|
+
try: () => parseApiKeyReferrers(decoded.referrers, messages.referrersError),
|
|
45
|
+
catch: (cause) => cause instanceof Error ? cause : new Error(messages.updateError),
|
|
46
|
+
});
|
|
47
|
+
const selectedGrant = {};
|
|
48
|
+
for (const project of Object.keys(permissionsRef.current)) {
|
|
49
|
+
selectedGrant[project] = [];
|
|
50
|
+
}
|
|
51
|
+
for (const option of permissionOptionsRef.current) {
|
|
52
|
+
if (!decoded.permissions[option.id])
|
|
53
|
+
continue;
|
|
54
|
+
selectedGrant[option.project] = [
|
|
55
|
+
...(selectedGrant[option.project] ?? []),
|
|
56
|
+
option.action,
|
|
57
|
+
];
|
|
58
|
+
}
|
|
59
|
+
const client = yield* authHttpClient(baseUrl);
|
|
60
|
+
const updated = yield* client.authExtra.updateApiKey({
|
|
61
|
+
params: { keyId: keyData.id },
|
|
62
|
+
payload: {
|
|
57
63
|
configId,
|
|
58
|
-
keyId: keyData.id,
|
|
59
64
|
name: decoded.name.trim(),
|
|
60
65
|
enabled: decoded.enabled,
|
|
61
66
|
permissions: selectedGrant,
|
|
62
67
|
referrers,
|
|
63
|
-
},
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}),
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
yield* Effect.sync(onSaved);
|
|
71
|
+
return updated;
|
|
72
|
+
}).pipe(Effect.mapError((cause) => cause instanceof Error ? cause : new Error(messages.updateError))),
|
|
68
73
|
}));
|
|
69
74
|
const submit = useAtomSet(form.submit);
|
|
70
75
|
const submitResult = useAtomValue(form.submit);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ProjectAccessLabelCatalog } from "../access";
|
|
1
|
+
import type { ProjectAccessLabelCatalog } from "../access.js";
|
|
2
2
|
export declare const ApiKeyPermissions: ({ description, idPrefix, permissions, labels, selected, title, onChange, }: {
|
|
3
3
|
description: string;
|
|
4
4
|
idPrefix: string;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
export declare const
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
export declare const apiKeyReferrers: (metadata: typeof Schema.Unknown.Type) => never[] | readonly string[];
|
|
3
|
+
export declare const withApiKeyReferrers: (metadata: typeof Schema.Unknown.Type, referrers: ReadonlyArray<string>) => {
|
|
3
4
|
allowedOrigins: string[];
|
|
4
5
|
};
|
|
5
6
|
export declare const ApiKeyReferrers: ({ metadata, unrestrictedLabel, }: {
|
|
@@ -3,11 +3,10 @@ import { Option, Schema } from "effect";
|
|
|
3
3
|
import { Badge } from "@/components/ui/badge";
|
|
4
4
|
const Metadata = Schema.Record(Schema.String, Schema.Unknown);
|
|
5
5
|
const MetadataJson = Schema.fromJsonString(Metadata);
|
|
6
|
+
const MetadataInput = Schema.Union([Metadata, MetadataJson]);
|
|
6
7
|
const Referrers = Schema.Array(Schema.String);
|
|
7
8
|
const apiKeyMetadata = (metadata) => {
|
|
8
|
-
const decodedMetadata =
|
|
9
|
-
? Schema.decodeUnknownOption(MetadataJson)(metadata)
|
|
10
|
-
: Schema.decodeUnknownOption(Metadata)(metadata);
|
|
9
|
+
const decodedMetadata = Schema.decodeUnknownOption(MetadataInput)(metadata);
|
|
11
10
|
return Option.getOrElse(decodedMetadata, () => ({}));
|
|
12
11
|
};
|
|
13
12
|
export const apiKeyReferrers = (metadata) => Option.getOrElse(Schema.decodeUnknownOption(Referrers)(apiKeyMetadata(metadata).allowedOrigins), () => []);
|
|
@@ -1,10 +1 @@
|
|
|
1
|
-
import { Schema } from "effect";
|
|
2
|
-
import { ExtraCreateApiKeyPayload, ExtraCreateApiKeyResponse, ExtraUpdateApiKeyPayload } from "../extra/schema";
|
|
3
|
-
export type CreateApiKeyPayload = typeof ExtraCreateApiKeyPayload.Type;
|
|
4
|
-
export type CreatedApiKey = typeof ExtraCreateApiKeyResponse.Type;
|
|
5
|
-
export type UpdateApiKeyPayload = typeof ExtraUpdateApiKeyPayload.Type;
|
|
6
1
|
export declare const parseApiKeyReferrers: (value: string, errorMessage: string) => string[];
|
|
7
|
-
export declare const createApiKey: (payload: CreateApiKeyPayload, fallbackError: string) => Promise<CreatedApiKey>;
|
|
8
|
-
export declare const updateApiKey: (payload: UpdateApiKeyPayload, fallbackError: string) => Promise<Schema.Struct.ReadonlySide<{
|
|
9
|
-
readonly ok: Schema.Boolean;
|
|
10
|
-
}, "Type">>;
|
|
@@ -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<import("effect/Schema").Struct.ReadonlySide<{
|
|
4
|
+
readonly session: import("effect/Schema").Struct<{
|
|
5
|
+
readonly id: import("effect/Schema").String;
|
|
6
|
+
readonly expiresAt: import("effect/Schema").DateFromString;
|
|
7
|
+
readonly token: import("effect/Schema").String;
|
|
8
|
+
readonly createdAt: import("effect/Schema").DateFromString;
|
|
9
|
+
readonly updatedAt: import("effect/Schema").DateFromString;
|
|
10
|
+
readonly ipAddress: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
11
|
+
readonly userAgent: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
12
|
+
readonly userId: import("effect/Schema").String;
|
|
13
|
+
readonly impersonatedBy: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
14
|
+
readonly impersonatedByOrganizationId: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
15
|
+
readonly activeOrganizationId: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
16
|
+
}>;
|
|
17
|
+
readonly user: import("effect/Schema").Struct<{
|
|
18
|
+
readonly id: import("effect/Schema").String;
|
|
19
|
+
readonly name: import("effect/Schema").String;
|
|
20
|
+
readonly email: import("effect/Schema").String;
|
|
21
|
+
readonly emailVerified: import("effect/Schema").Boolean;
|
|
22
|
+
readonly image: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
23
|
+
readonly role: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
24
|
+
readonly banned: import("effect/Schema").NullOr<import("effect/Schema").Boolean>;
|
|
25
|
+
readonly banReason: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
26
|
+
readonly banExpires: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").DateFromString>>;
|
|
27
|
+
readonly twoFactorEnabled: import("effect/Schema").optional<import("effect/Schema").Boolean>;
|
|
28
|
+
readonly lastLoginMethod: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
29
|
+
readonly createdAt: import("effect/Schema").DateFromString;
|
|
30
|
+
readonly updatedAt: import("effect/Schema").DateFromString;
|
|
31
|
+
}>;
|
|
32
|
+
}, "Type"> | null, import("../auth/schema.js").AuthBadRequest>, Atom.Atom<import("effect/unstable/reactivity/AsyncResult").AsyncResult<import("effect/unstable/reactivity/AsyncResult").AsyncResult<import("effect/Schema").Struct.ReadonlySide<{
|
|
33
|
+
readonly session: import("effect/Schema").Struct<{
|
|
34
|
+
readonly id: import("effect/Schema").String;
|
|
35
|
+
readonly expiresAt: import("effect/Schema").DateFromString;
|
|
36
|
+
readonly token: import("effect/Schema").String;
|
|
37
|
+
readonly createdAt: import("effect/Schema").DateFromString;
|
|
38
|
+
readonly updatedAt: import("effect/Schema").DateFromString;
|
|
39
|
+
readonly ipAddress: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
40
|
+
readonly userAgent: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
41
|
+
readonly userId: import("effect/Schema").String;
|
|
42
|
+
readonly impersonatedBy: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
43
|
+
readonly impersonatedByOrganizationId: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
44
|
+
readonly activeOrganizationId: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
45
|
+
}>;
|
|
46
|
+
readonly user: import("effect/Schema").Struct<{
|
|
47
|
+
readonly id: import("effect/Schema").String;
|
|
48
|
+
readonly name: import("effect/Schema").String;
|
|
49
|
+
readonly email: import("effect/Schema").String;
|
|
50
|
+
readonly emailVerified: import("effect/Schema").Boolean;
|
|
51
|
+
readonly image: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
52
|
+
readonly role: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
53
|
+
readonly banned: import("effect/Schema").NullOr<import("effect/Schema").Boolean>;
|
|
54
|
+
readonly banReason: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
55
|
+
readonly banExpires: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").DateFromString>>;
|
|
56
|
+
readonly twoFactorEnabled: import("effect/Schema").optional<import("effect/Schema").Boolean>;
|
|
57
|
+
readonly lastLoginMethod: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
58
|
+
readonly createdAt: import("effect/Schema").DateFromString;
|
|
59
|
+
readonly updatedAt: import("effect/Schema").DateFromString;
|
|
60
|
+
}>;
|
|
61
|
+
}, "Type"> | 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 import("effect/Schema").Struct.ReadonlySide<{
|
|
97
|
+
readonly id: import("effect/Schema").String;
|
|
98
|
+
readonly organizationId: import("effect/Schema").String;
|
|
99
|
+
readonly userId: import("effect/Schema").String;
|
|
100
|
+
readonly role: import("effect/Schema").String;
|
|
101
|
+
readonly createdAt: import("effect/Schema").DateFromString;
|
|
102
|
+
readonly user: import("effect/Schema").Struct<{
|
|
103
|
+
readonly id: import("effect/Schema").String;
|
|
104
|
+
readonly name: import("effect/Schema").String;
|
|
105
|
+
readonly email: import("effect/Schema").String;
|
|
106
|
+
readonly emailVerified: import("effect/Schema").Boolean;
|
|
107
|
+
readonly image: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
108
|
+
readonly role: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
109
|
+
readonly banned: import("effect/Schema").NullOr<import("effect/Schema").Boolean>;
|
|
110
|
+
readonly banReason: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
111
|
+
readonly banExpires: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").DateFromString>>;
|
|
112
|
+
readonly twoFactorEnabled: import("effect/Schema").optional<import("effect/Schema").Boolean>;
|
|
113
|
+
readonly lastLoginMethod: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
114
|
+
readonly createdAt: import("effect/Schema").DateFromString;
|
|
115
|
+
readonly updatedAt: import("effect/Schema").DateFromString;
|
|
116
|
+
}>;
|
|
117
|
+
}, "Type">[];
|
|
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 import("effect/Schema").Struct.ReadonlySide<{
|
|
142
|
+
readonly id: import("effect/Schema").String;
|
|
143
|
+
readonly organizationId: import("effect/Schema").String;
|
|
144
|
+
readonly userId: import("effect/Schema").String;
|
|
145
|
+
readonly role: import("effect/Schema").String;
|
|
146
|
+
readonly createdAt: import("effect/Schema").DateFromString;
|
|
147
|
+
readonly user: import("effect/Schema").Struct<{
|
|
148
|
+
readonly id: import("effect/Schema").String;
|
|
149
|
+
readonly name: import("effect/Schema").String;
|
|
150
|
+
readonly email: import("effect/Schema").String;
|
|
151
|
+
readonly emailVerified: import("effect/Schema").Boolean;
|
|
152
|
+
readonly image: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
153
|
+
readonly role: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
154
|
+
readonly banned: import("effect/Schema").NullOr<import("effect/Schema").Boolean>;
|
|
155
|
+
readonly banReason: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
156
|
+
readonly banExpires: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").DateFromString>>;
|
|
157
|
+
readonly twoFactorEnabled: import("effect/Schema").optional<import("effect/Schema").Boolean>;
|
|
158
|
+
readonly lastLoginMethod: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
159
|
+
readonly createdAt: import("effect/Schema").DateFromString;
|
|
160
|
+
readonly updatedAt: import("effect/Schema").DateFromString;
|
|
161
|
+
}>;
|
|
162
|
+
}, "Type">[];
|
|
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;
|