@axium/client 0.7.0 → 0.8.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.
@@ -0,0 +1,3 @@
1
+ import type { AccessControl, AccessMap } from '@axium/core';
2
+ export declare function setACL(itemType: string, itemId: string, data: AccessMap): Promise<AccessControl[]>;
3
+ export declare function getACL(itemType: string, itemId: string): Promise<AccessControl[]>;
package/dist/access.js ADDED
@@ -0,0 +1,9 @@
1
+ import { fetchAPI } from './requests.js';
2
+ export async function setACL(itemType, itemId, data) {
3
+ if ('public' in data)
4
+ data.public = parseInt(data.public.toString());
5
+ return await fetchAPI('POST', 'acl/:itemType/:itemId', data, itemType, itemId);
6
+ }
7
+ export async function getACL(itemType, itemId) {
8
+ return await fetchAPI('GET', 'acl/:itemType/:itemId', {}, itemType, itemId);
9
+ }
@@ -1,24 +1,37 @@
1
1
  <script lang="ts">
2
- import type { User } from '@axium/core';
3
- import { permissionNames, type AccessControllable } from '@axium/core/access';
2
+ import type { AccessMap, User } from '@axium/core';
3
+ import { permissionNames, type AccessControllable, type AccessControl } from '@axium/core/access';
4
4
  import type { Entries } from 'utilium';
5
5
  import FormDialog from './FormDialog.svelte';
6
6
  import UserCard from './UserCard.svelte';
7
+ import { userInfo } from '@axium/client/user';
8
+ import { getACL, setACL } from '@axium/client/access';
7
9
 
8
- let {
9
- item = $bindable(),
10
- editable,
11
- dialog = $bindable(),
12
- }: { item: Required<AccessControllable> & { name?: string; user: User }; editable: boolean; dialog?: HTMLDialogElement } = $props();
10
+ interface Props {
11
+ editable: boolean;
12
+ dialog?: HTMLDialogElement;
13
+ itemType: string;
14
+ item?: ({ name?: string; user?: User; id: string } & AccessControllable) | null;
15
+ acl?: AccessControl[];
16
+ }
17
+ let { item = $bindable(), itemType, editable, dialog = $bindable(), acl = $bindable(item?.acl) }: Props = $props();
18
+
19
+ if (!acl && item) getACL(itemType, item.id).then(fetched => (acl = item.acl = fetched));
13
20
 
14
21
  const permEntries = Object.entries(permissionNames) as any as Entries<typeof permissionNames>;
15
22
 
16
- const publicPerm = $derived(permissionNames[item.publicPermission]);
23
+ const publicPerm = $derived(permissionNames[item?.publicPermission || 0]);
17
24
  </script>
18
25
 
19
- <FormDialog bind:dialog submitText="Save">
26
+ <FormDialog
27
+ bind:dialog
28
+ submitText="Save"
29
+ submit={async data => {
30
+ if (item) await setACL(itemType, item.id, data as any as AccessMap);
31
+ }}
32
+ >
20
33
  {#snippet header()}
21
- {#if item.name}
34
+ {#if item?.name}
22
35
  <h3>Permissions for <strong>{item.name}</strong></h3>
23
36
  {:else}
24
37
  <h3>Permissions</h3>
@@ -26,18 +39,21 @@
26
39
  {/snippet}
27
40
 
28
41
  <div class="AccessControl">
29
- <UserCard user={item.user} />
42
+ {#if item?.user}
43
+ <UserCard user={item.user} />
44
+ {:else if item}
45
+ {#await userInfo(item.userId) then user}<UserCard {user} />{/await}
46
+ {/if}
30
47
  <span>Owner</span>
31
48
  </div>
32
49
 
33
- {#each item.acl as control}
50
+ {#each acl ?? [] as control}
34
51
  <div class="AccessControl">
35
52
  {#if !control.user}<i>Unknown</i>
36
53
  {:else}
37
54
  <UserCard user={control.user} />
38
55
  {#if editable}
39
- <input type="hidden" name="userId" value={control.user.id} />
40
- <select name="permission">
56
+ <select name={control.userId}>
41
57
  {#each permEntries as [key, name]}
42
58
  <option value={key} selected={key == control.permission}>{name}</option>
43
59
  {/each}
@@ -51,8 +67,8 @@
51
67
 
52
68
  <div class="AccessControl public">
53
69
  <strong>Public Access</strong>
54
- {#if editable}
55
- <select name="publicPermission">
70
+ {#if editable && item}
71
+ <select name="public">
56
72
  {#each permEntries as [key, name]}
57
73
  <option value={key} selected={key == item.publicPermission}>{name}</option>
58
74
  {/each}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axium/client",
3
- "version": "0.7.0",
3
+ "version": "0.8.0",
4
4
  "author": "James Prevett <jp@jamespre.dev>",
5
5
  "funding": {
6
6
  "type": "individual",