@absolutejs/auth 0.55.0 → 0.55.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/README.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Absolute Auth
2
2
 
3
+ Server applications should import the primary authentication contract from
4
+ `@absolutejs/auth/server`. This declaration-stable entry point exposes `auth`,
5
+ session types, route protection, provider configuration, and the other core
6
+ server utilities without loading declarations for every optional Auth feature.
7
+ The root entry point remains available for applications that need the complete
8
+ feature export surface.
9
+
3
10
  ## Overview
4
11
 
5
12
  Absolute Auth is a TypeScript-based authentication system that provides a comprehensive solution for handling user authentication in web applications. It supports multiple authentication providers and offers features such as authorization, callback handling, token refresh, token revocation, and session management.
@@ -1425,10 +1425,16 @@ var resolveAgentPrincipal = async (request, config) => {
1425
1425
  };
1426
1426
  // src/agents/routes.ts
1427
1427
  import { Elysia } from "elysia";
1428
+ var DELETE_CODE_POINT = 127;
1429
+ var HTTP_BAD_REQUEST = 400;
1430
+ var HTTP_FORBIDDEN = 403;
1431
+ var HTTP_OK = 200;
1432
+ var HTTP_UNAUTHORIZED = 401;
1433
+ var MINIMUM_PRINTABLE_CODE_POINT = 32;
1428
1434
  var quoteHeaderValue = (value) => {
1429
1435
  const printable = [...value].filter((character) => {
1430
1436
  const codePoint = character.codePointAt(0) ?? 0;
1431
- return codePoint >= 32 && codePoint !== 127;
1437
+ return codePoint >= MINIMUM_PRINTABLE_CODE_POINT && codePoint !== DELETE_CODE_POINT;
1432
1438
  }).join("");
1433
1439
  return `"${printable.replace(/[\\"]/g, "\\$&")}"`;
1434
1440
  };
@@ -1461,9 +1467,9 @@ var failureResponse = (config, failure, requiredScopes) => new Response(JSON.str
1461
1467
  requiredScopes
1462
1468
  })
1463
1469
  },
1464
- status: failure.code === "Forbidden" ? 403 : 401
1470
+ status: failure.code === "Forbidden" ? HTTP_FORBIDDEN : HTTP_UNAUTHORIZED
1465
1471
  });
1466
- var json = (value, status = 200) => new Response(JSON.stringify(value), {
1472
+ var json = (value, status = HTTP_OK) => new Response(JSON.stringify(value), {
1467
1473
  headers: {
1468
1474
  "cache-control": "no-store",
1469
1475
  "content-type": "application/json"
@@ -1497,7 +1503,7 @@ var registrationResponse = (result) => {
1497
1503
  ...body,
1498
1504
  error: "interaction_required",
1499
1505
  error_description: "Authenticate at the service and confirm the account link."
1500
- }, 401);
1506
+ }, HTTP_UNAUTHORIZED);
1501
1507
  }
1502
1508
  return json(body);
1503
1509
  };
@@ -1524,34 +1530,35 @@ var parseRegistrationInput = (value) => {
1524
1530
  return input;
1525
1531
  };
1526
1532
  var escapeHtml = (value) => value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;");
