@oxyhq/core 10.1.1 → 10.1.3

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.
@@ -26,6 +26,7 @@
26
26
  * builds the hand-off URL; device-first convergence syncs the session back.
27
27
  */
28
28
  import { logger } from '../utils/loggerUtils.js';
29
+ import { extractErrorStatus } from '../utils/errorUtils.js';
29
30
  import { CENTRAL_IDP_APEX } from '../utils/authWebUrl.js';
30
31
  import { generateOAuthState, generatePkcePair, normalizeOAuthRedirectUri, persistOAuthHandshake, } from '../utils/oauthPkce.js';
31
32
  import { projectSwitchableAccounts, switchableAccountIds, } from './accountProjection.js';
@@ -241,10 +242,20 @@ export class AccountDialogController {
241
242
  graph = await this.oxyServices.listAccounts();
242
243
  }
243
244
  catch (error) {
244
- // A graph-load failure is non-fatal: device rows still render. Surface the
245
- // message but keep going with whatever graph we already had.
246
- this.error = errorMessage(error);
247
- logger.warn('[AccountDialogController] listAccounts failed', { component: 'AccountDialogController' }, error);
245
+ // A 401 here is the EXPECTED signed-out edge, not a failure: the bearer was
246
+ // stale/revoked, so `HttpService` already cleared it and emitted
247
+ // `onTokensChanged(null)`, which drops the graph via `reconcileAuth`. Log at
248
+ // debug and leave the dialog error-free — a signed-out device with zero
249
+ // accounts is a normal state, not a warning. Any other error (network, 5xx,
250
+ // malformed) IS unexpected: surface it and warn while keeping the prior graph
251
+ // so device rows still render.
252
+ if (extractErrorStatus(error) === 401) {
253
+ logger.debug('[AccountDialogController] listAccounts unauthorized (signed out)', { component: 'AccountDialogController' }, error);
254
+ }
255
+ else {
256
+ this.error = errorMessage(error);
257
+ logger.warn('[AccountDialogController] listAccounts failed', { component: 'AccountDialogController' }, error);
258
+ }
248
259
  }
249
260
  if (seq !== this.refreshSeq)
250
261
  return; // superseded by a newer refresh
@@ -284,9 +295,16 @@ export class AccountDialogController {
284
295
  profiles = await this.oxyServices.getUsersByIds(ids);
285
296
  }
286
297
  catch (error) {
287
- // `getUsersByIds` already swallows per-chunk failures and returns `[]`;
288
- // this guards the unexpected total failure. Non-fatal keep prior map.
289
- logger.warn('[AccountDialogController] getUsersByIds failed', { component: 'AccountDialogController' }, error);
298
+ // A 401 is the EXPECTED signed-out edge (stale/cleared bearer) — log at debug.
299
+ // `getUsersByIds` already swallows per-chunk failures and returns `[]`, so any
300
+ // OTHER error here is an unexpected total failure worth a warn. Either way keep
301
+ // the prior profile map.
302
+ if (extractErrorStatus(error) === 401) {
303
+ logger.debug('[AccountDialogController] getUsersByIds unauthorized (signed out)', { component: 'AccountDialogController' }, error);
304
+ }
305
+ else {
306
+ logger.warn('[AccountDialogController] getUsersByIds failed', { component: 'AccountDialogController' }, error);
307
+ }
290
308
  return;
291
309
  }
292
310
  if (seq !== this.refreshSeq)
@@ -59,12 +59,11 @@ const INLINE_NEEDS_NORMALIZATION = /[^\x20-\x7E]|^ | $| {2}/;
59
59
  /**
60
60
  * Same idea as {@link INLINE_NEEDS_NORMALIZATION}, for MULTILINE values: `\n`
61
61
  * joins the printable-ASCII fast-path alphabet, and the additional shapes a
62
- * normalized body can never contain are a space before a line break (trailing
63
- * horizontal whitespace) and a run of three line breaks (more than one blank
64
- * line). A single space AFTER a line break is legal — a one-space indent is
65
- * the author's, and normalization deliberately preserves it.
62
+ * normalized body can never contain are a space adjacent to a line break — on
63
+ * either side, since every line is trimmed — and a run of three line breaks
64
+ * (more than one blank line).
66
65
  */
