@axium/client 0.39.5 → 0.39.7

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/uploads.js CHANGED
@@ -11,6 +11,25 @@ async function handleError(response) {
11
11
  const json = await response.json();
12
12
  throw json.message;
13
13
  }
14
+ /** Whether request bodies can be streams, rather than being coerced to a string. */
15
+ let supportsRequestStreams;
16
+ try {
17
+ const request = new Request('about:blank', {
18
+ method: 'POST',
19
+ body: new ReadableStream({
20
+ start(controller) {
21
+ controller.enqueue(new Uint8Array([0]));
22
+ controller.close();
23
+ },
24
+ }),
25
+ duplex: 'half',
26
+ });
27
+ const data = await request.arrayBuffer();
28
+ supportsRequestStreams = data.byteLength == 1;
29
+ }
30
+ catch {
31
+ supportsRequestStreams = false;
32
+ }
14
33
  /**
15
34
  * Does a chunked upload to a given endpoint
16
35
  */
@@ -63,10 +82,10 @@ export async function uploadChunked(options) {
63
82
  });
64
83
  let init = { duplex: 'half' };
65
84
  /** @see https://bugzilla.mozilla.org/show_bug.cgi?id=1387483 */
66
- if (globalThis.navigator?.userAgent?.toLowerCase().includes('firefox')) {
85
+ if (!supportsRequestStreams) {
67
86
  await body.cancel();
68
87
  init = {};
69
- warnOnce('Using a workaround for uploading on Firefox [https://bugzilla.mozilla.org/show_bug.cgi?id=1387483]');
88
+ warnOnce('Using a workaround since upload streams are not supported [https://bugzilla.mozilla.org/show_bug.cgi?id=1387483]');
70
89
  const chunkData = new Uint8Array(chunkSize);
71
90
  let bytesReadForChunk = 0;
72
91
  if (buffer.length > 0) {
package/dist/user.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { AuthInfo, NewSessionResponse, Passkey, PasskeyChangeable, Session, User, UserChangeable, UserPublic, Verification } from '@axium/core';
1
+ import type { AuthInfo, NewSessionResponse, Passkey, PasskeyChangeable, Session, SessionChangeable, User, UserChangeable, UserPublic, Verification } from '@axium/core';
2
2
  import * as z from 'zod';
3
3
  import Cache from './cache.js';
4
4
  export declare function login(userId: string): Promise<NewSessionResponse>;
@@ -16,6 +16,7 @@ export declare function currentSession(): Promise<(Session & {
16
16
  }) | null>;
17
17
  export declare function extendCurrentSession(userId: string): Promise<void>;
18
18
  export declare function getSessions(userId: string): Promise<Session[]>;
19
+ export declare function updateSession(userId: string, data: SessionChangeable): Promise<Session>;
19
20
  export declare function logout(userId: string, ...sessionId: string[]): Promise<Session[]>;
20
21
  export declare function logoutAll(userId: string): Promise<Session[]>;
21
22
  export declare function logoutCurrentSession(): Promise<Session>;
package/dist/user.js CHANGED
@@ -47,6 +47,10 @@ export async function getSessions(userId) {
47
47
  _checkId(userId);
48
48
  return await fetchAPI('GET', 'users/:id/sessions', {}, userId);
49
49
  }
50
+ export async function updateSession(userId, data) {
51
+ _checkId(userId);
52
+ return await fetchAPI('PATCH', 'users/:id/sessions', data, userId);
53
+ }
50
54
  export async function logout(userId, ...sessionId) {
51
55
  _checkId(userId);
52
56
  return await fetchAPI('DELETE', 'users/:id/sessions', { id: sessionId }, userId);
@@ -1,8 +1,11 @@
1
1
  <script lang="ts">
2
- import { logout, logoutAll, text } from '@axium/client';
2
+ import { logout, logoutAll, text, updateSession } from '@axium/client';
3
3
  import type { Session, User } from '@axium/core';
4
+ import { SessionChangeable } from '@axium/core/user';
4
5
  import FormDialog from './FormDialog.svelte';
5
6
  import Icon from './Icon.svelte';
7
+ import InlineEdit from './InlineEdit.svelte';
8
+ import { toastStatus } from './toast.js';
6
9
 
7
10
  let {
8
11
  sessions = $bindable(),
@@ -10,21 +13,43 @@
10
13
  user,
11
14
  redirectAfterLogoutAll = false,
12
15
  }: { sessions: Session[]; currentSession?: Session; user: User; redirectAfterLogoutAll?: boolean } = $props();
16
+
17
+ let editing = $state<string>();
13
18
  </script>
14
19
 
15
20
  {#each sessions as session}
16
21
  <div class="item session">
17
- <p>
18
- {session.name ?? `${session.id.slice(0, 4)}...${session.id.slice(-4)}`}
19
- {#if session.id == currentSession?.id}
20
- <span class="current">{text('SessionList.current')}</span>
21
- {/if}
22
- {#if session.elevated}
23
- <span class="elevated">{text('SessionList.elevated')}</span>
24
- {/if}
25
- </p>
22
+ {#if editing == session.id}
23
+ <InlineEdit
24
+ value={session.name}
25
+ schema={SessionChangeable.shape.name}
26
+ placeholder={text('SessionList.rename_placeholder')}
27
+ commit={name =>
28
+ toastStatus(
29
+ updateSession(user.id, { id: session.id, name }).then(updated => {
30
+ sessions = sessions.map(s => (s.id == updated.id ? updated : s));
31
+ }),
32
+ text('SessionList.toast_renamed')
33
+ )}
34
+ close={() => (editing = undefined)}
35
+ />
36
+ {:else}
37
+ <p>
38
+ {session.name || `${session.id.slice(0, 4)}...${session.id.slice(-4)}`}
39
+ {#if session.id == currentSession?.id}
40
+ <span class="current">{text('SessionList.current')}</span>
41
+ {/if}
42
+ {#if session.elevated}
43
+ <span class="elevated">{text('SessionList.elevated')}</span>
44
+ {/if}
45
+ </p>
46
+ {/if}
26
47
  <p class="timestamp">{text('SessionList.created', { date: session.created.toLocaleString() })}</p>
27
48
  <p class="timestamp">{text('SessionList.expires', { date: session.expires.toLocaleString() })}</p>
49
+ <button onclick={() => (editing = session.id)} class="rename icon-text">
50
+ <Icon i="pen" --size="16px" />
51
+ <span class="mobile-only">{text('generic.rename')}</span>
52
+ </button>
28
53
  <button command="show-modal" commandfor={'logout-session:' + session.id} class="logout icon-text">
29
54
  <Icon i="right-from-bracket" --size="16px" />
30
55
  <span class="mobile-only">{text('generic.logout')}</span>
@@ -53,7 +78,7 @@
53
78
  </FormDialog>
54
79
 
55
80
  <style>
56
- button.logout {
81
+ button:is(.logout, .rename) {
57
82
  width: fit-content;
58
83
  text-align: center;
59
84
  }
package/locales/en.json CHANGED
@@ -41,7 +41,9 @@
41
41
  "logout_all_question": "Are you sure you want to log out all sessions?",
42
42
  "logout_all_submit": "Logout All Sessions",
43
43
  "logout_all_trigger": "Logout All",
44
- "logout_single": "Are you sure you want to log out this session?"
44
+ "logout_single": "Are you sure you want to log out this session?",
45
+ "rename_placeholder": "Session name",
46
+ "toast_renamed": "Session renamed"
45
47
  },
46
48
  "Upload": {
47
49
  "upload": "Upload"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axium/client",
3
- "version": "0.39.5",
3
+ "version": "0.39.7",
4
4
  "author": "James Prevett <jp@jamespre.dev>",
5
5
  "funding": {
6
6
  "type": "individual",
@@ -49,7 +49,7 @@
49
49
  "build": "tsc"
50
50
  },
51
51
  "peerDependencies": {
52
- "@axium/core": ">=0.41.0",
52
+ "@axium/core": ">=0.41.3",
53
53
  "ioium": "^1.7.0",
54
54
  "semver": "^7.7.4",
55
55
  "svelte": "^5.36.0",
@@ -70,7 +70,7 @@
70
70
  }
71
71
 
72
72
  .session {
73
- grid-template-columns: 1fr 15em 15em 1em;
73
+ grid-template-columns: 1fr 15em 15em 1em 1em;
74
74
 
75
75
  .current {
76
76
  border-radius: 2em;
@@ -84,7 +84,8 @@
84
84
  background-color: #733;
85
85
  }
86
86
 
87
- .logout {
87
+ .logout,
88
+ .rename {
88
89
  display: contents;
89
90
  }
90
91
  }