@absolutejs/auth 0.75.4 → 0.75.6
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/agents/context.d.ts +6 -2
- package/dist/agents/index.js +6 -5
- package/dist/agents/index.js.map +3 -3
- package/dist/agents/routes.d.ts +10 -4
- package/dist/authContext.d.ts +178 -66
- package/dist/authorization/protectPermission.d.ts +8 -3
- package/dist/cli/migrate.js +14 -7
- package/dist/cli/migrate.js.map +3 -3
- package/dist/htmx/configuredRoutes.d.ts +126 -37
- package/dist/htmx/routes.d.ts +126 -37
- package/dist/index.d.ts +432 -162
- package/dist/index.js +57 -43
- package/dist/index.js.map +7 -7
- package/dist/routes/protectRoute.d.ts +21 -4
- package/dist/routes/stepUp.d.ts +8 -3
- package/dist/server.js +57 -43
- package/dist/server.js.map +7 -7
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Elysia } from 'elysia';
|
|
1
|
+
import { Elysia, StatusMap, type ElysiaStatus } from 'elysia';
|
|
2
2
|
import type { AuthSessionSource } from '../session/types';
|
|
3
3
|
import { type AccessTokenPrincipalConfig, type AuthPrincipal } from '../principal';
|
|
4
4
|
type AuthFailError = {
|
|
@@ -8,6 +8,11 @@ type AuthFailError = {
|
|
|
8
8
|
readonly code: 'Unauthorized';
|
|
9
9
|
readonly message: 'User is not authenticated';
|
|
10
10
|
};
|
|
11
|
+
type AuthFailureResponse = ElysiaStatus<'Bad Request', 'Cookies are missing', (typeof StatusMap)['Bad Request']> | ElysiaStatus<'Unauthorized', 'User is not authenticated', (typeof StatusMap)['Unauthorized']>;
|
|
12
|
+
type ProtectRoute<UserType> = {
|
|
13
|
+
<AuthReturn, AuthFailReturn = never>(handleAuth: (user: UserType) => Promise<AuthReturn>, handleAuthFail?: (error: AuthFailError) => AuthFailReturn): Promise<AuthFailureResponse | AuthReturn | Awaited<AuthFailReturn>>;
|
|
14
|
+
<AuthReturn, AuthFailReturn = never>(handleAuth: (user: UserType) => AuthReturn, handleAuthFail?: (error: AuthFailError) => AuthFailReturn): Promise<AuthFailureResponse | AuthReturn | Awaited<AuthFailReturn>>;
|
|
15
|
+
};
|
|
11
16
|
export declare const protectRoutePlugin: <UserType>({ accessTokens, authSessionStore }?: {
|
|
12
17
|
accessTokens?: AccessTokenPrincipalConfig<UserType>;
|
|
13
18
|
authSessionStore?: AuthSessionSource<UserType>;
|
|
@@ -18,8 +23,21 @@ export declare const protectRoutePlugin: <UserType>({ accessTokens, authSessionS
|
|
|
18
23
|
unregisteredSession: import("..").UnregisteredSessionRecord;
|
|
19
24
|
};
|
|
20
25
|
derive: {
|
|
26
|
+
readonly absoluteAuthStatus: {
|
|
27
|
+
error: {
|
|
28
|
+
readonly code: "Bad Request";
|
|
29
|
+
readonly message: "Cookies are missing";
|
|
30
|
+
};
|
|
31
|
+
user: null;
|
|
32
|
+
impersonator?: undefined;
|
|
33
|
+
} | {
|
|
34
|
+
error: null;
|
|
35
|
+
impersonator: import("..").Impersonator | undefined;
|
|
36
|
+
user: NonNullable<UserType> | null;
|
|
37
|
+
};
|
|
21
38
|
readonly authPrincipal: AuthPrincipal<UserType> | undefined;
|
|
22
|
-
|
|
39
|
+
} & {
|
|
40
|
+
readonly protectRoute: ProtectRoute<UserType>;
|
|
23
41
|
};
|
|
24
42
|
}, {
|
|
25
43
|
typebox: {};
|
|
@@ -36,8 +54,7 @@ export declare const protectRoutePlugin: <UserType>({ accessTokens, authSessionS
|
|
|
36
54
|
macroFn: {};
|
|
37
55
|
parser: {};
|
|
38
56
|
response: import("elysia/types").ExtractErrorFromHandle<{
|
|
39
|
-
readonly
|
|
40
|
-
readonly protectRoute: <AuthReturn, AuthFailReturn = never>(handleAuth: (user: UserType) => AuthReturn | Promise<AuthReturn>, handleAuthFail?: (error: AuthFailError) => AuthFailReturn) => import("elysia").ElysiaStatus<"Unauthorized", "User is not authenticated", 401> | import("elysia").ElysiaStatus<"Bad Request", "Cookies are missing", 400> | AuthReturn | Promise<AuthReturn> | NonNullable<AuthFailReturn>;
|
|
57
|
+
readonly protectRoute: ProtectRoute<UserType>;
|
|
41
58
|
}>;
|
|
42
59
|
}, {}, import("elysia/types").DefaultEphemeral, import("elysia/types").DefaultEphemeral>;
|
|
43
60
|
export {};
|
package/dist/routes/stepUp.d.ts
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
|
-
import { Elysia } from 'elysia';
|
|
1
|
+
import { Elysia, StatusMap, type ElysiaStatus } from 'elysia';
|
|
2
2
|
import type { AuthSessionSource } from '../session/types';
|
|
3
3
|
type ReauthFailError = {
|
|
4
4
|
readonly code: 'Unauthorized';
|
|
5
5
|
readonly message: 'Recent authentication required';
|
|
6
6
|
};
|
|
7
|
+
type ReauthFailureResponse = ElysiaStatus<'Unauthorized', 'Recent authentication required', (typeof StatusMap)['Unauthorized']>;
|
|
8
|
+
type RequireRecentAuth<UserType> = {
|
|
9
|
+
<AuthReturn, AuthFailReturn = never>(maxAgeMs: number, handleAuth: (user: UserType) => Promise<AuthReturn>, handleAuthFail?: (error: ReauthFailError) => AuthFailReturn): Promise<ReauthFailureResponse | AuthReturn | Awaited<AuthFailReturn>>;
|
|
10
|
+
<AuthReturn, AuthFailReturn = never>(maxAgeMs: number, handleAuth: (user: UserType) => AuthReturn, handleAuthFail?: (error: ReauthFailError) => AuthFailReturn): Promise<ReauthFailureResponse | AuthReturn | Awaited<AuthFailReturn>>;
|
|
11
|
+
};
|
|
7
12
|
export declare const stepUpPlugin: <UserType>({ authSessionStore }?: {
|
|
8
13
|
authSessionStore?: AuthSessionSource<UserType>;
|
|
9
14
|
}) => Elysia<"", "local", {
|
|
@@ -13,7 +18,7 @@ export declare const stepUpPlugin: <UserType>({ authSessionStore }?: {
|
|
|
13
18
|
unregisteredSession: import("..").UnregisteredSessionRecord;
|
|
14
19
|
};
|
|
15
20
|
derive: {
|
|
16
|
-
readonly requireRecentAuth: <
|
|
21
|
+
readonly requireRecentAuth: RequireRecentAuth<UserType>;
|
|
17
22
|
};
|
|
18
23
|
}, {
|
|
19
24
|
typebox: {};
|
|
@@ -30,7 +35,7 @@ export declare const stepUpPlugin: <UserType>({ authSessionStore }?: {
|
|
|
30
35
|
macroFn: {};
|
|
31
36
|
parser: {};
|
|
32
37
|
response: import("elysia/types").ExtractErrorFromHandle<{
|
|
33
|
-
readonly requireRecentAuth: <
|
|
38
|
+
readonly requireRecentAuth: RequireRecentAuth<UserType>;
|
|
34
39
|
}>;
|
|
35
40
|
}, {}, import("elysia/types").DefaultEphemeral, import("elysia/types").DefaultEphemeral>;
|
|
36
41
|
export {};
|
package/dist/server.js
CHANGED
|
@@ -4366,8 +4366,8 @@ var failureResponse = (config, failure, requiredScopes) => new Response(JSON.str
|
|
|
4366
4366
|
var agentAuthContextPlugin = (config) => new Elysia2({
|
|
4367
4367
|
name: "@absolutejs/auth/agent-context",
|
|
4368
4368
|
seed: pluginDependencySeed(config)
|
|
4369
|
-
}).derive(({ request }) =>
|
|
4370
|
-
protectAgent
|
|
4369
|
+
}).derive(({ request }) => {
|
|
4370
|
+
const protectAgent = async (requiredScopes, handleAuth, handleAuthFail) => {
|
|
4371
4371
|
if (config === undefined) {
|
|
4372
4372
|
const failure = {
|
|
4373
4373
|
code: "Unauthorized",
|
|
@@ -4393,8 +4393,9 @@ var agentAuthContextPlugin = (config) => new Elysia2({
|
|
|
4393
4393
|
return await handleAuthFail?.(failure) ?? failureResponse(config, failure, requiredScopes);
|
|
4394
4394
|
}
|
|
4395
4395
|
return handleAuth(principal);
|
|
4396
|
-
}
|
|
4397
|
-
}
|
|
4396
|
+
};
|
|
4397
|
+
return { protectAgent };
|
|
4398
|
+
}).as("global");
|
|
4398
4399
|
|
|
4399
4400
|
// src/agents/oauthGuide.ts
|
|
4400
4401
|
var DEFAULT_GUIDE_ROUTE = "/auth.md";
|
|
@@ -5605,17 +5606,17 @@ var protectPermissionPlugin = ({
|
|
|
5605
5606
|
}).use(sessionStore()).guard({
|
|
5606
5607
|
cookie: t3.Cookie({ user_session_id: userSessionIdTypebox }),
|
|
5607
5608
|
schema: "merge"
|
|
5608
|
-
}).derive(({ store: { session }, cookie: { user_session_id }, status }) =>
|
|
5609
|
-
protectPermission
|
|
5609
|
+
}).derive(({ store: { session }, cookie: { user_session_id }, status }) => {
|
|
5610
|
+
const protectPermission = (check, handleAuth, handleAuthFail) => getStatusFromSource({
|
|
5610
5611
|
authSessionStore,
|
|
5611
5612
|
session,
|
|
5612
5613
|
user_session_id
|
|
5613
5614
|
}).then(async ({ user, error }) => {
|
|
5614
5615
|
if (error) {
|
|
5615
|
-
return handleAuthFail?.(error) ?? status(error.code, error.message);
|
|
5616
|
+
return await handleAuthFail?.(error) ?? status(error.code, error.message);
|
|
5616
5617
|
}
|
|
5617
5618
|
if (!user) {
|
|
5618
|
-
return handleAuthFail?.({
|
|
5619
|
+
return await handleAuthFail?.({
|
|
5619
5620
|
code: "Unauthorized",
|
|
5620
5621
|
message: "User is not authenticated"
|
|
5621
5622
|
}) ?? status("Unauthorized", "User is not authenticated");
|
|
@@ -5632,14 +5633,15 @@ var protectPermissionPlugin = ({
|
|
|
5632
5633
|
organizationId: check.organizationId,
|
|
5633
5634
|
type: "authorization_denied"
|
|
5634
5635
|
});
|
|
5635
|
-
return handleAuthFail?.({
|
|
5636
|
+
return await handleAuthFail?.({
|
|
5636
5637
|
code: "Forbidden",
|
|
5637
5638
|
message: "Insufficient permissions"
|
|
5638
5639
|
}) ?? status("Forbidden", "Insufficient permissions");
|
|
5639
5640
|
}
|
|
5640
5641
|
return handleAuth(user);
|
|
5641
|
-
})
|
|
5642
|
-
}
|
|
5642
|
+
});
|
|
5643
|
+
return { protectPermission };
|
|
5644
|
+
}).as("global");
|
|
5643
5645
|
|
|
5644
5646
|
// src/routes/protectRoute.ts
|
|
5645
5647
|
import { Elysia as Elysia6, t as t4 } from "elysia";
|
|
@@ -5703,8 +5705,7 @@ var protectRoutePlugin = ({
|
|
|
5703
5705
|
}).derive(async ({
|
|
5704
5706
|
store: { session },
|
|
5705
5707
|
cookie: { user_session_id },
|
|
5706
|
-
headers
|
|
5707
|
-
status
|
|
5708
|
+
headers
|
|
5708
5709
|
}) => {
|
|
5709
5710
|
const sessionStatus = await getStatusFromSource({
|
|
5710
5711
|
authSessionStore,
|
|
@@ -5723,25 +5724,30 @@ var protectRoutePlugin = ({
|
|
|
5723
5724
|
authorization: headers.authorization,
|
|
5724
5725
|
config: accessTokens
|
|
5725
5726
|
});
|
|
5726
|
-
return {
|
|
5727
|
-
|
|
5728
|
-
|
|
5729
|
-
|
|
5730
|
-
|
|
5731
|
-
|
|
5732
|
-
|
|
5733
|
-
|
|
5734
|
-
|
|
5735
|
-
|
|
5736
|
-
|
|
5737
|
-
|
|
5738
|
-
|
|
5739
|
-
|
|
5740
|
-
}) ?? status("Unauthorized", "User is not authenticated");
|
|
5741
|
-
}
|
|
5742
|
-
return handleAuth(user);
|
|
5727
|
+
return { absoluteAuthStatus: sessionStatus, authPrincipal };
|
|
5728
|
+
}).derive(({ absoluteAuthStatus, authPrincipal, status }) => {
|
|
5729
|
+
const protectRoute = async (handleAuth, handleAuthFail) => {
|
|
5730
|
+
if (!absoluteAuthStatus)
|
|
5731
|
+
return await handleAuthFail?.({
|
|
5732
|
+
code: "Unauthorized",
|
|
5733
|
+
message: "User is not authenticated"
|
|
5734
|
+
}) ?? status("Unauthorized", "User is not authenticated");
|
|
5735
|
+
const user = authPrincipal?.user;
|
|
5736
|
+
const { error } = absoluteAuthStatus;
|
|
5737
|
+
if (error) {
|
|
5738
|
+
if (user)
|
|
5739
|
+
return handleAuth(user);
|
|
5740
|
+
return await handleAuthFail?.(error) ?? status(error.code, error.message);
|
|
5743
5741
|
}
|
|
5742
|
+
if (!user) {
|
|
5743
|
+
return await handleAuthFail?.({
|
|
5744
|
+
code: "Unauthorized",
|
|
5745
|
+
message: "User is not authenticated"
|
|
5746
|
+
}) ?? status("Unauthorized", "User is not authenticated");
|
|
5747
|
+
}
|
|
5748
|
+
return handleAuth(user);
|
|
5744
5749
|
};
|
|
5750
|
+
return { protectRoute };
|
|
5745
5751
|
}).as("global");
|
|
5746
5752
|
|
|
5747
5753
|
// src/routes/stepUp.ts
|
|
@@ -5754,23 +5760,24 @@ var stepUpPlugin = ({
|
|
|
5754
5760
|
}).use(sessionStore()).guard({
|
|
5755
5761
|
cookie: t5.Cookie({ user_session_id: userSessionIdTypebox }),
|
|
5756
5762
|
schema: "merge"
|
|
5757
|
-
}).derive(({ store: { session }, cookie: { user_session_id }, status }) =>
|
|
5758
|
-
requireRecentAuth
|
|
5763
|
+
}).derive(({ store: { session }, cookie: { user_session_id }, status }) => {
|
|
5764
|
+
const requireRecentAuth = (maxAgeMs, handleAuth, handleAuthFail) => loadSessionFromSource({
|
|
5759
5765
|
authSessionStore,
|
|
5760
5766
|
session,
|
|
5761
5767
|
userSessionId: user_session_id.value
|
|
5762
|
-
}).then((userSession) => {
|
|
5768
|
+
}).then(async (userSession) => {
|
|
5763
5769
|
const authenticatedAt = userSession?.authenticatedAt;
|
|
5764
5770
|
const isRecent = authenticatedAt !== undefined && Date.now() - authenticatedAt <= maxAgeMs;
|
|
5765
5771
|
if (!userSession || !isRecent) {
|
|
5766
|
-
return handleAuthFail?.({
|
|
5772
|
+
return await handleAuthFail?.({
|
|
5767
5773
|
code: "Unauthorized",
|
|
5768
5774
|
message: "Recent authentication required"
|
|
5769
5775
|
}) ?? status("Unauthorized", "Recent authentication required");
|
|
5770
5776
|
}
|
|
5771
5777
|
return handleAuth(userSession.user);
|
|
5772
|
-
})
|
|
5773
|
-
}
|
|
5778
|
+
});
|
|
5779
|
+
return { requireRecentAuth };
|
|
5780
|
+
}).as("global");
|
|
5774
5781
|
|
|
5775
5782
|
// src/oidc/socketTickets.ts
|
|
5776
5783
|
init_crypto();
|
|
@@ -40403,7 +40410,12 @@ var renderChunk = (chunk) => {
|
|
|
40403
40410
|
return "";
|
|
40404
40411
|
};
|
|
40405
40412
|
var formatSqlTemplate = (value) => value.queryChunks.map(renderChunk).join("");
|
|
40406
|
-
var
|
|
40413
|
+
var columnSqlType = (column) => {
|
|
40414
|
+
const dimensions = Reflect.get(column, "dimensions");
|
|
40415
|
+
const elementType = column.getSQLType();
|
|
40416
|
+
return typeof dimensions === "number" && dimensions > 0 ? `${elementType}${"[]".repeat(dimensions)}` : elementType;
|
|
40417
|
+
};
|
|
40418
|
+
var formatScalarDefault = (value) => {
|
|
40407
40419
|
if (value === null || value === undefined)
|
|
40408
40420
|
return "NULL";
|
|
40409
40421
|
if (is(value, SQL))
|
|
@@ -40414,15 +40426,17 @@ var formatDefault = (value) => {
|
|
|
40414
40426
|
return value ? "true" : "false";
|
|
40415
40427
|
if (typeof value === "number")
|
|
40416
40428
|
return String(value);
|
|
40417
|
-
if (
|
|
40429
|
+
if (typeof value === "object") {
|
|
40418
40430
|
return `'${JSON.stringify(value)}'::jsonb`;
|
|
40419
40431
|
}
|
|
40420
40432
|
return String(value);
|
|
40421
40433
|
};
|
|
40422
|
-
var
|
|
40434
|
+
var formatArrayDefault = (values) => `ARRAY[${values.map((value) => Array.isArray(value) ? formatArrayDefault(value) : formatScalarDefault(value)).join(", ")}]`;
|
|
40435
|
+
var formatDefault = (column, value) => {
|
|
40423
40436
|
const dimensions = Reflect.get(column, "dimensions");
|
|
40424
|
-
|
|
40425
|
-
|
|
40437
|
+
if (Array.isArray(value) && typeof dimensions === "number" && dimensions > 0)
|
|
40438
|
+
return `${formatArrayDefault(value)}::${columnSqlType(column)}`;
|
|
40439
|
+
return formatScalarDefault(value);
|
|
40426
40440
|
};
|
|
40427
40441
|
var columnSql = (column) => {
|
|
40428
40442
|
const parts = [`"${column.name}"`, columnSqlType(column)];
|
|
@@ -40431,7 +40445,7 @@ var columnSql = (column) => {
|
|
|
40431
40445
|
if (column.notNull && !column.primary)
|
|
40432
40446
|
parts.push("NOT NULL");
|
|
40433
40447
|
if (column.hasDefault && column.default !== undefined) {
|
|
40434
|
-
parts.push(`DEFAULT ${formatDefault(column.default)}`);
|
|
40448
|
+
parts.push(`DEFAULT ${formatDefault(column, column.default)}`);
|
|
40435
40449
|
}
|
|
40436
40450
|
if (column.isUnique)
|
|
40437
40451
|
parts.push("UNIQUE");
|
|
@@ -41672,5 +41686,5 @@ export {
|
|
|
41672
41686
|
VerificationProviderError
|
|
41673
41687
|
};
|
|
41674
41688
|
|
|
41675
|
-
//# debugId=
|
|
41689
|
+
//# debugId=6199F55288EF334A64756E2164756E21
|
|
41676
41690
|
//# sourceMappingURL=server.js.map
|