@axium/core 0.4.5 → 0.5.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.
@@ -3,11 +3,16 @@
3
3
  "application/json": "brackets-curly",
4
4
  "application/octet-stream": "file",
5
5
  "application/pdf": "file-invoice",
6
- "application/pgp-signature": "file-contract",
6
+ "application/pgp-signature": "file-signature",
7
+ "application/vnd.openxmlformats-officedocument.presentationml.presentation": "file-video",
8
+ "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": "file-spreadsheet",
9
+ "application/vnd.openxmlformats-officedocument.wordprocessingml.document": "file-contract",
7
10
  "application/vnd.rar": "box-archive",
8
11
  "application/x-7z-compressed": "file-zipper",
9
12
  "application/x-bzip": "file-zipper",
10
13
  "application/x-bzip2": "file-zipper",
14
+ "application/x-httpd-php": "brands/php",
15
+ "application/x-javascript": "brands/square-js",
11
16
  "application/x-sh": "square-terminal",
12
17
  "application/x-tar": "box-archive",
13
18
  "application/x-xz": "file-zipper",
@@ -18,12 +23,16 @@
18
23
  "image/gif": "gif",
19
24
  "image/svg+xml": "file-svg",
20
25
  "image/vnd.microsoft.icon": "icons",
26
+ "inode/directory": "folder",
21
27
  "text/css": "css",
22
28
  "text/csv": "file-csv",
23
29
  "text/html": "code",
24
30
  "text/javascript": "brands/square-js",
25
- "application/x-javascript": "brands/square-js",
26
31
  "text/plain": "file-lines",
32
+ "text/rust": "brands/rust",
33
+ "text/x-go": "brands/golang",
34
+ "text/x-php": "brands/php",
35
+ "text/x-sass": "brands/sass",
27
36
  "text/xml": "code",
28
37
  "video": "clapperboard-play"
29
38
  }
@@ -0,0 +1,28 @@
1
+ import type { User } from './user.js';
2
+ export interface AccessControl {
3
+ itemId: string;
4
+ userId: string;
5
+ user?: User;
6
+ createdAt: Date;
7
+ permission: Permission;
8
+ }
9
+ export declare enum Permission {
10
+ None = 0,
11
+ Read = 1,
12
+ Comment = 2,
13
+ Edit = 3,
14
+ Manage = 5
15
+ }
16
+ export declare const permissionNames: {
17
+ 0: string;
18
+ 1: string;
19
+ 2: string;
20
+ 3: string;
21
+ 5: string;
22
+ };
23
+ export interface AccessControllable {
24
+ userId: string;
25
+ publicPermission: Permission;
26
+ acl?: AccessControl[];
27
+ }
28
+ export declare function hasPermission(item: AccessControllable, userId: string | undefined, permission: Permission): boolean;
package/dist/access.js ADDED
@@ -0,0 +1,27 @@
1
+ export var Permission;
2
+ (function (Permission) {
3
+ Permission[Permission["None"] = 0] = "None";
4
+ Permission[Permission["Read"] = 1] = "Read";
5
+ Permission[Permission["Comment"] = 2] = "Comment";
6
+ Permission[Permission["Edit"] = 3] = "Edit";
7
+ Permission[Permission["Manage"] = 5] = "Manage";
8
+ })(Permission || (Permission = {}));
9
+ export const permissionNames = {
10
+ [Permission.None]: 'No Permissions',
11
+ [Permission.Read]: 'Reader',
12
+ [Permission.Comment]: 'Commenter',
13
+ [Permission.Edit]: 'Editor',
14
+ [Permission.Manage]: 'Manager',
15
+ };
16
+ export function hasPermission(item, userId, permission) {
17
+ if (item.publicPermission >= permission)
18
+ return true;
19
+ if (!userId)
20
+ return false;
21
+ if (item.userId == userId)
22
+ return true;
23
+ const entry = item.acl?.find(entry => entry.userId == userId);
24
+ if (!entry)
25
+ return false;
26
+ return entry.permission >= permission;
27
+ }
package/dist/api.d.ts CHANGED
@@ -3,6 +3,7 @@ import type z from 'zod';
3
3
  import type { RequestMethod } from './requests.js';
4
4
  import type { APIUserRegistration, LogoutSessions, PasskeyAuthenticationResponse, PasskeyChangeable, PasskeyRegistration, UserAuthOptions } from './schemas.js';
5
5
  import type { User, UserChangeable, UserPublic } from './user.js';
6
+ import type { AccessControl } from './access.js';
6
7
  export interface Session {
7
8
  id: string;
8
9
  userId: string;
@@ -100,6 +101,12 @@ export interface _apiTypes {
100
101
  id: string;
101
102
  }];
102
103
  };
104
+ 'acl/:itemType/:itemId': {
105
+ PUT: [{
106
+ userId: string;
107
+ permission: number;
108
+ }, AccessControl];
109
+ };
103
110
  }
104
111
  export type Endpoint = keyof _apiTypes;
105
112
  export type APIFunction<Method extends RequestMethod, E extends Endpoint> = Method extends keyof _apiTypes[E] ? _apiTypes[E][Method] extends [infer Body, infer Result] ? (body: Body) => Promise<Result> : () => _apiTypes[E][Method] : unknown;
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export * from './access.js';
1
2
  export * from './api.js';
2
3
  export * as icons from './icons.js';
3
4
  export * from './requests.js';
package/dist/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ export * from './access.js';
1
2
  export * from './api.js';
2
3
  export * as icons from './icons.js';
3
4
  export * from './requests.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axium/core",
3
- "version": "0.4.5",
3
+ "version": "0.5.1",
4
4
  "author": "James Prevett <axium@jamespre.dev> (https://jamespre.dev)",
5
5
  "funding": {
6
6
  "type": "individual",