@jskit-ai/auth-web 0.2.45 → 0.2.47

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/CHANGELOG.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
- - Up to medium width, the account control's avatar is hidden from assistive technology (`aria-hidden="true"`). That round button is named by the person's name, and the initials it shows ("AN" for ana.ferreira) were not in its name, which WCAG 2.5.3 Label in Name asks (axe `label-content-name-mismatch`); it now shows assistive technology no text beyond its name. On wider windows the control's name is the name it shows, as before.
5
+ - Up to medium width, the account control's name begins with the initials its avatar shows: "AN ana.ferreira" for ana.ferreira without a picture, the person's name alone with one. That round button is named by its aria-label, and WCAG 2.5.3 Label in Name asks that a control's name hold the text it shows, the words a person using speech input says to press it (axe `label-content-name-mismatch`). Its avatar is hidden from assistive technology (`aria-hidden="true"`), since the name says whose account it is; hiding it alone, as 0.2.45 did, left the finding, as axe counts every word drawn on the screen. On wider windows the control's name is the text it shows, as before.
6
6
  - Email change over HTTP: `POST /api/email-change` (signed in, `{ email, password }`) asks for it and `POST /api/email-change/confirm` (public, `{ token }`) uses the link, each limited per address by `config.auth.rateLimits.emailChange` (5 a minute) and `emailChangeConfirm` (10 a minute). The page the link opens is `DefaultEmailChangeView` (`./client/views/DefaultEmailChangeView`, route component `auth-email-change`, the `auth.email-change` route at `/auth/email-change`, public, registered by an application's own page as the sign-in, reset and sign-out pages are): it confirms the link once, takes the token out of the address, and says the new email or why the link was refused (`jskit.auth.emailChange.*`).
7
7
  - `POST /api/login/pass` hands `signInWithPass` the request that posted the pass, so local auth keeps the session's address and browser.
8
8
  - Its tests name `APP_ENV`, which the auth providers now read in place of `NODE_ENV`; the setup-code field is asked for by a staging or production server.
@@ -1,6 +1,6 @@
1
- import { createApp, h, ref } from "vue";
1
+ import { createApp, defineAsyncComponent, h, ref } from "vue";
2
2
  import { createPinia } from "pinia";
3
- import { createRouter, createWebHistory, RouterView } from "vue-router";
3
+ import { createRouter, createWebHistory, RouterView, useRoute } from "vue-router";
4
4
  import { QueryClient, VueQueryPlugin } from "@tanstack/vue-query";
5
5
  import "vuetify/styles";
6
6
  import "@jskit-ai/material-web/client/material.css";
@@ -84,7 +84,8 @@ const SecondFactorPage = {
84
84
  ]);
85
85
  }
86
86
  };
