@absolutejs/auth 0.75.4 → 0.75.5

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.
@@ -5,6 +5,10 @@ type AgentAuthFailure = {
5
5
  code: 'Forbidden' | 'Unauthorized';
6
6
  message: 'Agent is not authenticated' | 'Insufficient agent scopes';
7
7
  };
8
+ type ProtectAgent = {
9
+ <AuthReturn, AuthFailReturn = never>(requiredScopes: string[], handleAuth: (principal: AgentPrincipal) => Promise<AuthReturn>, handleAuthFail?: (error: AgentAuthFailure) => AuthFailReturn): Promise<Response | AuthReturn | Awaited<AuthFailReturn>>;
10
+ <AuthReturn, AuthFailReturn = never>(requiredScopes: string[], handleAuth: (principal: AgentPrincipal) => AuthReturn, handleAuthFail?: (error: AgentAuthFailure) => AuthFailReturn): Promise<Response | AuthReturn | Awaited<AuthFailReturn>>;
11
+ };
8
12
  export declare const agentAuthChallenge: ({ config, error, requiredScopes }: {
9
13
  config: AgentAuthConfig;
10
14
  error?: "invalid_token" | "insufficient_scope";
@@ -15,7 +19,7 @@ export declare const agentAuthContextPlugin: (config?: AgentAuthConfig) => Elysi
15
19
  decorator: {};
16
20
  store: {};
17
21
  derive: {
18
- readonly protectAgent: <AuthReturn, AuthFailReturn>(requiredScopes: string[], handleAuth: (principal: AgentPrincipal) => AuthReturn | Promise<AuthReturn>, handleAuthFail?: (error: AgentAuthFailure) => AuthFailReturn | Promise<AuthFailReturn>) => Promise<Response | AuthReturn | NonNullable<Awaited<AuthFailReturn>>>;
22
+ readonly protectAgent: ProtectAgent;
19
23
  };
20
24
  }, {
21
25
  typebox: {};
@@ -27,7 +31,7 @@ export declare const agentAuthContextPlugin: (config?: AgentAuthConfig) => Elysi
27
31
  macroFn: {};
28
32
  parser: {};
29
33
  response: import("elysia/types").ExtractErrorFromHandle<{
30
- readonly protectAgent: <AuthReturn, AuthFailReturn>(requiredScopes: string[], handleAuth: (principal: AgentPrincipal) => AuthReturn | Promise<AuthReturn>, handleAuthFail?: (error: AgentAuthFailure) => AuthFailReturn | Promise<AuthFailReturn>) => Promise<Response | AuthReturn | NonNullable<Awaited<AuthFailReturn>>>;
34
+ readonly protectAgent: ProtectAgent;
31
35
  }>;
32
36
  }, {}, import("elysia/types").DefaultEphemeral, import("elysia/types").DefaultEphemeral>;
33
37
  export {};
@@ -1651,8 +1651,8 @@ var failureResponse = (config, failure, requiredScopes) => new Response(JSON.str
1651
1651
  var agentAuthContextPlugin = (config) => new Elysia({
1652
1652
  name: "@absolutejs/auth/agent-context",
1653
1653
  seed: pluginDependencySeed(config)
1654
- }).derive(({ request }) => ({
1655
- protectAgent: async (requiredScopes, handleAuth, handleAuthFail) => {
1654
+ }).derive(({ request }) => {
1655
+ const protectAgent = async (requiredScopes, handleAuth, handleAuthFail) => {
1656
1656
  if (config === undefined) {
1657
1657
  const failure = {
1658
1658
  code: "Unauthorized",
@@ -1678,8 +1678,9 @@ var agentAuthContextPlugin = (config) => new Elysia({
1678
1678
  return await handleAuthFail?.(failure) ?? failureResponse(config, failure, requiredScopes);
1679
1679
  }
1680
1680
  return handleAuth(principal);
1681
- }
1682
- })).as("global");
1681
+ };
1682
+ return { protectAgent };
1683
+ }).as("global");
1683
1684
  // src/agents/routes.ts
1684
1685
  import { Elysia as Elysia2 } from "elysia";
1685
1686
  var HTTP_BAD_REQUEST = 400;
@@ -13799,5 +13800,5 @@ export {
13799
13800
  AGENT_CLAIM_GRANT_TYPE
13800
13801
  };
13801
13802
 
13802
- //# debugId=16DE04B83F43B7D264756E2164756E21
13803
+ //# debugId=4B045EFCE2BE01EE64756E2164756E21
13803
13804
  //# sourceMappingURL=index.js.map