@absolutejs/auth 0.32.0 → 0.34.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/dist/client/solid.d.ts +63 -0
- package/dist/client/solid.js +73 -0
- package/dist/client/solid.js.map +10 -0
- package/dist/client/svelte.d.ts +63 -0
- package/dist/client/svelte.js +61 -0
- package/dist/client/svelte.js.map +10 -0
- package/dist/client/vue.d.ts +63 -0
- package/dist/client/vue.js +73 -0
- package/dist/client/vue.js.map +10 -0
- package/dist/fga/config.d.ts +3 -3
- package/dist/fga/redisCheckCache.d.ts +11 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +26 -2
- package/dist/index.js.map +6 -5
- package/package.json +31 -4
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { type Accessor } from 'solid-js';
|
|
2
|
+
import type { AuthClient, AuthClientError } from './createAuthClient';
|
|
3
|
+
type Mutator<Args, Data> = (args: Args) => Promise<{
|
|
4
|
+
data: Data | null;
|
|
5
|
+
error: AuthClientError | null;
|
|
6
|
+
}>;
|
|
7
|
+
type MutationState<Args, Data> = {
|
|
8
|
+
data: Accessor<Data | null>;
|
|
9
|
+
error: Accessor<AuthClientError | null>;
|
|
10
|
+
isPending: Accessor<boolean>;
|
|
11
|
+
mutate: Mutator<Args, Data>;
|
|
12
|
+
reset: () => void;
|
|
13
|
+
};
|
|
14
|
+
export declare const useMagicLink: (client: AuthClient) => MutationState<{
|
|
15
|
+
email: string;
|
|
16
|
+
}, {
|
|
17
|
+
ok: true;
|
|
18
|
+
}>;
|
|
19
|
+
export declare const useMfaChallenge: (client: AuthClient) => MutationState<{
|
|
20
|
+
code: string;
|
|
21
|
+
}, {
|
|
22
|
+
status: "authenticated";
|
|
23
|
+
}>;
|
|
24
|
+
export declare const usePasswordReset: (client: AuthClient) => MutationState<{
|
|
25
|
+
email: string;
|
|
26
|
+
}, {
|
|
27
|
+
ok: true;
|
|
28
|
+
}>;
|
|
29
|
+
export declare const useSessions: (client: AuthClient) => {
|
|
30
|
+
data: Accessor<unknown[] | null>;
|
|
31
|
+
error: Accessor<AuthClientError | null>;
|
|
32
|
+
isPending: Accessor<boolean>;
|
|
33
|
+
refetch: () => Promise<void>;
|
|
34
|
+
revoke: (sessionId: string) => Promise<{
|
|
35
|
+
data: null;
|
|
36
|
+
error: AuthClientError;
|
|
37
|
+
} | {
|
|
38
|
+
data: {
|
|
39
|
+
ok: true;
|
|
40
|
+
};
|
|
41
|
+
error: null;
|
|
42
|
+
}>;
|
|
43
|
+
};
|
|
44
|
+
export declare const useSignIn: (client: AuthClient) => MutationState<{
|
|
45
|
+
email: string;
|
|
46
|
+
password: string;
|
|
47
|
+
}, {
|
|
48
|
+
passwordCompromised?: boolean;
|
|
49
|
+
status: "authenticated" | "mfa_required";
|
|
50
|
+
}>;
|
|
51
|
+
export declare const useSignOut: (client: AuthClient) => MutationState<unknown, {
|
|
52
|
+
ok: true;
|
|
53
|
+
}>;
|
|
54
|
+
export declare const useSignUp: (client: AuthClient) => MutationState<{
|
|
55
|
+
[extra: string]: unknown;
|
|
56
|
+
email: string;
|
|
57
|
+
password: string;
|
|
58
|
+
}, {
|
|
59
|
+
status: "authenticated";
|
|
60
|
+
} | {
|
|
61
|
+
status: "verification_required";
|
|
62
|
+
}>;
|
|
63
|
+
export {};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// src/client/solid.ts
|
|
3
|
+
import { createSignal, onCleanup } from "solid-js";
|
|
4
|
+
var useMutation = (run) => {
|
|
5
|
+
const [data, setData] = createSignal(null);
|
|
6
|
+
const [error, setError] = createSignal(null);
|
|
7
|
+
const [isPending, setIsPending] = createSignal(false);
|
|
8
|
+
let alive = true;
|
|
9
|
+
onCleanup(() => {
|
|
10
|
+
alive = false;
|
|
11
|
+
});
|
|
12
|
+
const mutate = async (args) => {
|
|
13
|
+
setIsPending(true);
|
|
14
|
+
setError(null);
|
|
15
|
+
const result = await run(args);
|
|
16
|
+
if (alive) {
|
|
17
|
+
setData(() => result.data);
|
|
18
|
+
setError(result.error);
|
|
19
|
+
setIsPending(false);
|
|
20
|
+
}
|
|
21
|
+
return result;
|
|
22
|
+
};
|
|
23
|
+
const reset = () => {
|
|
24
|
+
setData(() => null);
|
|
25
|
+
setError(null);
|
|
26
|
+
setIsPending(false);
|
|
27
|
+
};
|
|
28
|
+
return { data, error, isPending, mutate, reset };
|
|
29
|
+
};
|
|
30
|
+
var useMagicLink = (client) => useMutation(client.passwordless.requestMagicLink);
|
|
31
|
+
var useMfaChallenge = (client) => useMutation(client.mfa.challenge);
|
|
32
|
+
var usePasswordReset = (client) => useMutation(client.passwordReset.request);
|
|
33
|
+
var useSessions = (client) => {
|
|
34
|
+
const [data, setData] = createSignal(null);
|
|
35
|
+
const [error, setError] = createSignal(null);
|
|
36
|
+
const [isPending, setIsPending] = createSignal(true);
|
|
37
|
+
let alive = true;
|
|
38
|
+
onCleanup(() => {
|
|
39
|
+
alive = false;
|
|
40
|
+
});
|
|
41
|
+
const refetch = async () => {
|
|
42
|
+
setIsPending(true);
|
|
43
|
+
const result = await client.sessions.list();
|
|
44
|
+
if (alive) {
|
|
45
|
+
setData(() => result.data);
|
|
46
|
+
setError(result.error);
|
|
47
|
+
setIsPending(false);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
const revoke = async (sessionId) => {
|
|
51
|
+
const result = await client.sessions.revoke(sessionId);
|
|
52
|
+
if (result.error === null)
|
|
53
|
+
await refetch();
|
|
54
|
+
return result;
|
|
55
|
+
};
|
|
56
|
+
refetch();
|
|
57
|
+
return { data, error, isPending, refetch, revoke };
|
|
58
|
+
};
|
|
59
|
+
var useSignIn = (client) => useMutation(client.signIn.email);
|
|
60
|
+
var useSignOut = (client) => useMutation(client.signOut);
|
|
61
|
+
var useSignUp = (client) => useMutation(client.signUp.email);
|
|
62
|
+
export {
|
|
63
|
+
useSignUp,
|
|
64
|
+
useSignOut,
|
|
65
|
+
useSignIn,
|
|
66
|
+
useSessions,
|
|
67
|
+
usePasswordReset,
|
|
68
|
+
useMfaChallenge,
|
|
69
|
+
useMagicLink
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
//# debugId=C75839665B18FF0264756E2164756E21
|
|
73
|
+
//# sourceMappingURL=solid.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/client/solid.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"// Thin Solid composables over `createAuthClient`, mirroring `./react`. Same `{ data, error,\n// isPending, mutate, reset }` shape — only the reactivity is Solid's (signals + onCleanup).\n// Bring your own form / UI; these are primitives.\n\nimport { createSignal, onCleanup, type Accessor } from 'solid-js';\nimport type { AuthClient, AuthClientError } from './createAuthClient';\n\ntype Mutator<Args, Data> = (\n\targs: Args\n) => Promise<{ data: Data | null; error: AuthClientError | null }>;\n\ntype MutationState<Args, Data> = {\n\tdata: Accessor<Data | null>;\n\terror: Accessor<AuthClientError | null>;\n\tisPending: Accessor<boolean>;\n\tmutate: Mutator<Args, Data>;\n\treset: () => void;\n};\n\n// Generic mutation composable. The exported composables are 1-2 line specializations of\n// this — kept private so consumers depend on the named API, not this internal shape.\nconst useMutation = <Args, Data>(\n\trun: Mutator<Args, Data>\n): MutationState<Args, Data> => {\n\tconst [data, setData] = createSignal<Data | null>(null);\n\tconst [error, setError] = createSignal<AuthClientError | null>(null);\n\tconst [isPending, setIsPending] = createSignal(false);\n\tlet alive = true;\n\tonCleanup(() => {\n\t\talive = false;\n\t});\n\n\tconst mutate: Mutator<Args, Data> = async (args) => {\n\t\tsetIsPending(true);\n\t\tsetError(null);\n\t\tconst result = await run(args);\n\t\tif (alive) {\n\t\t\t// Solid's setter accepts a value or a setter-fn; the fn-form keeps Data | null\n\t\t\t// passing through without narrowing the writable signal's value type.\n\t\t\tsetData(() => result.data);\n\t\t\tsetError(result.error);\n\t\t\tsetIsPending(false);\n\t\t}\n\n\t\treturn result;\n\t};\n\n\tconst reset = () => {\n\t\tsetData(() => null);\n\t\tsetError(null);\n\t\tsetIsPending(false);\n\t};\n\n\treturn { data, error, isPending, mutate, reset };\n};\n\nexport const useMagicLink = (client: AuthClient) =>\n\tuseMutation(client.passwordless.requestMagicLink);\n\nexport const useMfaChallenge = (client: AuthClient) =>\n\tuseMutation(client.mfa.challenge);\n\nexport const usePasswordReset = (client: AuthClient) =>\n\tuseMutation(client.passwordReset.request);\n\n// Query composable for the user's active sessions; refetch() reruns it, revoke(sessionId)\n// kills one and refetches. Same `{ data, error, isPending }` triplet as the mutations so\n// the consumer can render one way.\nexport const useSessions = (client: AuthClient) => {\n\tconst [data, setData] = createSignal<unknown[] | null>(null);\n\tconst [error, setError] = createSignal<AuthClientError | null>(null);\n\tconst [isPending, setIsPending] = createSignal(true);\n\tlet alive = true;\n\tonCleanup(() => {\n\t\talive = false;\n\t});\n\n\tconst refetch = async () => {\n\t\tsetIsPending(true);\n\t\tconst result = await client.sessions.list();\n\t\tif (alive) {\n\t\t\tsetData(() => result.data);\n\t\t\tsetError(result.error);\n\t\t\tsetIsPending(false);\n\t\t}\n\t};\n\n\tconst revoke = async (sessionId: string) => {\n\t\tconst result = await client.sessions.revoke(sessionId);\n\t\tif (result.error === null) await refetch();\n\n\t\treturn result;\n\t};\n\n\tvoid refetch();\n\n\treturn { data, error, isPending, refetch, revoke };\n};\n\nexport const useSignIn = (client: AuthClient) =>\n\tuseMutation(client.signIn.email);\n\nexport const useSignOut = (client: AuthClient) => useMutation(client.signOut);\n\nexport const useSignUp = (client: AuthClient) =>\n\tuseMutation(client.signUp.email);\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": ";;AAIA;AAiBA,IAAM,cAAc,CACnB,QAC+B;AAAA,EAC/B,OAAO,MAAM,WAAW,aAA0B,IAAI;AAAA,EACtD,OAAO,OAAO,YAAY,aAAqC,IAAI;AAAA,EACnE,OAAO,WAAW,gBAAgB,aAAa,KAAK;AAAA,EACpD,I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SAAS,MAAM,OAAO,SAAS,OAAO,SAAS;AAAA,IACrD,IAAI,OAAO,UAAU;AAAA,MAAM,MAAM,QAAQ;AAAA,IAEzC,OAAO;AAAA;AAAA,EAGH,QAAQ;AAAA,EAEb,OAAO,EAAE,MAAM,OAAO,WAAW,SAAS,OAAO;AAAA;AAG3C,IAAM,YAAY,CAAC,WACzB,YAAY,OAAO,OAAO,KAAK;AAEzB,IAAM,aAAa,CAAC,WAAuB,YAAY,OAAO,OAAO;AAErE,IAAM,YAAY,CAAC,WACzB,YAAY,OAAO,OAAO,KAAK;",
|
|
8
|
+
"debugId": "C75839665B18FF0264756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { type Writable } from 'svelte/store';
|
|
2
|
+
import type { AuthClient, AuthClientError } from './createAuthClient';
|
|
3
|
+
type Mutator<Args, Data> = (args: Args) => Promise<{
|
|
4
|
+
data: Data | null;
|
|
5
|
+
error: AuthClientError | null;
|
|
6
|
+
}>;
|
|
7
|
+
type MutationState<Args, Data> = {
|
|
8
|
+
data: Writable<Data | null>;
|
|
9
|
+
error: Writable<AuthClientError | null>;
|
|
10
|
+
isPending: Writable<boolean>;
|
|
11
|
+
mutate: Mutator<Args, Data>;
|
|
12
|
+
reset: () => void;
|
|
13
|
+
};
|
|
14
|
+
export declare const useMagicLink: (client: AuthClient) => MutationState<{
|
|
15
|
+
email: string;
|
|
16
|
+
}, {
|
|
17
|
+
ok: true;
|
|
18
|
+
}>;
|
|
19
|
+
export declare const useMfaChallenge: (client: AuthClient) => MutationState<{
|
|
20
|
+
code: string;
|
|
21
|
+
}, {
|
|
22
|
+
status: "authenticated";
|
|
23
|
+
}>;
|
|
24
|
+
export declare const usePasswordReset: (client: AuthClient) => MutationState<{
|
|
25
|
+
email: string;
|
|
26
|
+
}, {
|
|
27
|
+
ok: true;
|
|
28
|
+
}>;
|
|
29
|
+
export declare const useSessions: (client: AuthClient) => {
|
|
30
|
+
data: Writable<unknown[] | null>;
|
|
31
|
+
error: Writable<AuthClientError | null>;
|
|
32
|
+
isPending: Writable<boolean>;
|
|
33
|
+
refetch: () => Promise<void>;
|
|
34
|
+
revoke: (sessionId: string) => Promise<{
|
|
35
|
+
data: null;
|
|
36
|
+
error: AuthClientError;
|
|
37
|
+
} | {
|
|
38
|
+
data: {
|
|
39
|
+
ok: true;
|
|
40
|
+
};
|
|
41
|
+
error: null;
|
|
42
|
+
}>;
|
|
43
|
+
};
|
|
44
|
+
export declare const useSignIn: (client: AuthClient) => MutationState<{
|
|
45
|
+
email: string;
|
|
46
|
+
password: string;
|
|
47
|
+
}, {
|
|
48
|
+
passwordCompromised?: boolean;
|
|
49
|
+
status: "authenticated" | "mfa_required";
|
|
50
|
+
}>;
|
|
51
|
+
export declare const useSignOut: (client: AuthClient) => MutationState<unknown, {
|
|
52
|
+
ok: true;
|
|
53
|
+
}>;
|
|
54
|
+
export declare const useSignUp: (client: AuthClient) => MutationState<{
|
|
55
|
+
[extra: string]: unknown;
|
|
56
|
+
email: string;
|
|
57
|
+
password: string;
|
|
58
|
+
}, {
|
|
59
|
+
status: "authenticated";
|
|
60
|
+
} | {
|
|
61
|
+
status: "verification_required";
|
|
62
|
+
}>;
|
|
63
|
+
export {};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// src/client/svelte.ts
|
|
3
|
+
import { writable } from "svelte/store";
|
|
4
|
+
var useMutation = (run) => {
|
|
5
|
+
const data = writable(null);
|
|
6
|
+
const error = writable(null);
|
|
7
|
+
const isPending = writable(false);
|
|
8
|
+
const mutate = async (args) => {
|
|
9
|
+
isPending.set(true);
|
|
10
|
+
error.set(null);
|
|
11
|
+
const result = await run(args);
|
|
12
|
+
data.set(result.data);
|
|
13
|
+
error.set(result.error);
|
|
14
|
+
isPending.set(false);
|
|
15
|
+
return result;
|
|
16
|
+
};
|
|
17
|
+
const reset = () => {
|
|
18
|
+
data.set(null);
|
|
19
|
+
error.set(null);
|
|
20
|
+
isPending.set(false);
|
|
21
|
+
};
|
|
22
|
+
return { data, error, isPending, mutate, reset };
|
|
23
|
+
};
|
|
24
|
+
var useMagicLink = (client) => useMutation(client.passwordless.requestMagicLink);
|
|
25
|
+
var useMfaChallenge = (client) => useMutation(client.mfa.challenge);
|
|
26
|
+
var usePasswordReset = (client) => useMutation(client.passwordReset.request);
|
|
27
|
+
var useSessions = (client) => {
|
|
28
|
+
const data = writable(null);
|
|
29
|
+
const error = writable(null);
|
|
30
|
+
const isPending = writable(true);
|
|
31
|
+
const refetch = async () => {
|
|
32
|
+
isPending.set(true);
|
|
33
|
+
const result = await client.sessions.list();
|
|
34
|
+
data.set(result.data);
|
|
35
|
+
error.set(result.error);
|
|
36
|
+
isPending.set(false);
|
|
37
|
+
};
|
|
38
|
+
const revoke = async (sessionId) => {
|
|
39
|
+
const result = await client.sessions.revoke(sessionId);
|
|
40
|
+
if (result.error === null)
|
|
41
|
+
await refetch();
|
|
42
|
+
return result;
|
|
43
|
+
};
|
|
44
|
+
refetch();
|
|
45
|
+
return { data, error, isPending, refetch, revoke };
|
|
46
|
+
};
|
|
47
|
+
var useSignIn = (client) => useMutation(client.signIn.email);
|
|
48
|
+
var useSignOut = (client) => useMutation(client.signOut);
|
|
49
|
+
var useSignUp = (client) => useMutation(client.signUp.email);
|
|
50
|
+
export {
|
|
51
|
+
useSignUp,
|
|
52
|
+
useSignOut,
|
|
53
|
+
useSignIn,
|
|
54
|
+
useSessions,
|
|
55
|
+
usePasswordReset,
|
|
56
|
+
useMfaChallenge,
|
|
57
|
+
useMagicLink
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
//# debugId=4A57E67D0678452364756E2164756E21
|
|
61
|
+
//# sourceMappingURL=svelte.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/client/svelte.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"// Thin Svelte composables over `createAuthClient`, mirroring `./react`. Same `{ data,\n// error, isPending, mutate, reset }` shape — only the reactivity is Svelte's (writable\n// stores from `svelte/store`, which work in both Svelte 4 with `$store` auto-subscription\n// and Svelte 5 with $state-based usage via `get(store)` or `$:` reactivity).\n// Bring your own form / UI; these are primitives.\n\nimport { writable, type Writable } from 'svelte/store';\nimport type { AuthClient, AuthClientError } from './createAuthClient';\n\ntype Mutator<Args, Data> = (\n\targs: Args\n) => Promise<{ data: Data | null; error: AuthClientError | null }>;\n\ntype MutationState<Args, Data> = {\n\tdata: Writable<Data | null>;\n\terror: Writable<AuthClientError | null>;\n\tisPending: Writable<boolean>;\n\tmutate: Mutator<Args, Data>;\n\treset: () => void;\n};\n\n// Generic mutation composable. The exported composables are 1-2 line specializations of\n// this — kept private so consumers depend on the named API, not this internal shape.\nconst useMutation = <Args, Data>(\n\trun: Mutator<Args, Data>\n): MutationState<Args, Data> => {\n\tconst data: Writable<Data | null> = writable(null);\n\tconst error: Writable<AuthClientError | null> = writable(null);\n\tconst isPending = writable(false);\n\n\tconst mutate: Mutator<Args, Data> = async (args) => {\n\t\tisPending.set(true);\n\t\terror.set(null);\n\t\tconst result = await run(args);\n\t\tdata.set(result.data);\n\t\terror.set(result.error);\n\t\tisPending.set(false);\n\n\t\treturn result;\n\t};\n\n\tconst reset = () => {\n\t\tdata.set(null);\n\t\terror.set(null);\n\t\tisPending.set(false);\n\t};\n\n\treturn { data, error, isPending, mutate, reset };\n};\n\nexport const useMagicLink = (client: AuthClient) =>\n\tuseMutation(client.passwordless.requestMagicLink);\n\nexport const useMfaChallenge = (client: AuthClient) =>\n\tuseMutation(client.mfa.challenge);\n\nexport const usePasswordReset = (client: AuthClient) =>\n\tuseMutation(client.passwordReset.request);\n\n// Query composable for the user's active sessions; refetch() reruns it, revoke(sessionId)\n// kills one and refetches. Same `{ data, error, isPending }` triplet as the mutations so\n// the consumer can render one way.\nexport const useSessions = (client: AuthClient) => {\n\tconst data: Writable<unknown[] | null> = writable(null);\n\tconst error: Writable<AuthClientError | null> = writable(null);\n\tconst isPending = writable(true);\n\n\tconst refetch = async () => {\n\t\tisPending.set(true);\n\t\tconst result = await client.sessions.list();\n\t\tdata.set(result.data);\n\t\terror.set(result.error);\n\t\tisPending.set(false);\n\t};\n\n\tconst revoke = async (sessionId: string) => {\n\t\tconst result = await client.sessions.revoke(sessionId);\n\t\tif (result.error === null) await refetch();\n\n\t\treturn result;\n\t};\n\n\tvoid refetch();\n\n\treturn { data, error, isPending, refetch, revoke };\n};\n\nexport const useSignIn = (client: AuthClient) =>\n\tuseMutation(client.signIn.email);\n\nexport const useSignOut = (client: AuthClient) => useMutation(client.signOut);\n\nexport const useSignUp = (client: AuthClient) =>\n\tuseMutation(client.signUp.email);\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": ";;AAMA;AAiBA,IAAM,cAAc,CACnB,QAC+B;AAAA,EAC/B,MAAM,OAA8B,SAAS,IAAI;AAAA,EACjD,MAAM,QAA0C,SAAS,IAAI;AAAA,EAC7D,MAAM,YAAY,SAAS,KAAK;AAAA,EAEhC,MAAM,SAA8B,OAAO,SAAS;AAAA,IACnD,UAAU,IAAI,IAAI;AAAA,IAClB,MAAM,IAAI,IAAI;AAAA,IACd,MAAM,SAAS,MAAM,IAAI,IAAI;AAAA,IAC7B,KAAK,IAAI,OAAO,IAAI;AAAA,IACpB,MAAM,IAAI,OAAO,KAAK;AAAA,IACtB,UAAU,IAAI,KAAK;AAAA,IAEnB,OAAO;AAAA;AAAA,EAGR,MAAM,QAAQ,MAAM;AAAA,IACnB,KAAK,IAAI,IAAI;AAAA,IACb,MAAM,IAAI,IAAI;AAAA,IACd,UAAU,IAAI,KAAK;AAAA;AAAA,EAGpB,OAAO,EAAE,MAAM,OAAO,WAAW,QAAQ,MAAM;AAAA;AAGzC,IAAM,eAAe,CAAC,WAC5B,YAAY,OAAO,aAAa,gBAAgB;AAE1C,IAAM,kBAAkB,CAAC,WAC/B,YAAY,OAAO,IAAI,SAAS;AAE1B,IAAM,mBAAmB,CAAC,WAChC,YAAY,OAAO,cAAc,OAAO;AAKlC,IAAM,cAAc,CAAC,WAAuB;AAAA,EAClD,MAAM,OAAmC,SAAS,IAAI;AAAA,EACtD,MAAM,QAA0C,SAAS,IAAI;AAAA,EAC7D,MAAM,YAAY,SAAS,IAAI;AAAA,EAE/B,MAAM,UAAU,YAAY;AAAA,IAC3B,UAAU,IAAI,IAAI;AAAA,IAClB,MAAM,SAAS,MAAM,OAAO,SAAS,KAAK;AAAA,IAC1C,KAAK,IAAI,OAAO,IAAI;AAAA,IACpB,MAAM,IAAI,OAAO,KAAK;AAAA,IACtB,UAAU,IAAI,KAAK;AAAA;AAAA,EAGpB,MAAM,SAAS,OAAO,cAAsB;AAAA,IAC3C,MAAM,SAAS,MAAM,OAAO,SAAS,OAAO,SAAS;AAAA,IACrD,IAAI,OAAO,UAAU;AAAA,MAAM,MAAM,QAAQ;AAAA,IAEzC,OAAO;AAAA;AAAA,EAGH,QAAQ;AAAA,EAEb,OAAO,EAAE,MAAM,OAAO,WAAW,SAAS,OAAO;AAAA;AAG3C,IAAM,YAAY,CAAC,WACzB,YAAY,OAAO,OAAO,KAAK;AAEzB,IAAM,aAAa,CAAC,WAAuB,YAAY,OAAO,OAAO;AAErE,IAAM,YAAY,CAAC,WACzB,YAAY,OAAO,OAAO,KAAK;",
|
|
8
|
+
"debugId": "4A57E67D0678452364756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { type Ref } from 'vue';
|
|
2
|
+
import type { AuthClient, AuthClientError } from './createAuthClient';
|
|
3
|
+
type Mutator<Args, Data> = (args: Args) => Promise<{
|
|
4
|
+
data: Data | null;
|
|
5
|
+
error: AuthClientError | null;
|
|
6
|
+
}>;
|
|
7
|
+
type MutationState<Args, Data> = {
|
|
8
|
+
data: Ref<Data | null>;
|
|
9
|
+
error: Ref<AuthClientError | null>;
|
|
10
|
+
isPending: Ref<boolean>;
|
|
11
|
+
mutate: Mutator<Args, Data>;
|
|
12
|
+
reset: () => void;
|
|
13
|
+
};
|
|
14
|
+
export declare const useMagicLink: (client: AuthClient) => MutationState<{
|
|
15
|
+
email: string;
|
|
16
|
+
}, {
|
|
17
|
+
ok: true;
|
|
18
|
+
}>;
|
|
19
|
+
export declare const useMfaChallenge: (client: AuthClient) => MutationState<{
|
|
20
|
+
code: string;
|
|
21
|
+
}, {
|
|
22
|
+
status: "authenticated";
|
|
23
|
+
}>;
|
|
24
|
+
export declare const usePasswordReset: (client: AuthClient) => MutationState<{
|
|
25
|
+
email: string;
|
|
26
|
+
}, {
|
|
27
|
+
ok: true;
|
|
28
|
+
}>;
|
|
29
|
+
export declare const useSessions: (client: AuthClient) => {
|
|
30
|
+
data: Ref<unknown[] | null, unknown[] | null>;
|
|
31
|
+
error: Ref<AuthClientError | null, AuthClientError | null>;
|
|
32
|
+
isPending: Ref<boolean, boolean>;
|
|
33
|
+
refetch: () => Promise<void>;
|
|
34
|
+
revoke: (sessionId: string) => Promise<{
|
|
35
|
+
data: null;
|
|
36
|
+
error: AuthClientError;
|
|
37
|
+
} | {
|
|
38
|
+
data: {
|
|
39
|
+
ok: true;
|
|
40
|
+
};
|
|
41
|
+
error: null;
|
|
42
|
+
}>;
|
|
43
|
+
};
|
|
44
|
+
export declare const useSignIn: (client: AuthClient) => MutationState<{
|
|
45
|
+
email: string;
|
|
46
|
+
password: string;
|
|
47
|
+
}, {
|
|
48
|
+
passwordCompromised?: boolean;
|
|
49
|
+
status: "authenticated" | "mfa_required";
|
|
50
|
+
}>;
|
|
51
|
+
export declare const useSignOut: (client: AuthClient) => MutationState<unknown, {
|
|
52
|
+
ok: true;
|
|
53
|
+
}>;
|
|
54
|
+
export declare const useSignUp: (client: AuthClient) => MutationState<{
|
|
55
|
+
[extra: string]: unknown;
|
|
56
|
+
email: string;
|
|
57
|
+
password: string;
|
|
58
|
+
}, {
|
|
59
|
+
status: "authenticated";
|
|
60
|
+
} | {
|
|
61
|
+
status: "verification_required";
|
|
62
|
+
}>;
|
|
63
|
+
export {};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// src/client/vue.ts
|
|
3
|
+
import { onScopeDispose, ref } from "vue";
|
|
4
|
+
var useMutation = (run) => {
|
|
5
|
+
const data = ref(null);
|
|
6
|
+
const error = ref(null);
|
|
7
|
+
const isPending = ref(false);
|
|
8
|
+
let alive = true;
|
|
9
|
+
onScopeDispose(() => {
|
|
10
|
+
alive = false;
|
|
11
|
+
});
|
|
12
|
+
const mutate = async (args) => {
|
|
13
|
+
isPending.value = true;
|
|
14
|
+
error.value = null;
|
|
15
|
+
const result = await run(args);
|
|
16
|
+
if (alive) {
|
|
17
|
+
data.value = result.data;
|
|
18
|
+
error.value = result.error;
|
|
19
|
+
isPending.value = false;
|
|
20
|
+
}
|
|
21
|
+
return result;
|
|
22
|
+
};
|
|
23
|
+
const reset = () => {
|
|
24
|
+
data.value = null;
|
|
25
|
+
error.value = null;
|
|
26
|
+
isPending.value = false;
|
|
27
|
+
};
|
|
28
|
+
return { data, error, isPending, mutate, reset };
|
|
29
|
+
};
|
|
30
|
+
var useMagicLink = (client) => useMutation(client.passwordless.requestMagicLink);
|
|
31
|
+
var useMfaChallenge = (client) => useMutation(client.mfa.challenge);
|
|
32
|
+
var usePasswordReset = (client) => useMutation(client.passwordReset.request);
|
|
33
|
+
var useSessions = (client) => {
|
|
34
|
+
const data = ref(null);
|
|
35
|
+
const error = ref(null);
|
|
36
|
+
const isPending = ref(true);
|
|
37
|
+
let alive = true;
|
|
38
|
+
onScopeDispose(() => {
|
|
39
|
+
alive = false;
|
|
40
|
+
});
|
|
41
|
+
const refetch = async () => {
|
|
42
|
+
isPending.value = true;
|
|
43
|
+
const result = await client.sessions.list();
|
|
44
|
+
if (alive) {
|
|
45
|
+
data.value = result.data;
|
|
46
|
+
error.value = result.error;
|
|
47
|
+
isPending.value = false;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
const revoke = async (sessionId) => {
|
|
51
|
+
const result = await client.sessions.revoke(sessionId);
|
|
52
|
+
if (result.error === null)
|
|
53
|
+
await refetch();
|
|
54
|
+
return result;
|
|
55
|
+
};
|
|
56
|
+
refetch();
|
|
57
|
+
return { data, error, isPending, refetch, revoke };
|
|
58
|
+
};
|
|
59
|
+
var useSignIn = (client) => useMutation(client.signIn.email);
|
|
60
|
+
var useSignOut = (client) => useMutation(client.signOut);
|
|
61
|
+
var useSignUp = (client) => useMutation(client.signUp.email);
|
|
62
|
+
export {
|
|
63
|
+
useSignUp,
|
|
64
|
+
useSignOut,
|
|
65
|
+
useSignIn,
|
|
66
|
+
useSessions,
|
|
67
|
+
usePasswordReset,
|
|
68
|
+
useMfaChallenge,
|
|
69
|
+
useMagicLink
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
//# debugId=3BD102183F34B9F664756E2164756E21
|
|
73
|
+
//# sourceMappingURL=vue.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/client/vue.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"// Thin Vue composables over `createAuthClient`, mirroring `./react`. Same `{ data, error,\n// isPending, mutate, reset }` shape — only the reactivity is Vue's (refs + onScopeDispose).\n// Bring your own form / UI; these are primitives.\n\nimport { onScopeDispose, ref, type Ref } from 'vue';\nimport type { AuthClient, AuthClientError } from './createAuthClient';\n\ntype Mutator<Args, Data> = (\n\targs: Args\n) => Promise<{ data: Data | null; error: AuthClientError | null }>;\n\ntype MutationState<Args, Data> = {\n\tdata: Ref<Data | null>;\n\terror: Ref<AuthClientError | null>;\n\tisPending: Ref<boolean>;\n\tmutate: Mutator<Args, Data>;\n\treset: () => void;\n};\n\n// Generic mutation composable. The exported composables are 1-2 line specializations of\n// this — kept private so consumers depend on the named API, not this internal shape.\nconst useMutation = <Args, Data>(\n\trun: Mutator<Args, Data>\n): MutationState<Args, Data> => {\n\tconst data: Ref<Data | null> = ref(null);\n\tconst error: Ref<AuthClientError | null> = ref(null);\n\tconst isPending = ref(false);\n\tlet alive = true;\n\tonScopeDispose(() => {\n\t\talive = false;\n\t});\n\n\tconst mutate: Mutator<Args, Data> = async (args) => {\n\t\tisPending.value = true;\n\t\terror.value = null;\n\t\tconst result = await run(args);\n\t\tif (alive) {\n\t\t\tdata.value = result.data;\n\t\t\terror.value = result.error;\n\t\t\tisPending.value = false;\n\t\t}\n\n\t\treturn result;\n\t};\n\n\tconst reset = () => {\n\t\tdata.value = null;\n\t\terror.value = null;\n\t\tisPending.value = false;\n\t};\n\n\treturn { data, error, isPending, mutate, reset };\n};\n\nexport const useMagicLink = (client: AuthClient) =>\n\tuseMutation(client.passwordless.requestMagicLink);\n\nexport const useMfaChallenge = (client: AuthClient) =>\n\tuseMutation(client.mfa.challenge);\n\nexport const usePasswordReset = (client: AuthClient) =>\n\tuseMutation(client.passwordReset.request);\n\n// Query composable for the user's active sessions; refetch() reruns it, revoke(sessionId)\n// kills one and refetches. Same `{ data, error, isPending }` triplet as the mutations so\n// the consumer can render one way.\nexport const useSessions = (client: AuthClient) => {\n\tconst data: Ref<unknown[] | null> = ref(null);\n\tconst error: Ref<AuthClientError | null> = ref(null);\n\tconst isPending = ref(true);\n\tlet alive = true;\n\tonScopeDispose(() => {\n\t\talive = false;\n\t});\n\n\tconst refetch = async () => {\n\t\tisPending.value = true;\n\t\tconst result = await client.sessions.list();\n\t\tif (alive) {\n\t\t\tdata.value = result.data;\n\t\t\terror.value = result.error;\n\t\t\tisPending.value = false;\n\t\t}\n\t};\n\n\tconst revoke = async (sessionId: string) => {\n\t\tconst result = await client.sessions.revoke(sessionId);\n\t\tif (result.error === null) await refetch();\n\n\t\treturn result;\n\t};\n\n\tvoid refetch();\n\n\treturn { data, error, isPending, refetch, revoke };\n};\n\nexport const useSignIn = (client: AuthClient) =>\n\tuseMutation(client.signIn.email);\n\nexport const useSignOut = (client: Au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,UAAU,QAAQ;AAAA,IAClB,MAAM,SAAS,MAAM,OAAO,SAAS,KAAK;AAAA,IAC1C,IAAI,OAAO;AAAA,MACV,KAAK,QAAQ,OAAO;AAAA,MACpB,MAAM,QAAQ,OAAO;AAAA,MACrB,UAAU,QAAQ;AAAA,IACnB;AAAA;AAAA,EAGD,MAAM,SAAS,OAAO,cAAsB;AAAA,IAC3C,MAAM,SAAS,MAAM,OAAO,SAAS,OAAO,SAAS;AAAA,IACrD,IAAI,OAAO,UAAU;AAAA,MAAM,MAAM,QAAQ;AAAA,IAEzC,OAAO;AAAA;AAAA,EAGH,QAAQ;AAAA,EAEb,OAAO,EAAE,MAAM,OAAO,WAAW,SAAS,OAAO;AAAA;AAG3C,IAAM,YAAY,CAAC,WACzB,YAAY,OAAO,OAAO,KAAK;AAEzB,IAAM,aAAa,CAAC,WAAuB,YAAY,OAAO,OAAO;AAErE,IAAM,YAAY,CAAC,WACzB,YAAY,OAAO,OAAO,KAAK;",
|
|
8
|
+
"debugId": "3BD102183F34B9F664756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
package/dist/fga/config.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { FgaSchema, Warrant, WarrantStore } from './types';
|
|
2
2
|
export type FgaCache = {
|
|
3
|
-
clear: () => void
|
|
4
|
-
get: (key: string) => boolean | undefined
|
|
5
|
-
set: (key: string, value: boolean) => void
|
|
3
|
+
clear: () => void | Promise<void>;
|
|
4
|
+
get: (key: string) => boolean | undefined | Promise<boolean | undefined>;
|
|
5
|
+
set: (key: string, value: boolean) => void | Promise<void>;
|
|
6
6
|
};
|
|
7
7
|
export type FgaConfig = {
|
|
8
8
|
cache?: FgaCache;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { RedisLike } from '../stores/redis';
|
|
2
|
+
import type { FgaCache } from './config';
|
|
3
|
+
export type RedisFgaCacheClient = RedisLike & {
|
|
4
|
+
keys?: (pattern: string) => Promise<string[]>;
|
|
5
|
+
};
|
|
6
|
+
type CreateRedisFgaCacheOptions = {
|
|
7
|
+
keyPrefix?: string;
|
|
8
|
+
ttlMs?: number;
|
|
9
|
+
};
|
|
10
|
+
export declare const createRedisFgaCache: (redis: RedisFgaCacheClient, { keyPrefix, ttlMs }?: CreateRedisFgaCacheOptions) => FgaCache;
|
|
11
|
+
export {};
|
package/dist/index.d.ts
CHANGED
|
@@ -15140,6 +15140,7 @@ export * from './fga/config';
|
|
|
15140
15140
|
export * from './fga/schema';
|
|
15141
15141
|
export * from './fga/types';
|
|
15142
15142
|
export { createInMemoryWarrantStore, warrantKey } from './fga/inMemoryStores';
|
|
15143
|
+
export { createRedisFgaCache, type RedisFgaCacheClient } from './fga/redisCheckCache';
|
|
15143
15144
|
export { createNeonWarrantStore, createPostgresWarrantStore, warrantsTable } from './fga/postgresStores';
|
|
15144
15145
|
export { ssoDiscoveryRoute } from './sso/discoveryRoute';
|
|
15145
15146
|
export { oidcSsoRoutes } from './sso/oidcRoutes';
|
package/dist/index.js
CHANGED
|
@@ -22191,7 +22191,7 @@ var evaluate = async (context, resourceType, resourceId, relation, depth) => {
|
|
|
22191
22191
|
var cacheKey = (query) => `${query.resourceType}:${query.resourceId}#${query.relation}@${query.subjectType}:${query.subjectId}`;
|
|
22192
22192
|
var check = async (config, query) => {
|
|
22193
22193
|
const key = cacheKey(query);
|
|
22194
|
-
const cached = config.cache?.get(key);
|
|
22194
|
+
const cached = await config.cache?.get(key);
|
|
22195
22195
|
if (cached !== undefined)
|
|
22196
22196
|
return cached;
|
|
22197
22197
|
const context = {
|
|
@@ -22375,6 +22375,29 @@ var createInMemoryWarrantStore = () => {
|
|
|
22375
22375
|
};
|
|
22376
22376
|
};
|
|
22377
22377
|
var warrantKey = (warrant) => `${warrant.resourceType}:${warrant.resourceId}#${warrant.relation}@${warrant.subjectType}:${warrant.subjectId}#${warrant.subjectRelation ?? ""}`;
|
|
22378
|
+
// src/fga/redisCheckCache.ts
|
|
22379
|
+
var DEFAULT_TTL_MS = 5000;
|
|
22380
|
+
var DEFAULT_PREFIX2 = "auth:fga:";
|
|
22381
|
+
var parseBoolean = (raw) => {
|
|
22382
|
+
if (raw === "true")
|
|
22383
|
+
return true;
|
|
22384
|
+
if (raw === "false")
|
|
22385
|
+
return false;
|
|
22386
|
+
return;
|
|
22387
|
+
};
|
|
22388
|
+
var createRedisFgaCache = (redis, { keyPrefix = DEFAULT_PREFIX2, ttlMs = DEFAULT_TTL_MS } = {}) => ({
|
|
22389
|
+
clear: async () => {
|
|
22390
|
+
const enumerate = redis.keys;
|
|
22391
|
+
if (enumerate === undefined)
|
|
22392
|
+
return;
|
|
22393
|
+
const keys = await enumerate(`${keyPrefix}*`);
|
|
22394
|
+
await Promise.all(keys.map((key) => redis.del(key)));
|
|
22395
|
+
},
|
|
22396
|
+
get: async (key) => parseBoolean(await redis.get(keyPrefix + key)),
|
|
22397
|
+
set: async (key, value) => {
|
|
22398
|
+
await redis.set(keyPrefix + key, value ? "true" : "false", ttlMs);
|
|
22399
|
+
}
|
|
22400
|
+
});
|
|
22378
22401
|
// src/fga/postgresStores.ts
|
|
22379
22402
|
var ID_LENGTH9 = 255;
|
|
22380
22403
|
var warrantsTable = pgTable("auth_fga_warrants", {
|
|
@@ -23734,6 +23757,7 @@ export {
|
|
|
23734
23757
|
createScimToken,
|
|
23735
23758
|
createRiskEngine,
|
|
23736
23759
|
createRedisLockoutStore,
|
|
23760
|
+
createRedisFgaCache,
|
|
23737
23761
|
createRedisAuthSessionStore,
|
|
23738
23762
|
createPostgresWebhookDeliveryStore,
|
|
23739
23763
|
createPostgresWebAuthnCredentialStore,
|
|
@@ -23901,5 +23925,5 @@ export {
|
|
|
23901
23925
|
AuthIdentityConflictError
|
|
23902
23926
|
};
|
|
23903
23927
|
|
|
23904
|
-
//# debugId=
|
|
23928
|
+
//# debugId=0F54EE0288E37B6464756E2164756E21
|
|
23905
23929
|
//# sourceMappingURL=index.js.map
|