lattris 0.1.3 → 0.1.4

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/build.json CHANGED
@@ -1 +1 @@
1
- {"commit":"cecf7e60eb450bce092dc992155ff77002fc1379","builtAt":"2026-09-15T22:27:41Z"}
1
+ {"commit":"92b27e26b7bbfb87059aec6ca19287eb8f2830f2","builtAt":"2026-09-15T23:11:21Z"}
package/dist/main.js CHANGED
@@ -1019,16 +1019,14 @@ export const validAccessToken = async (cfg) => {
1019
1019
  throw new Error('not-logged-in');
1020
1020
  }
1021
1021
  };
1022
- // An absent or unrefreshable session sends no Authorization header, since the
1023
- // API refuses any present invalid bearer by its own rule.
1022
+ // A public read sends no Authorization header when obtaining an optional token
1023
+ // fails for any reason; the API refuses any present invalid bearer by its own rule.
1024
1024
  export const optionalAccessToken = async (cfg) => {
1025
1025
  try {
1026
1026
  return await validAccessToken(cfg);
1027
1027
  }
1028
- catch (error) {
1029
- if (error instanceof Error && error.message === 'not-logged-in')
1030
- return undefined;
1031
- throw error;
1028
+ catch {
1029
+ return undefined;
1032
1030
  }
1033
1031
  };
1034
1032
  // Render a door to STDERR (stdout stays clean for piped data):
@@ -1187,13 +1185,23 @@ export const edgeRefusal = (status, headers, bytes) => {
1187
1185
  // delete route's success) has no body to parse.
1188
1186
  const HTTP_NO_CONTENT = 204;
1189
1187
  export const apiFetch = async (accessToken, url, init = {}, addressKind = 'api') => {
1190
- const headers = { ...init.headers };
1191
- if (accessToken !== undefined)
1192
- headers.Authorization = `Bearer ${accessToken}`;
1193
- const res = await fetch(url, {
1194
- ...init,
1195
- headers
1196
- });
1188
+ const { retryAnonymousOn401 = false, ...requestInit } = init;
1189
+ const request = (token) => {
1190
+ const headers = { ...requestInit.headers };
1191
+ if (token !== undefined)
1192
+ headers.Authorization = `Bearer ${token}`;
1193
+ else if (retryAnonymousOn401)
1194
+ delete headers.Authorization;
1195
+ return fetch(url, { ...requestInit, headers });
1196
+ };
1197
+ let res = await request(accessToken);
1198
+ const isRead = requestInit.method === undefined || requestInit.method.toUpperCase() === 'GET';
1199
+ if (retryAnonymousOn401 && isRead && accessToken !== undefined && res.status === 401) {
1200
+ // Suppress the rejected optional bearer’s login door; only the anonymous
1201
+ // answer is rendered. Never retry a write or an already-anonymous call.
1202
+ await res.body?.cancel().catch(() => { });
1203
+ res = await request(undefined);
1204
+ }
1197
1205
  if (!res.ok) {
1198
1206
  // Bytes, not text: the edge excerpt is cut by byte before decoding, and
1199
1207
  // the house-error parse below decodes the same bytes (BOM dropped, as
@@ -2621,7 +2629,8 @@ const getMemory = async (cfg, idOrAddress, flags, by) => {
2621
2629
  const url = buildGetMemoryUrl(cfg.webUrl, ownerHandle, address?.ref ?? idOrAddress, flags);
2622
2630
  const enveloped = url.search !== '';
2623
2631
  const result = await apiFetch(accessToken, url, {
2624
- headers: { Accept: 'application/json' }
2632
+ headers: { Accept: 'application/json' },
2633
+ retryAnonymousOn401: true
2625
2634
  }, 'web');
2626
2635
  if (!result.ok) {
2627
2636
  renderAmbiguousIfPresent(result.body);
@@ -2730,7 +2739,8 @@ const getWallMemories = async (cfg, ownerHandle, flags) => {
2730
2739
  if (flags.content !== undefined)
2731
2740
  url.searchParams.set('content', flags.content);
2732
2741
  const result = await apiFetch(accessToken, url, {
2733
- headers: { Accept: 'application/json' }
2742
+ headers: { Accept: 'application/json' },
2743
+ retryAnonymousOn401: true
2734
2744
  }, 'web');
2735
2745
  if (!result.ok) {
2736
2746
  process.exitCode = result.exit;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lattris",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "type": "module",
5
5
  "description": "First-party CLI for Lattris — sign in, capture notes and sessions, and read your own tree from the terminal.",
6
6
  "keywords": [