@absolutejs/auth 0.77.0 → 0.77.1

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
@@ -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: async (requiredScopes, handleAuth, handleAuthFail) => {
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
- })).as("global");
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: (check, handleAuth, handleAuthFail) => getStatusFromSource({
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
- })).as("global");
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
- authPrincipal,
4734
- protectRoute: (handleAuth, handleAuthFail) => {
4735
- const user = authPrincipal?.user;
4736
- const { error } = sessionStatus;
4737
- if (error) {
4738
- if (user)
4739
- return handleAuth(user);
4740
- return handleAuthFail?.(error) ?? status(error.code, error.message);
4741
- }
4742
- if (!user) {
4743
- return handleAuthFail?.({
4744
- code: "Unauthorized",
4745
- message: "User is not authenticated"
4746
- }) ?? status("Unauthorized", "User is not authenticated");
4747
- }
4748
- return handleAuth(user);
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);
4749
4747
  }
4748
+ if (!user) {
4749
+ return await handleAuthFail?.({
4750
+ code: "Unauthorized",
4751
+ message: "User is not authenticated"
4752
+ }) ?? status("Unauthorized", "User is not authenticated");
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: (maxAgeMs, handleAuth, handleAuthFail) => loadSessionFromSource({
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
- })).as("global");
4784
+ });
4785
+ return { requireRecentAuth };
4786
+ }).as("global");
4780
4787
 
4781
4788
  // src/oidc/socketTickets.ts
4782
4789
  init_crypto();
@@ -39797,7 +39804,12 @@ var renderChunk = (chunk) => {
39797
39804
  return "";
39798
39805
  };
39799
39806
  var formatSqlTemplate = (value) => value.queryChunks.map(renderChunk).join("");
39800
- var formatDefault = (value) => {
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 (Array.isArray(value) || typeof value === "object") {
39823
+ if (typeof value === "object") {
39812
39824
  return `'${JSON.stringify(value)}'::jsonb`;
39813
39825
  }
39814
39826
  return String(value);
39815
39827
  };
39816
- var columnSqlType = (column) => {
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
- const elementType = column.getSQLType();
39819
- return typeof dimensions === "number" && dimensions > 0 ? `${elementType}${"[]".repeat(dimensions)}` : elementType;
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=D2745F53605E4E1E64756E2164756E21
41448
+ //# debugId=DEC787FA4F1E8D6464756E2164756E21
41435
41449
  //# sourceMappingURL=index.js.map