1527
- var agentAuthPlugin = (config) => {
1528
- const plugin = new Elysia().derive(({ request }) => ({
1529
- protectAgent: async (requiredScopes, handleAuth, handleAuthFail) => {
1530
- if (config === undefined) {
1531
- const failure = {
1532
- code: "Unauthorized",
1533
- message: "Agent is not authenticated"
1534
- };
1535
- return await handleAuthFail?.(failure) ?? new Response(failure.message, { status: 401 });
1536
- }
1537
- const principal = await resolveAgentPrincipal(request, config);
1538
- if (principal === undefined) {
1539
- const failure = {
1540
- code: "Unauthorized",
1541
- message: "Agent is not authenticated"
1542
- };
1543
- return await handleAuthFail?.(failure) ?? failureResponse(config, failure, requiredScopes);
1544
- }
1545
- if (!agentHasScopes(principal, requiredScopes)) {
1546
- const failure = {
1547
- code: "Forbidden",
1548
- message: "Insufficient agent scopes"
1549
- };
1550
- return await handleAuthFail?.(failure) ?? failureResponse(config, failure, requiredScopes);
1551
- }
1552
- return handleAuth(principal);
1533
+ var agentAuthContextPlugin = (config) => new Elysia().derive(({ request }) => ({
1534
+ protectAgent: async (requiredScopes, handleAuth, handleAuthFail) => {
1535
+ if (config === undefined) {
1536
+ const failure = {
1537
+ code: "Unauthorized",
1538
+ message: "Agent is not authenticated"
1539
+ };
1540
+ return await handleAuthFail?.(failure) ?? new Response(failure.message, { status: 401 });
1553
1541
  }
1554
- }));
1542
+ const principal = await resolveAgentPrincipal(request, config);
1543
+ if (principal === undefined) {
1544
+ const failure = {
1545
+ code: "Unauthorized",
1546
+ message: "Agent is not authenticated"
1547
+ };
1548
+ return await handleAuthFail?.(failure) ?? failureResponse(config, failure, requiredScopes);
1549
+ }
1550
+ if (!agentHasScopes(principal, requiredScopes)) {
1551
+ const failure = {
1552
+ code: "Forbidden",
1553
+ message: "Insufficient agent scopes"
1554
+ };
1555
+ return await handleAuthFail?.(failure) ?? failureResponse(config, failure, requiredScopes);
1556
+ }
1557
+ return handleAuth(principal);
1558
+ }
1559
+ }));
1560
+ var agentAuthPlugin = (config) => {
1561
+ const plugin = agentAuthContextPlugin(config);
1555
1562
  if (config === undefined)
1556
1563
  return plugin.as("global");
1557
1564
  if (config.agentRegistration === undefined) {
@@ -1582,11 +1589,11 @@ var agentAuthPlugin = (config) => {
1582
1589
  }).post(identityRoute, async ({ body }) => {
1583
1590
  const value = recordBody(body);
1584
1591
  if (value === undefined || typeof value.type !== "string") {
1585
- return json({ error: "invalid_request" }, 400);
1592
+ return json({ error: "invalid_request" }, HTTP_BAD_REQUEST);
1586
1593
  }
1587
1594
  const input = parseRegistrationInput(value);
1588
1595
  if (input === undefined)
1589
- return json({ error: "invalid_request" }, 400);
1596
+ return json({ error: "invalid_request" }, HTTP_BAD_REQUEST);
1590
1597
  const result = await startAgentRegistration(config, input);
1591
1598
  if ("error" in result) {
1592
1599
  return json({
@@ -1598,7 +1605,7 @@ var agentAuthPlugin = (config) => {
1598
1605
  }).post(claimRoute, async ({ body }) => {
1599
1606
  const value = recordBody(body);
1600
1607
  if (value === undefined || typeof value.claim_token !== "string" || typeof value.email !== "string") {
1601
- return json({ error: "invalid_request" }, 400);
1608
+ return json({ error: "invalid_request" }, HTTP_BAD_REQUEST);
1602
1609
  }
1603
1610
  const result = await beginAgentClaim(config, {
1604
1611
  claimToken: value.claim_token,
@@ -1613,7 +1620,7 @@ var agentAuthPlugin = (config) => {
1613
1620
  value = Object.fromEntries(new URLSearchParams(body));
1614
1621
  }
1615
1622
  if (value === undefined || typeof value.claim_attempt_token !== "string" || typeof value.user_code !== "string") {
1616
- return json({ error: "invalid_request" }, 400);
1623
+ return json({ error: "invalid_request" }, HTTP_BAD_REQUEST);
1617
1624
  }
1618
1625
  const result = await completeAgentClaim(config, {
1619
1626
  attemptToken: value.claim_attempt_token,
@@ -12826,5 +12833,5 @@ export {
12826
12833
  AGENT_CLAIM_GRANT_TYPE
12827
12834
  };
12828
12835
 
12829
- //# debugId=4AABAB4CBDEE339264756E2164756E21
12836
+ //# debugId=05CB90C7C290284064756E2164756E21
12830
12837
  //# sourceMappingURL=index.js.map