67
- const MULTILINE_NEEDS_NORMALIZATION = /[^\x20-\x7E\n]|^[ \n]|[ \n]$| {2}| \n|\n{3}/;
66
+ const MULTILINE_NEEDS_NORMALIZATION = /[^\x20-\x7E\n]|^[ \n]|[ \n]$| {2}| \n|\n |\n{3}/;
68
67
  /** Any run of whitespace, including tabs, line breaks and Unicode spaces. */
69
68
  const ANY_WHITESPACE_RUN = /\s+/g;
70
69
  /**
@@ -86,8 +85,18 @@ const LINE_BREAK_FORMS = /\r\n|\r|\p{Zl}|\p{Zp}/gu;
86
85
  * Applied AFTER {@link LINE_BREAK_FORMS}, so no line break can hide in it.
87
86
  */
88
87
  const HORIZONTAL_WHITESPACE_RUN = /[^\S\n]+/g;
89
- /** Horizontal whitespace at the end of a line — the blank-line spoiler. */
88
+ /**
89
+ * Horizontal whitespace at the END of a line — the blank-line spoiler: it is
90
+ * what makes an "empty" line non-empty and hides it from {@link EXCESS_BLANK_LINES}.
91
+ */
90
92
  const TRAILING_HORIZONTAL_WHITESPACE = / +\n/g;
93
+ /**
94
+ * Horizontal whitespace at the START of a line: source-markup indentation. HTML
95
+ * collapses it by spec, so it is invisible where the text came from and carries
96
+ * no meaning — it only becomes visible once a client renders the value with
97
+ * `white-space: pre-wrap`.
98
+ */
99
+ const LEADING_HORIZONTAL_WHITESPACE = /\n +/g;
91
100
  /** Three or more line breaks: more than one blank line between paragraphs. */
92
101
  const EXCESS_BLANK_LINES = /\n{3,}/g;
93
102
  /**
@@ -131,20 +140,23 @@ export function normalizeInlineText(value) {
131
140
  * 2. Unify every line-break form (CRLF, lone CR, U+2028, U+2029) to `\n`.
132
141
  * 3. Collapse runs of HORIZONTAL whitespace (spaces, tabs, NBSP and friends)
133
142
  * to a single space. Line breaks are untouched.
134
- * 4. Strip the horizontal whitespace at the END of each line.
143
+ * 4. Strip the horizontal whitespace at BOTH ends of every line.
135
144
  * 5. Collapse three or more line breaks to exactly one blank line (`\n\n`).
136
- * 6. Trim both ends.
145
+ * 6. Trim both ends of the value.
137
146
  *
138
147
  * STEP 4 MUST PRECEDE STEP 5 — this is the whole point of the function. A
139
148
  * "blank" line that actually contains spaces (`"a\n \n \nb"`) breaks the
140
149
  * run of `\n` characters, so a bare `\n{3,}` collapse (step 5 alone) never sees
141
150
  * it and the extra blank lines survive into the UI. That is exactly the bug in
142
- * federated post bodies. Removing the trailing horizontal whitespace first
143
- * turns those lines into real, empty lines, which step 5 then collapses.
151
+ * federated post bodies. Trimming each line first turns those lines into real,
152
+ * empty lines, which step 5 then collapses.
144
153
  *
145
- * A single space at the START of a line is preserved: only RUNS of horizontal
146
- * whitespace collapse, and an indent is not trailing whitespace, so a one-space
147
- * indent is treated as the author's and left alone.
154
+ * Every line is trimmed on BOTH sides, so a leading indent is removed outright
155
+ * rather than reduced to one space. Step 3 has already destroyed whatever indent
156
+ * the author wrote (`" Mundo"` `" Mundo"`), so a surviving space would not
157
+ * be the author's intent — it would be an arbitrary remnant of exactly the
158
+ * source-markup indentation this function exists to erase, and `pre-wrap` renders
159
+ * it. Indentation is invisible in HTML by spec; it must be invisible here too.
148
160
  *
149
161
  * A value that is empty or whitespace-only returns `''`.
150
162
  *
@@ -159,6 +171,7 @@ export function normalizeMultilineText(value) {
159
171
  .replace(LINE_BREAK_FORMS, '\n')
160
172
  .replace(HORIZONTAL_WHITESPACE_RUN, ' ')
161
173
  .replace(TRAILING_HORIZONTAL_WHITESPACE, '\n')
174
+ .replace(LEADING_HORIZONTAL_WHITESPACE, '\n')
162
175
  .replace(EXCESS_BLANK_LINES, '\n\n')
163
176
  .trim();
164
177
  }