@absolutejs/auth 0.77.0 → 0.78.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/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 +20 -13
- package/dist/cli/migrate.js.map +4 -4
- package/dist/htmx/configuredRoutes.d.ts +126 -37
- package/dist/htmx/routes.d.ts +126 -37
- package/dist/index.d.ts +427 -157
- package/dist/index.js +63 -49
- package/dist/index.js.map +8 -8
- package/dist/linkedProviders/index.js +7 -7
- package/dist/linkedProviders/index.js.map +3 -3
- package/dist/routes/protectRoute.d.ts +21 -4
- package/dist/routes/stepUp.d.ts +8 -3
- package/dist/server.js +63 -49
- package/dist/server.js.map +8 -8
- 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
|
@@ -4368,8 +4368,8 @@ var failureResponse = (config, failure, requiredScopes) => new Response(JSON.str
|
|
|
4368
4368
|
var agentAuthContextPlugin = (config) => new Elysia2({
|
|
4369
4369
|
name: "@absolutejs/auth/agent-context",
|
|
4370
4370
|
seed: pluginDependencySeed(config)
|
|
4371
|
-
}).derive(({ request }) =>
|
|
4372
|
-
protectAgent
|
|
4371
|
+
}).derive(({ request }) => {
|
|
4372
|
+
const protectAgent = async (requiredScopes, handleAuth, handleAuthFail) => {
|
|
4373
4373
|
if (config === undefined) {
|
|
4374
4374
|
const failure = {
|
|
4375
4375
|
code: "Unauthorized",
|
|
@@ -4395,8 +4395,9 @@ var agentAuthContextPlugin = (config) => new Elysia2({
|
|
|
4395
4395
|
return await handleAuthFail?.(failure) ?? failureResponse(config, failure, requiredScopes);
|
|
4396
4396
|
}
|
|
4397
4397
|
return handleAuth(principal);
|
|
4398
|
-
}
|
|
4399
|
-
}
|
|
4398
|
+
};
|
|
4399
|
+
return { protectAgent };
|
|
4400
|
+
}).as("global");
|
|
4400
4401
|
|
|
4401
4402
|
// src/agents/oauthGuide.ts
|
|
4402
4403
|
var DEFAULT_GUIDE_ROUTE = "/auth.md";
|
|
@@ -5607,17 +5608,17 @@ var protectPermissionPlugin = ({
|
|
|
5607
5608
|
}).use(sessionStore()).guard({
|
|
5608
5609
|
cookie: t3.Cookie({ user_session_id: userSessionIdTypebox }),
|
|
5609
5610
|
schema: "merge"
|
|
5610
|
-
}).derive(({ store: { session }, cookie: { user_session_id }, status }) =>
|
|
5611
|
-
protectPermission
|
|
5611
|
+
}).derive(({ store: { session }, cookie: { user_session_id }, status }) => {
|
|
5612
|
+
const protectPermission = (check, handleAuth, handleAuthFail) => getStatusFromSource({
|
|
5612
5613
|
authSessionStore,
|
|
5613
5614
|
session,
|
|
5614
5615
|
user_session_id
|
|
5615
5616
|
}).then(async ({ user, error }) => {
|
|
5616
5617
|
if (error) {
|
|
5617
|
-
return handleAuthFail?.(error) ?? status(error.code, error.message);
|
|
5618
|
+
return await handleAuthFail?.(error) ?? status(error.code, error.message);
|
|
5618
5619
|
}
|
|
5619
5620
|
if (!user) {
|
|
5620
|
-
return handleAuthFail?.({
|
|
5621
|
+
return await handleAuthFail?.({
|
|
5621
5622
|
code: "Unauthorized",
|
|
5622
5623
|
message: "User is not authenticated"
|
|
5623
5624
|
}) ?? status("Unauthorized", "User is not authenticated");
|
|
@@ -5634,14 +5635,15 @@ var protectPermissionPlugin = ({
|
|
|
5634
5635
|
organizationId: check.organizationId,
|
|
5635
5636
|
type: "authorization_denied"
|
|
5636
5637
|
});
|
|
5637
|
-
return handleAuthFail?.({
|
|
5638
|
+
return await handleAuthFail?.({
|
|
5638
5639
|
code: "Forbidden",
|
|
5639
5640
|
message: "Insufficient permissions"
|
|
5640
5641
|
}) ?? status("Forbidden", "Insufficient permissions");
|
|
5641
5642
|
}
|
|
5642
5643
|
return handleAuth(user);
|
|
5643
|
-
})
|
|
5644
|
-
}
|
|
5644
|
+
});
|
|
5645
|
+
return { protectPermission };
|
|
5646
|
+
}).as("global");
|
|
5645
5647
|
|
|
5646
5648
|
// src/routes/protectRoute.ts
|
|
5647
5649
|
import { Elysia as Elysia6, t as t4 } from "elysia";
|
|
@@ -5705,8 +5707,7 @@ var protectRoutePlugin = ({
|
|
|
5705
5707
|
}).derive(async ({
|
|
5706
5708
|
store: { session },
|
|
5707
5709
|
cookie: { user_session_id },
|
|
5708
|
-
headers
|
|
5709
|
-
status
|
|
5710
|
+
headers
|
|
5710
5711
|
}) => {
|
|
5711
5712
|
const sessionStatus = await getStatusFromSource({
|
|
5712
5713
|
authSessionStore,
|
|
@@ -5725,25 +5726,30 @@ var protectRoutePlugin = ({
|
|
|
5725
5726
|
authorization: headers.authorization,
|
|
5726
5727
|
config: accessTokens
|
|
5727
5728
|
});
|
|
5728
|
-
return {
|
|
5729
|
-
|
|
5730
|
-
|
|
5731
|
-
|
|
5732
|
-
|
|
5733
|
-
|
|
5734
|
-
|
|
5735
|
-
|
|
5736
|
-
|
|
5737
|
-
|
|
5738
|
-
|
|
5739
|
-
|
|
5740
|
-
|
|
5741
|
-
|
|
5742
|
-
|
|
5743
|
-
|
|
5744
|
-
return
|
|
5729
|
+
return { absoluteAuthStatus: sessionStatus, authPrincipal };
|
|
5730
|
+
}).derive(({ absoluteAuthStatus, authPrincipal, status }) => {
|
|
5731
|
+
const protectRoute = async (handleAuth, handleAuthFail) => {
|
|
5732
|
+
if (!absoluteAuthStatus)
|
|
5733
|
+
return await handleAuthFail?.({
|
|
5734
|
+
code: "Unauthorized",
|
|
5735
|
+
message: "User is not authenticated"
|
|
5736
|
+
}) ?? status("Unauthorized", "User is not authenticated");
|
|
5737
|
+
const user = authPrincipal?.user;
|
|
5738
|
+
const { error } = absoluteAuthStatus;
|
|
5739
|
+
if (error) {
|
|
5740
|
+
if (user)
|
|
5741
|
+
return handleAuth(user);
|
|
5742
|
+
return await handleAuthFail?.(error) ?? status(error.code, error.message);
|
|
5743
|
+
}
|
|
5744
|
+
if (!user) {
|
|
5745
|
+
return await handleAuthFail?.({
|
|
5746
|
+
code: "Unauthorized",
|
|
5747
|
+
message: "User is not authenticated"
|
|
5748
|
+
}) ?? status("Unauthorized", "User is not authenticated");
|
|
5745
5749
|
}
|
|
5750
|
+
return handleAuth(user);
|
|
5746
5751
|
};
|
|
5752
|
+
return { protectRoute };
|
|
5747
5753
|
}).as("global");
|
|
5748
5754
|
|
|
5749
5755
|
// src/routes/stepUp.ts
|
|
@@ -5756,23 +5762,24 @@ var stepUpPlugin = ({
|
|
|
5756
5762
|
}).use(sessionStore()).guard({
|
|
5757
5763
|
cookie: t5.Cookie({ user_session_id: userSessionIdTypebox }),
|
|
5758
5764
|
schema: "merge"
|
|
5759
|
-
}).derive(({ store: { session }, cookie: { user_session_id }, status }) =>
|
|
5760
|
-
requireRecentAuth
|
|
5765
|
+
}).derive(({ store: { session }, cookie: { user_session_id }, status }) => {
|
|
5766
|
+
const requireRecentAuth = (maxAgeMs, handleAuth, handleAuthFail) => loadSessionFromSource({
|
|
5761
5767
|
authSessionStore,
|
|
5762
5768
|
session,
|
|
5763
5769
|
userSessionId: user_session_id.value
|
|
5764
|
-
}).then((userSession) => {
|
|
5770
|
+
}).then(async (userSession) => {
|
|
5765
5771
|
const authenticatedAt = userSession?.authenticatedAt;
|
|
5766
5772
|
const isRecent = authenticatedAt !== undefined && Date.now() - authenticatedAt <= maxAgeMs;
|
|
5767
5773
|
if (!userSession || !isRecent) {
|
|
5768
|
-
return handleAuthFail?.({
|
|
5774
|
+
return await handleAuthFail?.({
|
|
5769
5775
|
code: "Unauthorized",
|
|
5770
5776
|
message: "Recent authentication required"
|
|
5771
5777
|
}) ?? status("Unauthorized", "Recent authentication required");
|
|
5772
5778
|
}
|
|
5773
5779
|
return handleAuth(userSession.user);
|
|
5774
|
-
})
|
|
5775
|
-
}
|
|
5780
|
+
});
|
|
5781
|
+
return { requireRecentAuth };
|
|
5782
|
+
}).as("global");
|
|
5776
5783
|
|
|
5777
5784
|
// src/oidc/socketTickets.ts
|
|
5778
5785
|
init_crypto();
|
|
@@ -35326,7 +35333,7 @@ var linkedProviderBindingsTable = pgTable("linked_provider_bindings", {
|
|
|
35326
35333
|
available_scopes: jsonb("available_scopes").$type().notNull().default([]),
|
|
35327
35334
|
capabilities: jsonb("capabilities").$type().default([]),
|
|
35328
35335
|
connector_provider: varchar("connector_provider", { length: 64 }).notNull(),
|
|
35329
|
-
created_at: timestamp("created_at").notNull().defaultNow(),
|
|
35336
|
+
created_at: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
35330
35337
|
email: varchar("email", { length: 320 }),
|
|
35331
35338
|
external_account_id: varchar("external_account_id", {
|
|
35332
35339
|
length: 255
|
|
@@ -35339,18 +35346,18 @@ var linkedProviderBindingsTable = pgTable("linked_provider_bindings", {
|
|
|
35339
35346
|
label: varchar("label", { length: 255 }),
|
|
35340
35347
|
metadata: jsonb("metadata").$type().default({}),
|
|
35341
35348
|
status: varchar("status", { length: 64 }).$type().notNull(),
|
|
35342
|
-
updated_at: timestamp("updated_at").notNull().defaultNow(),
|
|
35349
|
+
updated_at: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
|
|
35343
35350
|
username: varchar("username", { length: 255 })
|
|
35344
35351
|
});
|
|
35345
35352
|
var linkedProviderGrantsTable = pgTable("linked_provider_grants", {
|
|
35346
35353
|
access_token_ciphertext: text("access_token_ciphertext"),
|
|
35347
35354
|
auth_provider_key: varchar("auth_provider_key", { length: 64 }).notNull(),
|
|
35348
|
-
created_at: timestamp("created_at").notNull().defaultNow(),
|
|
35349
|
-
expires_at: timestamp("expires_at"),
|
|
35355
|
+
created_at: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
35356
|
+
expires_at: timestamp("expires_at", { withTimezone: true }),
|
|
35350
35357
|
granted_scopes: jsonb("granted_scopes").$type().notNull().default([]),
|
|
35351
35358
|
id: varchar("id", { length: 255 }).primaryKey(),
|
|
35352
35359
|
last_refresh_error: text("last_refresh_error"),
|
|
35353
|
-
last_refreshed_at: timestamp("last_refreshed_at"),
|
|
35360
|
+
last_refreshed_at: timestamp("last_refreshed_at", { withTimezone: true }),
|
|
35354
35361
|
metadata: jsonb("metadata").$type().default({}),
|
|
35355
35362
|
owner_ref: varchar("owner_ref", { length: 255 }).notNull(),
|
|
35356
35363
|
provider_family: varchar("provider_family", { length: 64 }).notNull(),
|
|
@@ -35358,7 +35365,7 @@ var linkedProviderGrantsTable = pgTable("linked_provider_grants", {
|
|
|
35358
35365
|
refresh_token_ciphertext: text("refresh_token_ciphertext"),
|
|
35359
35366
|
status: varchar("status", { length: 64 }).$type().notNull(),
|
|
35360
35367
|
token_type: varchar("token_type", { length: 64 }),
|
|
35361
|
-
updated_at: timestamp("updated_at").notNull().defaultNow()
|
|
35368
|
+
updated_at: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow()
|
|
35362
35369
|
});
|
|
35363
35370
|
var toTimestamp = (value) => value === undefined ? null : new Date(value);
|
|
35364
35371
|
var fromTimestamp = (value) => value === null ? undefined : value.getTime();
|
|
@@ -40793,7 +40800,12 @@ var renderChunk = (chunk) => {
|
|
|
40793
40800
|
return "";
|
|
40794
40801
|
};
|
|
40795
40802
|
var formatSqlTemplate = (value) => value.queryChunks.map(renderChunk).join("");
|
|
40796
|
-
var
|
|
40803
|
+
var columnSqlType = (column) => {
|
|
40804
|
+
const dimensions = Reflect.get(column, "dimensions");
|
|
40805
|
+
const elementType = column.getSQLType();
|
|
40806
|
+
return typeof dimensions === "number" && dimensions > 0 ? `${elementType}${"[]".repeat(dimensions)}` : elementType;
|
|
40807
|
+
};
|
|
40808
|
+
var formatScalarDefault = (value) => {
|
|
40797
40809
|
if (value === null || value === undefined)
|
|
40798
40810
|
return "NULL";
|
|
40799
40811
|
if (is(value, SQL))
|
|
@@ -40804,15 +40816,17 @@ var formatDefault = (value) => {
|
|
|
40804
40816
|
return value ? "true" : "false";
|
|
40805
40817
|
if (typeof value === "number")
|
|
40806
40818
|
return String(value);
|
|
40807
|
-
if (
|
|
40819
|
+
if (typeof value === "object") {
|
|
40808
40820
|
return `'${JSON.stringify(value)}'::jsonb`;
|
|
40809
40821
|
}
|
|
40810
40822
|
return String(value);
|
|
40811
40823
|
};
|
|
40812
|
-
var
|
|
40824
|
+
var formatArrayDefault = (values) => `ARRAY[${values.map((value) => Array.isArray(value) ? formatArrayDefault(value) : formatScalarDefault(value)).join(", ")}]`;
|
|
40825
|
+
var formatDefault = (column, value) => {
|
|
40813
40826
|
const dimensions = Reflect.get(column, "dimensions");
|
|
40814
|
-
|
|
40815
|
-
|
|
40827
|
+
if (Array.isArray(value) && typeof dimensions === "number" && dimensions > 0)
|
|
40828
|
+
return `${formatArrayDefault(value)}::${columnSqlType(column)}`;
|
|
40829
|
+
return formatScalarDefault(value);
|
|
40816
40830
|
};
|
|
40817
40831
|
var columnSql = (column) => {
|
|
40818
40832
|
const parts = [`"${column.name}"`, columnSqlType(column)];
|
|
@@ -40821,7 +40835,7 @@ var columnSql = (column) => {
|
|
|
40821
40835
|
if (column.notNull && !column.primary)
|
|
40822
40836
|
parts.push("NOT NULL");
|
|
40823
40837
|
if (column.hasDefault && column.default !== undefined) {
|
|
40824
|
-
parts.push(`DEFAULT ${formatDefault(column.default)}`);
|
|
40838
|
+
parts.push(`DEFAULT ${formatDefault(column, column.default)}`);
|
|
40825
40839
|
}
|
|
40826
40840
|
if (column.isUnique)
|
|
40827
40841
|
parts.push("UNIQUE");
|
|
@@ -42071,5 +42085,5 @@ export {
|
|
|
42071
42085
|
userSessionIdTypebox
|
|
42072
42086
|
};
|
|
42073
42087
|
|
|
42074
|
-
//# debugId=
|
|
42088
|
+
//# debugId=2F4B37C045D05FBC64756E2164756E21
|
|
42075
42089
|
//# sourceMappingURL=server.js.map
|