@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/index.js CHANGED
@@ -3370,8 +3370,8 @@ var failureResponse = (config, failure, requiredScopes) => new Response(JSON.str
3370
3370
  var agentAuthContextPlugin = (config) => new Elysia2({
3371
3371
  name: "@absolutejs/auth/agent-context",
3372
3372
  seed: pluginDependencySeed(config)
3373
- }).derive(({ request }) => ({
3374
- protectAgent: async (requiredScopes, handleAuth, handleAuthFail) => {
3373
+ }).derive(({ request }) => {
3374
+ const protectAgent = async (requiredScopes, handleAuth, handleAuthFail) => {
3375
3375
  if (config === undefined) {
3376
3376
  const failure = {
3377
3377
  code: "Unauthorized",
@@ -3397,8 +3397,9 @@ var agentAuthContextPlugin = (config) => new Elysia2({
3397
3397
  return await handleAuthFail?.(failure) ?? failureResponse(config, failure, requiredScopes);
3398
3398
  }
3399
3399
  return handleAuth(principal);
3400
- }
3401
- })).as("global");
3400
+ };
3401
+ return { protectAgent };
3402
+ }).as("global");
3402
3403
 
3403
3404
  // src/agents/oauthGuide.ts
3404
3405
  var DEFAULT_GUIDE_ROUTE = "/auth.md";
@@ -4609,17 +4610,17 @@ var protectPermissionPlugin = ({
4609
4610
  }).use(sessionStore()).guard({
4610
4611
  cookie: t3.Cookie({ user_session_id: userSessionIdTypebox }),
4611
4612
  schema: "merge"
4612
- }).derive(({ store: { session }, cookie: { user_session_id }, status }) => ({
4613
- protectPermission: (check, handleAuth, handleAuthFail) => getStatusFromSource({
4613
+ }).derive(({ store: { session }, cookie: { user_session_id }, status }) => {
4614
+ const protectPermission = (check, handleAuth, handleAuthFail) => getStatusFromSource({
4614
4615
  authSessionStore,
4615
4616
  session,
4616
4617
  user_session_id
4617
4618
  }).then(async ({ user, error }) => {
4618
4619
  if (error) {
4619
- return handleAuthFail?.(error) ?? status(error.code, error.message);
4620
+ return await handleAuthFail?.(error) ?? status(error.code, error.message);
4620
4621
  }
4621
4622
  if (!user) {
4622
- return handleAuthFail?.({
4623
+ return await handleAuthFail?.({
4623
4624
  code: "Unauthorized",
4624
4625
  message: "User is not authenticated"
4625
4626
  }) ?? status("Unauthorized", "User is not authenticated");
@@ -4636,14 +4637,15 @@ var protectPermissionPlugin = ({
4636
4637
  organizationId: check.organizationId,
4637
4638
  type: "authorization_denied"
4638
4639
  });
4639
- return handleAuthFail?.({
4640
+ return await handleAuthFail?.({
4640
4641
  code: "Forbidden",
4641
4642
  message: "Insufficient permissions"
4642
4643
  }) ?? status("Forbidden", "Insufficient permissions");
4643
4644
  }
4644
4645
  return handleAuth(user);
4645
- })
4646
- })).as("global");
4646
+ });
4647
+ return { protectPermission };
4648
+ }).as("global");
4647
4649
 
4648
4650
  // src/routes/protectRoute.ts
4649
4651
  import { Elysia as Elysia6, t as t4 } from "elysia";
@@ -4707,8 +4709,7 @@ var protectRoutePlugin = ({
4707
4709
  }).derive(async ({
4708
4710
  store: { session },
4709
4711
  cookie: { user_session_id },
4710
- headers,
4711
- status
4712
+ headers
4712
4713
  }) => {
4713
4714
  const sessionStatus = await getStatusFromSource({
4714
4715
  authSessionStore,
@@ -4727,25 +4728,30 @@ var protectRoutePlugin = ({
4727
4728
  authorization: headers.authorization,
4728
4729
  config: accessTokens
4729
4730
  });
4730
- return {
4731
- authPrincipal,
4732
- protectRoute: (handleAuth, handleAuthFail) => {
4733
- const user = authPrincipal?.user;
4734
- const { error } = sessionStatus;
4735
- if (error) {
4736
- if (user)
4737
- return handleAuth(user);
4738
- return handleAuthFail?.(error) ?? status(error.code, error.message);
4739
- }
4740
- if (!user) {
4741
- return handleAuthFail?.({
4742
- code: "Unauthorized",
4743
- message: "User is not authenticated"
4744
- }) ?? status("Unauthorized", "User is not authenticated");
4745
- }
4746
- return handleAuth(user);
4731
+ return { absoluteAuthStatus: sessionStatus, authPrincipal };
4732
+ }).derive(({ absoluteAuthStatus, authPrincipal, status }) => {
4733
+ const protectRoute = async (handleAuth, handleAuthFail) => {
4734
+ if (!absoluteAuthStatus)
4735
+ return await handleAuthFail?.({
4736
+ code: "Unauthorized",
4737
+ message: "User is not authenticated"
4738
+ }) ?? status("Unauthorized", "User is not authenticated");
4739
+ const user = authPrincipal?.user;
4740
+ const { error } = absoluteAuthStatus;
4741
+ if (error) {
4742
+ if (user)
4743
+ return handleAuth(user);
4744
+ return await handleAuthFail?.(error) ?? status(error.code, error.message);
4747
4745
  }
4746
+ if (!user) {
4747
+ return await handleAuthFail?.({
4748
+ code: "Unauthorized",
4749
+ message: "User is not authenticated"
4750
+ }) ?? status("Unauthorized", "User is not authenticated");
4751
+ }
4752
+ return handleAuth(user);
4748
4753
  };
4754
+ return { protectRoute };
4749
4755
  }).as("global");
4750
4756
 
4751
4757
  // src/routes/stepUp.ts
@@ -4758,23 +4764,24 @@ var stepUpPlugin = ({
4758
4764
  }).use(sessionStore()).guard({
4759
4765
  cookie: t5.Cookie({ user_session_id: userSessionIdTypebox }),
4760
4766
  schema: "merge"
4761
- }).derive(({ store: { session }, cookie: { user_session_id }, status }) => ({
4762
- requireRecentAuth: (maxAgeMs, handleAuth, handleAuthFail) => loadSessionFromSource({
4767
+ }).derive(({ store: { session }, cookie: { user_session_id }, status }) => {
4768
+ const requireRecentAuth = (maxAgeMs, handleAuth, handleAuthFail) => loadSessionFromSource({
4763
4769
  authSessionStore,
4764
4770
  session,
4765
4771
  userSessionId: user_session_id.value
4766
- }).then((userSession) => {
4772
+ }).then(async (userSession) => {
4767
4773
  const authenticatedAt = userSession?.authenticatedAt;
4768
4774
  const isRecent = authenticatedAt !== undefined && Date.now() - authenticatedAt <= maxAgeMs;
4769
4775
  if (!userSession || !isRecent) {
4770
- return handleAuthFail?.({
4776
+ return await handleAuthFail?.({
4771
4777
  code: "Unauthorized",
4772
4778
  message: "Recent authentication required"
4773
4779
  }) ?? status("Unauthorized", "Recent authentication required");
4774
4780
  }
4775
4781
  return handleAuth(userSession.user);
4776
- })
4777
- })).as("global");
4782
+ });
4783
+ return { requireRecentAuth };
4784
+ }).as("global");
4778
4785
 
4779
4786
  // src/oidc/socketTickets.ts
4780
4787
  init_crypto();
@@ -39407,7 +39414,12 @@ var renderChunk = (chunk) => {
39407
39414
  return "";
39408
39415
  };
39409
39416
  var formatSqlTemplate = (value) => value.queryChunks.map(renderChunk).join("");
39410
- var formatDefault = (value) => {
39417
+ var columnSqlType = (column) => {
39418
+ const dimensions = Reflect.get(column, "dimensions");
39419
+ const elementType = column.getSQLType();
39420
+ return typeof dimensions === "number" && dimensions > 0 ? `${elementType}${"[]".repeat(dimensions)}` : elementType;
39421
+ };
39422
+ var formatScalarDefault = (value) => {
39411
39423
  if (value === null || value === undefined)
39412
39424
  return "NULL";
39413
39425
  if (is(value, SQL))
@@ -39418,15 +39430,17 @@ var formatDefault = (value) => {
39418
39430
  return value ? "true" : "false";
39419
39431
  if (typeof value === "number")
39420
39432
  return String(value);
39421
- if (Array.isArray(value) || typeof value === "object") {
39433
+ if (typeof value === "object") {
39422
39434
  return `'${JSON.stringify(value)}'::jsonb`;
39423
39435
  }
39424
39436
  return String(value);
39425
39437
  };
39426
- var columnSqlType = (column) => {
39438
+ var formatArrayDefault = (values) => `ARRAY[${values.map((value) => Array.isArray(value) ? formatArrayDefault(value) : formatScalarDefault(value)).join(", ")}]`;
39439
+ var formatDefault = (column, value) => {
39427
39440
  const dimensions = Reflect.get(column, "dimensions");
39428
- const elementType = column.getSQLType();
39429
- return typeof dimensions === "number" && dimensions > 0 ? `${elementType}${"[]".repeat(dimensions)}` : elementType;
39441
+ if (Array.isArray(value) && typeof dimensions === "number" && dimensions > 0)
39442
+ return `${formatArrayDefault(value)}::${columnSqlType(column)}`;
39443
+ return formatScalarDefault(value);
39430
39444
  };
39431
39445
  var columnSql = (column) => {
39432
39446
  const parts = [`"${column.name}"`, columnSqlType(column)];
@@ -39435,7 +39449,7 @@ var columnSql = (column) => {
39435
39449
  if (column.notNull && !column.primary)
39436
39450
  parts.push("NOT NULL");
39437
39451
  if (column.hasDefault && column.default !== undefined) {
39438
- parts.push(`DEFAULT ${formatDefault(column.default)}`);
39452
+ parts.push(`DEFAULT ${formatDefault(column, column.default)}`);
39439
39453
  }
39440
39454
  if (column.isUnique)
39441
39455
  parts.push("UNIQUE");
@@ -41026,5 +41040,5 @@ export {
41026
41040
  ABSOLUTE_NATIVE_AUTH_CLIENTS_ENV
41027
41041
  };
41028
41042
 
41029
- //# debugId=245E854B8173886A64756E2164756E21
41043
+ //# debugId=6A181AF492FBB0A264756E2164756E21
41030
41044
  //# sourceMappingURL=index.js.map