87
- // An application's console: its refund route asks for a code proved within five minutes, through the step-up dialog.
87
+ // An application's console, in the shell's layout as an app's screens are: its refund route asks for a code proved
88
+ // within five minutes, through the step-up dialog, over the page the shell makes inert while the dialog is open.
88
89
  const ConsolePage = {
89
90
  setup() {
90
91
  const { open, run, verified, cancel } = useSecondFactorStepUp();
@@ -124,7 +125,7 @@ const router = createRouter({
124
125
  { path: "/", redirect: "/home" },
125
126
  { path: "/home", component: HomePage },
126
127
  { path: "/account/second-factor", component: SecondFactorPage },
127
- { path: "/console", component: ConsolePage },
128
+ { path: "/console", component: ConsolePage, meta: { shell: true } },
128
129
  { path: "/auth/login", component: DefaultLoginView },
129
130
  { path: "/auth/reset-password", component: DefaultResetPasswordView },
130
131
  { path: "/auth/signout", component: DefaultSignOutView },
@@ -137,7 +138,19 @@ const router = createRouter({
137
138
  { path: "/auth/pattern/signout", component: PatternSignOutPage }
138
139
  ]
139
140
  });
140
- const app = createApp({ render: () => h(components.VApp, null, { default: () => h(components.VMain, null, { default: () => h(RouterView) }) }) });
141
+ // A page in the shell's layout (`meta.shell`) has the layout's main; the others have a plain one. Only the console
142
+ // page is in the layout, so only it loads the layout: the sign-in pages load what they did before.
143
+ const ShellLayout = defineAsyncComponent(() => import("@jskit-ai/shell-web/client/components/ShellLayout"));
144
+ const app = createApp({
145
+ setup() {
146
+ const route = useRoute();
147
+ return () => h(components.VApp, null, {
148
+ default: () => route.meta.shell
149
+ ? h(ShellLayout, { title: "Console" }, { default: () => h(RouterView) })
150
+ : h(components.VMain, null, { default: () => h(RouterView) })
151
+ });
152
+ }
153
+ });
141
154
  const pinia = createPinia();
142
155
  app.provide(SHELL_WEB_PLACEMENT_RUNTIME_KEY, placement);
143
156
  app.provide(SHELL_WEB_ERROR_RUNTIME_KEY, errorRuntime);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jskit-ai/auth-web",
3
- "version": "0.2.45",
3
+ "version": "0.2.47",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "test": "jskit test"
@@ -36,7 +36,7 @@
36
36
  "@jskit-ai/auth-core": "0.2.31",
37
37
  "@jskit-ai/http-runtime": "0.2.27",
38
38
  "@jskit-ai/kernel": "0.2.27",
39
- "@jskit-ai/shell-web": "0.2.39",
39
+ "@jskit-ai/shell-web": "0.2.41",
40
40
  "@tanstack/vue-query": "^5.90.5",
41
41
  "pinia": "^4.0.3",
42
42
  "vue": "^3.5.44",
@@ -11,8 +11,10 @@ const { t } = useJskitText();
11
11
  const { context: shellPlacementContext } = useWebPlacementContext();
12
12
  // On expanded windows the activator is a pill with the name beside the avatar, the name ending in an ellipsis past
13
13
  // 12rem; on medium and compact windows, where the app bar's title and actions need the room, it is a round icon
14
- // button around the avatar, named by its aria-label. That avatar is hidden from assistive technology: its initials
15
- // are not in the name, and a control's name holds the text it shows (WCAG 2.5.3 Label in Name).
14
+ // button around the avatar, named by its aria-label. A control's name holds the text it shows (WCAG 2.5.3 Label in
15
+ // Name), the words a person using speech input says to press it, and every word drawn on the screen counts, hidden
16
+ // from assistive technology or not; so without a picture that name begins with the initials the avatar shows,
17
+ // "AN ana.ferreira". The avatar itself stays hidden from assistive technology: the name says whose account it is.
16
18
  const { isExpanded, isLarge } = useShellWindowSizeClass();
17
19
  const showsName = computed(() => isExpanded.value || isLarge.value);
18
20
 
@@ -61,6 +63,8 @@ const initials = computed(() => {
61
63
  return text.slice(0, 2).toUpperCase();
62
64
  });
63
65
 
66
+ const compactName = computed(() => (avatarUrl.value ? displayName.value : `${initials.value} ${displayName.value}`));
67
+
64
68
  const placementContext = computed(() => {
65
69
  return {
66
70
  auth: auth.authState,
@@ -84,7 +88,7 @@ const placementContext = computed(() => {
84
88
  </v-avatar>
85
89
  <span class="auth-profile-widget__name ml-2 text-body-medium">{{ displayName }}</span>
86
90
  </v-btn>
87
- <v-btn v-else v-bind="props" icon variant="text" class="auth-profile-widget__activator" :aria-label="displayName">
91
+ <v-btn v-else v-bind="props" icon variant="text" class="auth-profile-widget__activator" :aria-label="compactName">
88
92
  <v-avatar size="32" color="primary" variant="tonal" aria-hidden="true">
89
93
  <v-img v-if="avatarUrl" :src="avatarUrl" cover />
90
94
  <span v-else class="text-body-small font-weight-medium">{{ initials }}</span>
@@ -78,7 +78,7 @@ test("auth profile activator keeps Material 3's 48dp touch target without a fixe
78
78
  // Without the name, up to medium width, the activator is an icon button, so its state layer is a circle round the
79
79
  // avatar; the name shows on expanded windows only, through the shell's window size classes.
80
80
  assert.match(widgetSource, /const showsName = computed\(\(\) => isExpanded\.value \|\| isLarge\.value\);/u);
81
- assert.match(widgetSource, /<v-btn v-else v-bind="props" icon variant="text" class="auth-profile-widget__activator" :aria-label="displayName">/u);
81
+ assert.match(widgetSource, /<v-btn v-else v-bind="props" icon variant="text" class="auth-profile-widget__activator" :aria-label="compactName">/u);
82
82
  // material-web gives every default-size button a 48dp touch target around its 40dp body; a fixed height would
83
83
  // make the button itself taller than Material 3 draws it.
84
84
  assert.doesNotMatch(widgetSource, /min-height/u);
@@ -96,6 +96,13 @@ after(async () => {
96
96
  }
97
97
  });
98
98
 
99
+ // The app's /home after the page load that brought the browser there: a sign-in, the provider's redirect back or
100
+ // another site's link replaces the page, and a page load waits under the navigation timeout, not expect's 5 s, which
101
+ // is too short for a whole page load while many browser test files run at once.
102
+ function waitForHome(page) {
103
+ return page.waitForURL((url) => url.origin === new URL(stack.appUrl).origin && url.pathname === "/home");
104
+ }
105
+
99
106
  function cookieNames(header) {
100
107
  return String(header || "").split(";").map((pair) => pair.split("=")[0].trim()).filter(Boolean).sort();
101
108
  }
@@ -144,6 +151,7 @@ test("with strict cookies, Google sign-in comes back from the provider's site an
144
151
  await page.getByRole("button", { name: "Continue with Google" }).click();
145
152
  await page.waitForURL((url) => url.href.startsWith(stack.issuerUrl));
146
153
  await page.getByRole("button", { name: "Continue", exact: true }).click();
154
+ await waitForHome(page);
147
155
  await expect(page.getByTestId("home")).toHaveText("Signed in: true");
148
156
  assert.equal(new URL(page.url()).pathname, "/home");
149
157
 
@@ -193,12 +201,14 @@ test("with strict cookies, a link from another site opens the app signed in by t
193
201
  await page.getByLabel("Email").fill("grace@example.com");
194
202
  await page.getByLabel("Password", { exact: true }).fill(PASSWORD);
195
203
  await page.getByTestId("auth-submit").click();
204
+ await waitForHome(page);
196
205
  await expect(page.getByTestId("home")).toHaveText("Signed in: true");
197
206
 
198
207
  stack.apiRequests.length = 0;
199
208
  documents.length = 0;
200
209
  await page.goto(webmail);
201
210
  await page.getByRole("link", { name: "Open your account" }).click();
211
+ await waitForHome(page);
202
212
  await expect(page.getByTestId("home")).toHaveText("Signed in: true");
203
213
  // The link's page load came from another site and carried no Strict cookie ...
204
214
  const landing = await appDocument(documents, (url) => url.pathname === "/home");
@@ -190,7 +190,14 @@ test("removing the authenticator takes a code or a recovery code, shows a wait b
190
190
  await finish(api);
191
191
  });
192
192
 
193
- test("a route that asks for a fresh code opens the step-up dialog, runs again after the code, and Escape cancels it, focus returning to the control each time", options, async () => {
193
+ // Whether every part of the shell's page around the console (its app bar and main at least) is inert, as it is while
194
+ // the step-up dialog is open, or else every part live.
195
+ async function shellPageIs(page, inert) {
196
+ const parts = await page.evaluate(() => [...document.querySelectorAll("[data-shell-page]")].map((part) => part.inert));
197
+ return parts.length >= 2 && parts.every((part) => part === inert);
198
+ }
199
+
200
+ test("a route that asks for a fresh code opens the step-up dialog over an inert page, runs again after the code, and Escape cancels it, focus returning to the control each time", options, async () => {
194
201
  const api = await openApp({
195
202
  "POST /api/console/refund": [REQUIRED, { json: { refunded: true } }, REQUIRED],
196
203
  "POST /api/second-factor/verify": [
@@ -205,6 +212,7 @@ test("a route that asks for a fresh code opens the step-up dialog, runs again af
205
212
  const dialog = page.getByRole("dialog", { name: "Confirm it's you" });
206
213
  await expect(dialog.getByRole("heading", { name: "Confirm it's you" })).toBeVisible();
207
214
  await expect(dialog.getByLabel("6-digit code")).toBeFocused();
215
+ assert.ok(await shellPageIs(page, true), "the shell's app bar and main are inert behind the dialog");
208
216
  await fitsTheScreen(page);
209
217
  await page.keyboard.type("000000");
210
218
  await page.keyboard.press("Enter");
@@ -213,15 +221,18 @@ test("a route that asks for a fresh code opens the step-up dialog, runs again af
213
221
  await page.keyboard.press("Enter");
214
222
  await expect(page.getByTestId("console-outcome")).toHaveText("Refunded");
215
223
  await expect(dialog).toBeHidden();
216
- // Focus is back on the control that sent the request, after a code as after cancelling.
224
+ // Focus is back on the control that sent the request, after a code as after cancelling, on a live page.
217
225
  await expect(page.getByRole("button", { name: "Refund" })).toBeFocused();
226
+ assert.ok(await shellPageIs(page, false), "the page is live again");
218
227
 
219
228
  await page.keyboard.press("Enter");
220
229
  await expect(dialog.getByLabel("6-digit code")).toBeFocused();
230
+ assert.ok(await shellPageIs(page, true), "the page is inert behind the dialog again");
221
231
  await page.keyboard.press("Escape");
222
232
  await expect(dialog).toBeHidden();
223
233
  await expect(page.getByTestId("console-outcome")).toHaveText("Refund failed: Confirm it's you with a code from your authenticator app.");
224
234
  await expect(page.getByRole("button", { name: "Refund" })).toBeFocused();
235
+ assert.ok(await shellPageIs(page, false), "the page is live after Escape");
225
236
 
226
237
  assert.equal(bodiesOf(api, "POST /api/console/refund").length, 3);
227
238
  assert.deepEqual(bodiesOf(api, "POST /api/second-factor/verify"), [{ code: "000000" }, { code: "123456" }]);
@@ -1,4 +1,5 @@
1
1
  import assert from "node:assert/strict";
2
+ import { createRequire } from "node:module";
2
3
  import process from "node:process";
3
4
  import { after, before, test } from "node:test";
4
5
  import { fileURLToPath } from "node:url";
@@ -6,6 +7,8 @@ import { chromium, expect } from "@playwright/test";
6
7
  import { createChromiumLaunchOptions, startViteFixture, stopProcess } from "../../../tooling/testUtils/browserFixture.mjs";
7
8
 
8
9
  const RUN = process.env.JSKIT_AUTH_WEB_BROWSER_INTEGRATION === "1";
10
+ // axe-core as the page runs it, to check a rule the way axe reports it on an app's screens.
11
+ const AXE_PATH = createRequire(import.meta.url).resolve("axe-core/axe.min.js");
9
12
  const options = { skip: !RUN, timeout: 120_000 };
10
13
  const GUARD_EVALUATOR_KEY = "__JSKIT_WEB_SHELL_GUARD_EVALUATOR__";
11
14
  const CAPABILITIES = {
@@ -86,7 +89,9 @@ function reports(page) {
86
89
  return page.evaluate(() => window.authFixture.reports);
87
90
  }
88
91
 
89
- // The page itself, not a sign-in page whose returnTo=/home also ends the address.
92
+ // The page itself, not a sign-in page whose returnTo=/home also ends the address. Signing in replaces the page, so
93
+ // a check of /home waits for its page load first, under the navigation timeout: expect's own 5 s is too short for a
94
+ // whole page load while many browser test files run at once.
90
95
  function waitForHome(page) {
91
96
  return page.waitForURL((url) => url.pathname === "/home");
92
97
  }
@@ -121,6 +126,7 @@ test("password sign-in opens the requested page, remembers the account, and sign
121
126
  await expect(page.getByTestId("auth-submit")).toBeDisabled();
122
127
 
123
128
  await signIn(page, "Ada@Example.com", "correct horse");
129
+ await waitForHome(page);
124
130
  await expect(page.getByTestId("home")).toHaveText("Signed in: true");
125
131
  assert.equal(new URL(page.url()).pathname, "/home");
126
132
  const login = api.requests.find((request) => request.key === "POST /api/login");
@@ -139,6 +145,8 @@ test("password sign-in opens the requested page, remembers the account, and sign
139
145
  assert.deepEqual(await page.evaluate(() => window.authFixture.context.auth.permissions), ["read"]);
140
146
 
141
147
  await page.goto("/auth/signout?returnTo=/home");
148
+ // Signing out replaces the page with sign-in's.
149
+ await page.waitForURL((url) => url.pathname === "/auth/login");
142
150
  await expect(page.getByText("Welcome back, Ada Lovelace")).toBeVisible();
143
151
  assert.equal(new URL(page.url()).search, "?returnTo=%2Fhome");
144
152
  assert.equal(api.requests.filter((request) => request.key === "POST /api/logout").length, 1);
@@ -186,6 +194,7 @@ test("a refused sign-in reports the server's error and leaves the form usable",
186
194
  test("a signed-in visitor leaves the sign-in page, on opening it and when a session starts elsewhere", options, async () => {
187
195
  const signedIn = await openApp({ session: SIGNED_IN });
188
196
  await signedIn.page.goto("/auth/login?returnTo=/home");
197
+ await waitForHome(signedIn.page);
189
198
  await expect(signedIn.page.getByTestId("home")).toHaveText("Signed in: true");
190
199
  await finish(signedIn);
191
200
 
@@ -471,6 +480,7 @@ test("OAuth starts at the provider and a callback finishes on the requested page
471
480
  }
472
481
  });
473
482
  await api.page.goto("/auth/login?code=code-1&state=state-1&oauthProvider=google&oauthReturnTo=/home");
483
+ await waitForHome(api.page);
474
484
  await expect(api.page.getByTestId("home")).toHaveText("Signed in: true");
475
485
  assert.deepEqual(api.requests.at(-1).body, { provider: "google", code: "code-1", state: "state-1" });
476
486
  await finish(api);
@@ -484,6 +494,8 @@ test("OAuth starts at the provider and a callback finishes on the requested page
484
494
  }
485
495
  });
486
496
  await landed.page.goto("/home?code=code-2&oauthProvider=google");
497
+ // The guard sends the callback to sign-in, which completes it and replaces the page with /home again.
498
+ await landed.page.waitForURL((url) => url.pathname === "/home" && !url.searchParams.has("code"));
487
499
  await expect(landed.page.getByTestId("home")).toHaveText("Signed in: true");
488
500
  assert.equal(new URL(landed.page.url()).searchParams.has("code"), false);
489
501
  await finish(landed);
@@ -578,32 +590,28 @@ test("the account control is the avatar alone up to medium width and truncates a
578
590
  await finish(api);
579
591
  });
580
592
 
581
- // WCAG 2.5.3 Label in Name: a control's name holds the text it shows. Up to medium width the account control is
582
- // named by the person's name (its aria-label) and shows their initials, "AN" for ana.ferreira, which are not in that
583
- // name (axe label-content-name-mismatch). Its avatar is hidden from assistive technology, so the control shows it no
584
- // text beyond its name; on wider windows the name is the text it shows.
585
- test("the account control's name holds every word it shows on a phone and a tablet: WCAG 2.5.3 (axe label-content-name-mismatch)", options, async () => {
593
+ // WCAG 2.5.3 Label in Name: a control's name holds the text it shows, the words a person using speech input says to
594
+ // press it. Up to medium width the account control is a round button named by its aria-label, and without a picture
595
+ // its avatar shows the initials, "AN" for ana.ferreira. axe's label-content-name-mismatch counts every word drawn on
596
+ // the screen, aria-hidden or not, so the name begins with the initials: "AN ana.ferreira".
597
+ test("the account control's name holds the initials it shows on a phone and a tablet: WCAG 2.5.3 (axe label-content-name-mismatch)", options, async () => {
586
598
  const name = "ana.ferreira";
587
- const words = (text) => text.toLowerCase().split(/[^\p{L}\p{N}]+/u).filter(Boolean);
588
599
  for (const viewport of [{ width: 390, height: 844 }, { width: 768, height: 1024 }]) {
589
600
  const at = `${viewport.width}px`;
590
601
  const api = await openApp({ session: { ...SIGNED_IN, username: name }, viewport });
591
602
  const { page } = api;
592
603
  await page.goto("/home");
593
- const control = page.getByRole("button", { name, exact: true });
594
- await expect(control, at).toBeVisible();
604
+ const control = page.getByRole("button", { name: /ana\.ferreira/u });
595
605
  await expect(control, `${at}: it shows the initials`).toHaveText("AN");
596
- // The text the control shows assistive technology: its text outside anything aria-hidden.
597
- const shown = await control.evaluate((button) => {
598
- const walker = document.createTreeWalker(button, NodeFilter.SHOW_TEXT);
599
- const texts = [];
600
- for (let node = walker.nextNode(); node; node = walker.nextNode()) {
601
- if (!node.parentElement.closest("[aria-hidden=true]")) texts.push(node.textContent);
602
- }
603
- return texts.join(" ");
606
+ await page.addScriptTag({ path: AXE_PATH });
607
+ const audit = await control.evaluate(async (button) => {
608
+ const results = await window.axe.run(button, { runOnly: { type: "rule", values: ["label-content-name-mismatch"] } });
609
+ const nodes = (outcome) => outcome.flatMap((rule) => rule.nodes.map((node) => node.failureSummary ?? node.html));
610
+ return { violations: nodes(results.violations), incomplete: nodes(results.incomplete), passed: nodes(results.passes).length };
604
611
  });
605
- const missing = words(shown).filter((word) => !words(name).includes(word));
606
- assert.deepEqual(missing, [], `${at}: the control shows "${shown.trim()}", which its name "${name}" does not hold`);
612
+ assert.deepEqual({ violations: audit.violations, incomplete: audit.incomplete }, { violations: [], incomplete: [] }, at);
613
+ assert.equal(audit.passed, 1, `${at}: axe checked the control's name against what it shows`);
614
+ await expect(control, at).toHaveAccessibleName(`AN ${name}`);
607
615
  await finish(api);
608
616
  }
609
617
  });