@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
package/dist/index.js
CHANGED
|
@@ -3372,8 +3372,8 @@ var failureResponse = (config, failure, requiredScopes) => new Response(JSON.str
|
|
|
3372
3372
|
var agentAuthContextPlugin = (config) => new Elysia2({
|
|
3373
3373
|
name: "@absolutejs/auth/agent-context",
|
|
3374
3374
|
seed: pluginDependencySeed(config)
|
|
3375
|
-
}).derive(({ request }) =>
|
|
3376
|
-
protectAgent
|
|
3375
|
+
}).derive(({ request }) => {
|
|
3376
|
+
const protectAgent = async (requiredScopes, handleAuth, handleAuthFail) => {
|
|
3377
3377
|
if (config === undefined) {
|
|
3378
3378
|
const failure = {
|
|
3379
3379
|
code: "Unauthorized",
|
|
@@ -3399,8 +3399,9 @@ var agentAuthContextPlugin = (config) => new Elysia2({
|
|
|
3399
3399
|
return await handleAuthFail?.(failure) ?? failureResponse(config, failure, requiredScopes);
|
|
3400
3400
|
}
|
|
3401
3401
|
return handleAuth(principal);
|
|
3402
|
-
}
|
|
3403
|
-
}
|
|
3402
|
+
};
|
|
3403
|
+
return { protectAgent };
|
|
3404
|
+
}).as("global");
|
|
3404
3405
|
|
|
3405
3406
|
// src/agents/oauthGuide.ts
|
|
3406
3407
|
var DEFAULT_GUIDE_ROUTE = "/auth.md";
|
|
@@ -4611,17 +4612,17 @@ var protectPermissionPlugin = ({
|
|
|
4611
4612
|
}).use(sessionStore()).guard({
|
|
4612
4613
|
cookie: t3.Cookie({ user_session_id: userSessionIdTypebox }),
|
|
4613
4614
|
schema: "merge"
|
|
4614
|
-
}).derive(({ store: { session }, cookie: { user_session_id }, status }) =>
|
|
4615
|
-
protectPermission
|
|
4615
|
+
}).derive(({ store: { session }, cookie: { user_session_id }, status }) => {
|
|
4616
|
+
const protectPermission = (check, handleAuth, handleAuthFail) => getStatusFromSource({
|
|
4616
4617
|
authSessionStore,
|
|
4617
4618
|
session,
|
|
4618
4619
|
user_session_id
|
|
4619
4620
|
}).then(async ({ user, error }) => {
|
|
4620
4621
|
if (error) {
|
|
4621
|
-
return handleAuthFail?.(error) ?? status(error.code, error.message);
|
|
4622
|
+
return await handleAuthFail?.(error) ?? status(error.code, error.message);
|
|
4622
4623
|
}
|
|
4623
4624
|
if (!user) {
|
|
4624
|
-
return handleAuthFail?.({
|
|
4625
|
+
return await handleAuthFail?.({
|
|
4625
4626
|
code: "Unauthorized",
|
|
4626
4627
|
message: "User is not authenticated"
|
|
4627
4628
|
}) ?? status("Unauthorized", "User is not authenticated");
|
|
@@ -4638,14 +4639,15 @@ var protectPermissionPlugin = ({
|
|
|
4638
4639
|
organizationId: check.organizationId,
|
|
4639
4640
|
type: "authorization_denied"
|
|
4640
4641
|
});
|
|
4641
|
-
return handleAuthFail?.({
|
|
4642
|
+
return await handleAuthFail?.({
|
|
4642
4643
|
code: "Forbidden",
|
|
4643
4644
|
message: "Insufficient permissions"
|
|
4644
4645
|
}) ?? status("Forbidden", "Insufficient permissions");
|
|
4645
4646
|
}
|
|
4646
4647
|
return handleAuth(user);
|
|
4647
|
-
})
|
|
4648
|
-
}
|
|
4648
|
+
});
|
|
4649
|
+
return { protectPermission };
|
|
4650
|
+
}).as("global");
|
|
4649
4651
|
|
|
4650
4652
|
// src/routes/protectRoute.ts
|
|
4651
4653
|
import { Elysia as Elysia6, t as t4 } from "elysia";
|
|
@@ -4709,8 +4711,7 @@ var protectRoutePlugin = ({
|
|
|
4709
4711
|
}).derive(async ({
|
|
4710
4712
|
store: { session },
|
|
4711
4713
|
cookie: { user_session_id },
|
|
4712
|
-
headers
|
|
4713
|
-
status
|
|
4714
|
+
headers
|
|
4714
4715
|
}) => {
|
|
4715
4716
|
const sessionStatus = await getStatusFromSource({
|
|
4716
4717
|
authSessionStore,
|
|
@@ -4729,25 +4730,30 @@ var protectRoutePlugin = ({
|
|
|
4729
4730
|
authorization: headers.authorization,
|
|
4730
4731
|
config: accessTokens
|
|
4731
4732
|
});
|
|
4732
|
-
return {
|
|
4733
|
-
|
|
4734
|
-
|
|
4735
|
-
|
|
4736
|
-
|
|
4737
|
-
|
|
4738
|
-
|
|
4739
|
-
|
|
4740
|
-
|
|
4741
|
-
|
|
4742
|
-
|
|
4743
|
-
|
|
4744
|
-
|
|
4745
|
-
|
|
4746
|
-
|
|
4747
|
-
|
|
4748
|
-
return
|
|
4733
|
+
return { absoluteAuthStatus: sessionStatus, authPrincipal };
|
|
4734
|
+
}).derive(({ absoluteAuthStatus, authPrincipal, status }) => {
|
|
4735
|
+
const protectRoute = async (handleAuth, handleAuthFail) => {
|
|
4736
|
+
if (!absoluteAuthStatus)
|
|
4737
|
+
return await handleAuthFail?.({
|
|
4738
|
+
code: "Unauthorized",
|
|
4739
|
+
message: "User is not authenticated"
|
|
4740
|
+
}) ?? status("Unauthorized", "User is not authenticated");
|
|
4741
|
+
const user = authPrincipal?.user;
|
|
4742
|
+
const { error } = absoluteAuthStatus;
|
|
4743
|
+
if (error) {
|
|
4744
|
+
if (user)
|
|
4745
|
+
return handleAuth(user);
|
|
4746
|
+
return await handleAuthFail?.(error) ?? status(error.code, error.message);
|
|
4747
|
+
}
|
|
4748
|
+
if (!user) {
|
|
4749
|
+
return await handleAuthFail?.({
|
|
4750
|
+
code: "Unauthorized",
|
|
4751
|
+
message: "User is not authenticated"
|
|
4752
|
+
}) ?? status("Unauthorized", "User is not authenticated");
|
|
4749
4753
|
}
|
|
4754
|
+
return handleAuth(user);
|
|
4750
4755
|
};
|
|
4756
|
+
return { protectRoute };
|
|
4751
4757
|
}).as("global");
|
|
4752
4758
|
|
|
4753
4759
|
// src/routes/stepUp.ts
|
|
@@ -4760,23 +4766,24 @@ var stepUpPlugin = ({
|
|
|
4760
4766
|
}).use(sessionStore()).guard({
|
|
4761
4767
|
cookie: t5.Cookie({ user_session_id: userSessionIdTypebox }),
|
|
4762
4768
|
schema: "merge"
|
|
4763
|
-
}).derive(({ store: { session }, cookie: { user_session_id }, status }) =>
|
|
4764
|
-
requireRecentAuth
|
|
4769
|
+
}).derive(({ store: { session }, cookie: { user_session_id }, status }) => {
|
|
4770
|
+
const requireRecentAuth = (maxAgeMs, handleAuth, handleAuthFail) => loadSessionFromSource({
|
|
4765
4771
|
authSessionStore,
|
|
4766
4772
|
session,
|
|
4767
4773
|
userSessionId: user_session_id.value
|
|
4768
|
-
}).then((userSession) => {
|
|
4774
|
+
}).then(async (userSession) => {
|
|
4769
4775
|
const authenticatedAt = userSession?.authenticatedAt;
|
|
4770
4776
|
const isRecent = authenticatedAt !== undefined && Date.now() - authenticatedAt <= maxAgeMs;
|
|
4771
4777
|
if (!userSession || !isRecent) {
|
|
4772
|
-
return handleAuthFail?.({
|
|
4778
|
+
return await handleAuthFail?.({
|
|
4773
4779
|
code: "Unauthorized",
|
|
4774
4780
|
message: "Recent authentication required"
|
|
4775
4781
|
}) ?? status("Unauthorized", "Recent authentication required");
|
|
4776
4782
|
}
|
|
4777
4783
|
return handleAuth(userSession.user);
|
|
4778
|
-
})
|
|
4779
|
-
}
|
|
4784
|
+
});
|
|
4785
|
+
return { requireRecentAuth };
|
|
4786
|
+
}).as("global");
|
|
4780
4787
|
|
|
4781
4788
|
// src/oidc/socketTickets.ts
|
|
4782
4789
|
init_crypto();
|
|
@@ -34330,7 +34337,7 @@ var linkedProviderBindingsTable = pgTable("linked_provider_bindings", {
|
|
|
34330
34337
|
available_scopes: jsonb("available_scopes").$type().notNull().default([]),
|
|
34331
34338
|
capabilities: jsonb("capabilities").$type().default([]),
|
|
34332
34339
|
connector_provider: varchar("connector_provider", { length: 64 }).notNull(),
|
|
34333
|
-
created_at: timestamp("created_at").notNull().defaultNow(),
|
|
34340
|
+
created_at: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
34334
34341
|
email: varchar("email", { length: 320 }),
|
|
34335
34342
|
external_account_id: varchar("external_account_id", {
|
|
34336
34343
|
length: 255
|
|
@@ -34343,18 +34350,18 @@ var linkedProviderBindingsTable = pgTable("linked_provider_bindings", {
|
|
|
34343
34350
|
label: varchar("label", { length: 255 }),
|
|
34344
34351
|
metadata: jsonb("metadata").$type().default({}),
|
|
34345
34352
|
status: varchar("status", { length: 64 }).$type().notNull(),
|
|
34346
|
-
updated_at: timestamp("updated_at").notNull().defaultNow(),
|
|
34353
|
+
updated_at: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
|
|
34347
34354
|
username: varchar("username", { length: 255 })
|
|
34348
34355
|
});
|
|
34349
34356
|
var linkedProviderGrantsTable = pgTable("linked_provider_grants", {
|
|
34350
34357
|
access_token_ciphertext: text("access_token_ciphertext"),
|
|
34351
34358
|
auth_provider_key: varchar("auth_provider_key", { length: 64 }).notNull(),
|
|
34352
|
-
created_at: timestamp("created_at").notNull().defaultNow(),
|
|
34353
|
-
expires_at: timestamp("expires_at"),
|
|
34359
|
+
created_at: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
34360
|
+
expires_at: timestamp("expires_at", { withTimezone: true }),
|
|
34354
34361
|
granted_scopes: jsonb("granted_scopes").$type().notNull().default([]),
|
|
34355
34362
|
id: varchar("id", { length: 255 }).primaryKey(),
|
|
34356
34363
|
last_refresh_error: text("last_refresh_error"),
|
|
34357
|
-
last_refreshed_at: timestamp("last_refreshed_at"),
|
|
34364
|
+
last_refreshed_at: timestamp("last_refreshed_at", { withTimezone: true }),
|
|
34358
34365
|
metadata: jsonb("metadata").$type().default({}),
|
|
34359
34366
|
owner_ref: varchar("owner_ref", { length: 255 }).notNull(),
|
|
34360
34367
|
provider_family: varchar("provider_family", { length: 64 }).notNull(),
|
|
@@ -34362,7 +34369,7 @@ var linkedProviderGrantsTable = pgTable("linked_provider_grants", {
|
|
|
34362
34369
|
refresh_token_ciphertext: text("refresh_token_ciphertext"),
|
|
34363
34370
|
status: varchar("status", { length: 64 }).$type().notNull(),
|
|
34364
34371
|
token_type: varchar("token_type", { length: 64 }),
|
|
34365
|
-
updated_at: timestamp("updated_at").notNull().defaultNow()
|
|
34372
|
+
updated_at: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow()
|
|
34366
34373
|
});
|
|
34367
34374
|
var toTimestamp = (value) => value === undefined ? null : new Date(value);
|
|
34368
34375
|
var fromTimestamp = (value) => value === null ? undefined : value.getTime();
|
|
@@ -39797,7 +39804,12 @@ var renderChunk = (chunk) => {
|
|
|
39797
39804
|
return "";
|
|
39798
39805
|
};
|
|
39799
39806
|
var formatSqlTemplate = (value) => value.queryChunks.map(renderChunk).join("");
|
|
39800
|
-
var
|
|
39807
|
+
var columnSqlType = (column) => {
|
|
39808
|
+
const dimensions = Reflect.get(column, "dimensions");
|
|
39809
|
+
const elementType = column.getSQLType();
|
|
39810
|
+
return typeof dimensions === "number" && dimensions > 0 ? `${elementType}${"[]".repeat(dimensions)}` : elementType;
|
|
39811
|
+
};
|
|
39812
|
+
var formatScalarDefault = (value) => {
|
|
39801
39813
|
if (value === null || value === undefined)
|
|
39802
39814
|
return "NULL";
|
|
39803
39815
|
if (is(value, SQL))
|
|
@@ -39808,15 +39820,17 @@ var formatDefault = (value) => {
|
|
|
39808
39820
|
return value ? "true" : "false";
|
|
39809
39821
|
if (typeof value === "number")
|
|
39810
39822
|
return String(value);
|
|
39811
|
-
if (
|
|
39823
|
+
if (typeof value === "object") {
|
|
39812
39824
|
return `'${JSON.stringify(value)}'::jsonb`;
|
|
39813
39825
|
}
|
|
39814
39826
|
return String(value);
|
|
39815
39827
|
};
|
|
39816
|
-
var
|
|
39828
|
+
var formatArrayDefault = (values) => `ARRAY[${values.map((value) => Array.isArray(value) ? formatArrayDefault(value) : formatScalarDefault(value)).join(", ")}]`;
|
|
39829
|
+
var formatDefault = (column, value) => {
|
|
39817
39830
|
const dimensions = Reflect.get(column, "dimensions");
|
|
39818
|
-
|
|
39819
|
-
|
|
39831
|
+
if (Array.isArray(value) && typeof dimensions === "number" && dimensions > 0)
|
|
39832
|
+
return `${formatArrayDefault(value)}::${columnSqlType(column)}`;
|
|
39833
|
+
return formatScalarDefault(value);
|
|
39820
39834
|
};
|
|
39821
39835
|
var columnSql = (column) => {
|
|
39822
39836
|
const parts = [`"${column.name}"`, columnSqlType(column)];
|
|
@@ -39825,7 +39839,7 @@ var columnSql = (column) => {
|
|
|
39825
39839
|
if (column.notNull && !column.primary)
|
|
39826
39840
|
parts.push("NOT NULL");
|
|
39827
39841
|
if (column.hasDefault && column.default !== undefined) {
|
|
39828
|
-
parts.push(`DEFAULT ${formatDefault(column.default)}`);
|
|
39842
|
+
parts.push(`DEFAULT ${formatDefault(column, column.default)}`);
|
|
39829
39843
|
}
|
|
39830
39844
|
if (column.isUnique)
|
|
39831
39845
|
parts.push("UNIQUE");
|
|
@@ -41431,5 +41445,5 @@ export {
|
|
|
41431
41445
|
writeWarrant
|
|
41432
41446
|
};
|
|
41433
41447
|
|
|
41434
|
-
//# debugId=
|
|
41448
|
+
//# debugId=ED19DD93253BFAE664756E2164756E21
|
|
41435
41449
|
//# sourceMappingURL=index.js.map
|