@axium/server 0.34.3 → 0.35.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/api/acl.js CHANGED
@@ -2,7 +2,7 @@ import * as z from 'zod';
2
2
  import * as acl from '../acl.js';
3
3
  import { error, parseBody, withError } from '../requests.js';
4
4
  import { addRoute } from '../routes.js';
5
- import { checkAuthForItem } from '../auth.js';
5
+ import { authRequestForItem } from '../auth.js';
6
6
  import { AccessControlUpdate, AccessTarget } from '@axium/core';
7
7
  function getTable(itemType) {
8
8
  const tables = acl.listTables();
@@ -23,19 +23,19 @@ addRoute({
23
23
  async PATCH(request, { itemType, itemId }) {
24
24
  const table = getTable(itemType);
25
25
  const { target, permissions } = await parseBody(request, AccessControlUpdate);
26
- await checkAuthForItem(request, itemType, itemId, { manage: true });
26
+ await authRequestForItem(request, itemType, itemId, { manage: true });
27
27
  return await acl.update(table, itemId, target, permissions);
28
28
  },
29
29
  async PUT(request, { itemType, itemId }) {
30
30
  const table = getTable(itemType);
31
31
  const target = await parseBody(request, AccessTarget);
32
- await checkAuthForItem(request, itemType, itemId, { manage: true });
32
+ await authRequestForItem(request, itemType, itemId, { manage: true });
33
33
  return await acl.add(table, itemId, target);
34
34
  },
35
35
  async DELETE(request, { itemType, itemId }) {
36
36
  const table = getTable(itemType);
37
37
  const target = await parseBody(request, AccessTarget);
38
- await checkAuthForItem(request, itemType, itemId, { manage: true });
38
+ await authRequestForItem(request, itemType, itemId, { manage: true });
39
39
  return await acl.remove(table, itemId, target);
40
40
  },
41
41
  });
package/dist/auth.d.ts CHANGED
@@ -41,8 +41,9 @@ export interface ItemAuthResult<TB extends acl.TargetName> {
41
41
  user?: UserInternal;
42
42
  session?: SessionInternal;
43
43
  }
44
+ export declare function authSessionForItem<const TB extends acl.TargetName>(itemType: TB, itemId: string, permissions: Partial<acl.PermissionsFor<`acl.${TB}`>>, session?: SessionAndUser | null): Promise<ItemAuthResult<TB>>;
44
45
  /**
45
46
  * Authenticate a request against an "item" which has an ACL table.
46
47
  * This will fetch the item, ACLs, users, and the authenticating session.
47
48
  */
48
- export declare function checkAuthForItem<const TB extends acl.TargetName>(request: Request, itemType: TB, itemId: string, permissions: Partial<acl.PermissionsFor<`acl.${TB}`>>): Promise<ItemAuthResult<TB>>;
49
+ export declare function authRequestForItem<const TB extends acl.TargetName>(request: Request, itemType: TB, itemId: string, permissions: Partial<acl.PermissionsFor<`acl.${TB}`>>): Promise<ItemAuthResult<TB>>;
package/dist/auth.js CHANGED
@@ -110,15 +110,7 @@ export async function checkAuthForUser(request, userId, sensitive = false) {
110
110
  error(403, 'This token can not be used for sensitive actions');
111
111
  return Object.assign(session, { accessor: session.user });
112
112
  }
113
- /**
114
- * Authenticate a request against an "item" which has an ACL table.
115
- * This will fetch the item, ACLs, users, and the authenticating session.
116
- */
117
- export async function checkAuthForItem(request, itemType, itemId, permissions) {
118
- const token = getToken(request, false);
119
- if (!token)
120
- error(401, 'Missing token');
121
- const session = await getSessionAndUser(token).catch(() => null);
113
+ export async function authSessionForItem(itemType, itemId, permissions, session) {
122
114
  const { userId, user } = session ?? {};
123
115
  // Note: we need to do casting because of TS limitations with generics
124
116
  const item = await db
@@ -152,3 +144,14 @@ export async function checkAuthForItem(request, itemType, itemId, permissions) {
152
144
  error(403, 'Access denied');
153
145
  return result;
154
146
  }
147
+ /**
148
+ * Authenticate a request against an "item" which has an ACL table.
149
+ * This will fetch the item, ACLs, users, and the authenticating session.
150
+ */
151
+ export async function authRequestForItem(request, itemType, itemId, permissions) {
152
+ const token = getToken(request, false);
153
+ if (!token)
154
+ error(401, 'Missing token');
155
+ const session = await getSessionAndUser(token).catch(() => null);
156
+ return await authSessionForItem(itemType, itemId, permissions, session);
157
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axium/server",
3
- "version": "0.34.3",
3
+ "version": "0.35.0",
4
4
  "author": "James Prevett <axium@jamespre.dev>",
5
5
  "funding": {
6
6
  "type": "individual",