@aiquants/contact-map 0.22.0 → 0.24.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.
package/README.md CHANGED
@@ -51,6 +51,7 @@ Peer dependencies:
51
51
  ```json
52
52
  {
53
53
  "peerDependencies": {
54
+ "@aiquants/auth-core": "^0.9.0",
54
55
  "@aiquants/directory-tree": "^6.0.0",
55
56
  "@aiquants/fuzzy-search": "^3.2.1",
56
57
  "@aiquants/resize-panels": "^2.2.0",
@@ -66,8 +67,8 @@ Peer dependencies:
66
67
  }
67
68
  ```
68
69
 
69
- These are the ranges this version is published with. The repository's `package.json` writes the `@aiquants` ones as `workspace:^`, which publishing expands to `^` and the workspace's version, so `pnpm view @aiquants/contact-map@<version> peerDependencies` prints the ranges of any version.
70
- これはこの版を公開したときの範囲。リポジトリの `package.json` は `@aiquants` のものを `workspace:^` と書き、公開のときにワークスペースの版の `^` へ展開されるので、どの版の範囲も `pnpm view @aiquants/contact-map@<version> peerDependencies` で確かめられる。
70
+ These are the ranges this version is published with: the repository's `package.json` writes each `@aiquants` floor as `workspace:^X.Y.Z`, which publishing writes out as `^X.Y.Z`. `pnpm view @aiquants/contact-map@<version> peerDependencies` prints the ranges of any version.
71
+ これはこの版を公開したときの範囲 (リポジトリの `package.json` は `@aiquants` のものの下限を `workspace:^X.Y.Z` と書き、公開でそのまま `^X.Y.Z` になる)。どの版の範囲も `pnpm view @aiquants/contact-map@<version> peerDependencies` で確かめられる。
71
72
 
72
73
  ---
73
74
 
@@ -117,7 +118,8 @@ The handler calls `authenticate` in one way only, `authenticate(request, { failu
117
118
  `db`, `table`, `ensureConnection` and `authenticate` are required, and `createContactMapStreamHandler` / `createContactMapServer` throw a `TypeError` when `db` or `table` is missing, `table.contacted_at` is missing or is not a Drizzle column, `ensureConnection` or `authenticate` is not a function, or `firstBatchSize` / `nextBatchSize` is given but is not a number.
118
119
  They throw a `RangeError` when `table.contacted_at` is not a `datetime2` column (`datetime2` or `datetime2(0)` to `datetime2(7)`; a `datetime`, `datetimeoffset` or `date` column is refused) or `firstBatchSize` or `nextBatchSize` is a number but not an integer from 1 to `Number.MAX_SAFE_INTEGER`.
119
120
  Each message names the setting and ends with the value given (`[contact-map] server config authenticate must be the function that returns the request's user (…); got undefined`, `[contact-map] server config table.contacted_at must be a Drizzle datetime2 column; got "datetime"`). A stream open to everyone says so with an `authenticate` that returns a user; leaving the setting out never serves the contacts unauthenticated.
120
- The handler calls `authenticate(request, { failureRedirect: null })` after checking the resume cursor (a malformed cursor gets 400 without authenticating), answers 401 when no user comes back, and sends a returned `cookie` as `Set-Cookie` on the 401 and on the stream response alike, so a session the call refreshed reaches the browser. When `authenticate` throws, the handler logs the error through `logger` and answers 500 with `{ "error": "authentication failed on the server" }`, so nothing of the session infrastructure reaches the client.
121
+ The handler calls `authenticate(request, { failureRedirect: null })` after checking the resume cursor (a malformed cursor gets 400 without authenticating), answers the 401 of `@aiquants/auth-core` when no user comes back (`accessFailureResponse("unauthenticated")`: the JSON body `{ "accessFailure": "unauthenticated" }` with `Cache-Control: no-store`), and sends a returned `cookie` as `Set-Cookie` on the 401 and on the stream response alike, so a session the call refreshed reaches the browser.
122
+ When `authenticate` throws, the handler logs the error through `logger` and answers 500 with `{ "error": "authentication failed on the server" }`, so nothing of the session infrastructure reaches the client.
121
123
  The stream is sent with `Cache-Control: no-store, no-transform`.
122
124
 
123
125
  The resume cursor (`StreamCursor`: each chunk line's `nextCursor`, sent back as `cursor_contacted_at` / `cursor_person_id`) is written by the server and opaque to clients. Its `contacted_at` is the last row's value in UTC with exactly 7 fractional digits (`YYYY-MM-DDThh:mm:ss.fffffffZ`, the 100 ns of `datetime2(7)`), read from the database as text so that no digit is lost to the driver's millisecond `Date`, or `null` once the stream has reached the rows without one; its `person_id` is the last row's id, any safe integer (a signed key may be negative).
@@ -125,18 +127,19 @@ The chunk query checks both values by the rules below when it writes the cursor,
125
127
  The handler accepts only that form naming a real instant from year 1 on and a `cursor_person_id` holding a safe integer written in canonical decimal (`0`, or digits without a leading zero after an optional minus sign); anything else (`-0`, `+5`, `05`, `1e3`, …) gets 400 before authenticating.
126
128
  The next chunk compares the bare column with the cursor cast to `datetime2(7)`, so an index on (`is_active`, `contacted_at`, `person_id`) can seek. `createContactMapServer().getContactsStreamChunk(cursor)` checks the cursor by the same rules and throws a `TypeError` (a value of the wrong type or shape) or a `RangeError` (any other form) before connecting.
127
129
  `ContactMapStreamClient` sends the cursor back unchanged. When a resumed request gets 400 (the cursor was written by a server of another version), it drops the cursor and loads from the beginning again once, keeping the records it has (they are keyed by `person_id`); a 400 to a request without a cursor, or a second 400 in the same load, ends the load at once with `[contact-map] the server rejected the stream request (400); reload the page`.
128
- A 401 or 403 ends the load at once in phase `auth-required` with the error `Authentication required`, without retrying (`retryNow()` starts again from the last cursor, for example after the user signs in again; meanwhile the failure notice below the header shows `streamAuthRequired` and its retry button, see Stream Status).
130
+ A 401 or 403 is an access failure, read from the status alone (`accessFailureKindOfStatus` of `@aiquants/auth-core`; the body is not read): the load ends at once without retrying, in phase `unauthenticated` (401) or `forbidden` (403), with no error (`retryNow()` starts again from the last cursor, for example after the user signs in again or is granted the permission; meanwhile the failure notice below the header holds the node of the host's access failure presenter, see Access Failures).
129
131
  Any other failed response (the 500 of a throwing `authenticate` included) is retried with backoff (1 s, doubling up to 30 s; the annotation shows `annotationReconnecting` meanwhile) and sets the error to `[contact-map] the stream request failed (status <status>)`. The sixth failure in a row ends the load in phase `failed` (`retryNow()` starts again from the last cursor; the failure notice shows `streamLoadFailed` and its retry button meanwhile).
130
132
 
131
133
  `db`・`table`・`ensureConnection`・`authenticate` は必須で、`db` か `table` が無い、`table.contacted_at` が無いか Drizzle の列でない、`ensureConnection` か `authenticate` が関数でない、または `firstBatchSize` / `nextBatchSize` が数値でなければ `createContactMapStreamHandler` / `createContactMapServer` は `TypeError` を、`table.contacted_at` が `datetime2` の列 (`datetime2` か `datetime2(0)` から `datetime2(7)`。`datetime`・`datetimeoffset`・`date` の列は断る) でないか、`firstBatchSize` か `nextBatchSize` が 1 から `Number.MAX_SAFE_INTEGER` までの整数でない数値なら `RangeError` を投げる。
132
- どの文言も設定を名指し、与えた値で終わる (`[contact-map] server config authenticate must be the function that returns the request's user (…); got undefined`、`[contact-map] server config table.contacted_at must be a Drizzle datetime2 column; got "datetime"`)。誰にでも開くストリームは user を返す `authenticate` で明示し、設定を書き漏らしても認証なしで連絡先を配ることはない。ハンドラーは再開カーソルを検査してから (不正な形は認証せずに 400) `authenticate(request, { failureRedirect: null })` を呼び、user が無ければ 401 を返し、返された `cookie` は 401 にもストリームの応答にも `Set-Cookie` で載せる (呼び出しが更新したセッションをブラウザへ届ける)。
134
+ どの文言も設定を名指し、与えた値で終わる (`[contact-map] server config authenticate must be the function that returns the request's user (…); got undefined`、`[contact-map] server config table.contacted_at must be a Drizzle datetime2 column; got "datetime"`)。誰にでも開くストリームは user を返す `authenticate` で明示し、設定を書き漏らしても認証なしで連絡先を配ることはない。
135
+ ハンドラーは再開カーソルを検査してから (不正な形は認証せずに 400) `authenticate(request, { failureRedirect: null })` を呼び、user が無ければ `@aiquants/auth-core` の 401 (`accessFailureResponse("unauthenticated")`。JSON の本文 `{ "accessFailure": "unauthenticated" }` と `Cache-Control: no-store`) を返し、返された `cookie` は 401 にもストリームの応答にも `Set-Cookie` で載せる (呼び出しが更新したセッションをブラウザへ届ける)。
133
136
  `authenticate` が例外を投げると、ハンドラーはそのエラーを `logger` へ出し、500 (`{ "error": "authentication failed on the server" }`) を返す (セッションの基盤の詳細はクライアントへ出さない)。ストリームは `Cache-Control: no-store, no-transform` で送る。
134
137
 
135
138
  再開カーソル (`StreamCursor`。各チャンク行の `nextCursor` で、`cursor_contacted_at` / `cursor_person_id` として送り返す) はサーバーが書き、クライアントにとって形は不透明。`contacted_at` は最後の行の値を UTC で小数部ちょうど 7 桁 (`YYYY-MM-DDThh:mm:ss.fffffffZ`、`datetime2(7)` の 100 ns) で表したもので、ドライバのミリ秒までの `Date` で桁を落とさないようデータベースから文字列で読む。日時の無い行へ進んだ後は `null`。`person_id` は最後の行の ID で、負を含む任意の安全な整数 (符号付きのキーは負にもなる)。
136
139
  チャンクの照会はカーソルを書くときに両方の値を下の規則で確かめるので、サーバーが書いたカーソルは次の要求が必ず受け入れる。最後の行の `person_id` が安全な整数でないチャンクは、その値を示すエラーで失敗する。
137
140
  ハンドラーは 1 年以降の実在する日時を表すこの形と、安全な整数を正規の 10 進 (`0` か、省略できる負の符号に続く先頭が 0 でない数字) で書いた `cursor_person_id` だけを受け入れ、それ以外 (`-0`・`+5`・`05`・`1e3` など) は認証の前に 400 で断る。次のチャンクは素の列と `datetime2(7)` へ CAST したカーソルを比べるので、(`is_active`, `contacted_at`, `person_id`) の索引でシークできる。`createContactMapServer().getContactsStreamChunk(cursor)` も同じ規則でカーソルを検査し、接続の前に `TypeError` (型や形の誤り) か `RangeError` (それ以外の形) を投げる。
138
141
  `ContactMapStreamClient` はカーソルをそのまま送り返す。再開した要求が 400 を受けたら (別の版のサーバーが書いたカーソル)、カーソルを捨てて最初から 1 回だけ読み直し、受信済みのレコードは残す (`person_id` で重ねる)。カーソルの無い要求への 400 と、同じ読み込みでの 2 回目の 400 は、`[contact-map] the server rejected the stream request (400); reload the page` で即座に読み込みを終える。
139
- 401 と 403 は再試行せず、段階 `auth-required`・エラー `Authentication required` で即座に読み込みを終える (`retryNow()` で最終カーソルから読み直す。たとえば再ログインの後。その間、見出しの下の失敗の知らせが `streamAuthRequired` と再試行のボタンを見せる。ストリームの状態の表示の節を参照)。それ以外の失敗の応答 (`authenticate` が投げたときの 500 を含む) はバックオフ (1 秒から倍々に最大 30 秒。その間、注記は `annotationReconnecting` を表示) で再試行し、エラーを `[contact-map] the stream request failed (status <status>)` にする。続けて 6 回目の失敗で、段階 `failed` として読み込みを終える (`retryNow()` で最終カーソルから始め直す。その間、失敗の知らせが `streamLoadFailed` と再試行のボタンを見せる)。
142
+ 401 と 403 はアクセスの失敗で、状態だけから読む (`@aiquants/auth-core` の `accessFailureKindOfStatus`。本文は読まない)。再試行せずに即座に読み込みを終え、段階は 401 が `unauthenticated`、403 が `forbidden` で、エラーは持たない (`retryNow()` で最終カーソルから読み直す。たとえばサインインし直した後や権限を得た後。その間、見出しの下の失敗の知らせがホストのアクセスの失敗の示し手の node を持つ。アクセスの失敗の節を参照)。それ以外の失敗の応答 (`authenticate` が投げたときの 500 を含む) はバックオフ (1 秒から倍々に最大 30 秒。その間、注記は `annotationReconnecting` を表示) で再試行し、エラーを `[contact-map] the stream request failed (status <status>)` にする。続けて 6 回目の失敗で、段階 `failed` として読み込みを終える (`retryNow()` で最終カーソルから始め直す。その間、失敗の知らせが `streamLoadFailed` と再試行のボタンを見せる)。
140
143
 
141
144
  ### 2. Client Page Setup / クライアント側ページの設定
142
145
 
@@ -341,24 +344,30 @@ The steps read these host CSS variables, each the step's value while the host le
341
344
  `ContactMapAppView` はストリームの状態を 3 つの部品で見せる。ホストは見出しを畳むことがある (スマホの幅など) ので、見出しには利用者が操作するものも聞くべきものも置かない。
342
345
 
343
346
  - **The annotation** (`ContactMapAnnotation`, the `annotation` that `renderHeader` places): the record and company counts, a progress badge while the stream is idle or streaming, and a reconnecting badge (`annotationReconnecting`) while it waits to retry. It is not a live region and holds no control.
344
- - **The failure notice** (`ContactMapStreamFailureNotice`): while the phase is `failed` or `auth-required`, a band in the flow right after the header (the host's `renderHeader` or the default heading) and before the search page shows the message (`streamLoadFailed` with the received count, or `streamAuthRequired`) and a retry button (`streamRetry`) that calls the stream's `retryNow()`.
345
- The band is a group named by the message, which also describes the button; it is not a live region (the announcer tells the change). The `failed` message carries the client's English error text as its tooltip (`title`), supplementary detail drawn by the browser; `auth-required` carries none, since its message tells the cause.
346
- The band overlaps neither the header nor the page: it pushes the page down by its height and 8 px, and a one-line band is 52 px tall (1 + 3 + 44 + 3 + 1), on the 4 px lattice. Its text is the rose tone's on the tone's tint (7.21:1 in the light scheme, 11.09:1 in the dark one); the button is a 44 × 44 px target on the surface (its text 7.92:1 and 12.59:1), outlined by the control outline (4.34:1 and 5.97:1 on the band) and ringed by the package's focus ring (6.22:1 and 9.42:1 on the band).
347
- When the band leaves while it holds focus (the retry pressed, or another call of the stream's `retryNow()`, which a component mounting `useContactMapStream` makes for a stream that failed), focus goes to the search page beside it instead of falling to the body: to the search field, or to the selected page tab while the page shows its settings or its statistics (the field is then not rendered). Focus put elsewhere by then stays where it is.
347
+ - **The failure notice** (`ContactMapStreamFailureNotice`): in the flow right after the header (the host's `renderHeader` or the default heading) and before the search page, while the stream gave up or the server refused it, and nothing in the other phases.
348
+ While the phase is `failed`, a band shows the message (`streamLoadFailed` with the received count) and a retry button (`streamRetry`) that calls the stream's `retryNow()`. The band is a group named by the message, which also describes the button; it is not a live region (the announcer tells the change). The message carries the client's English error text as its tooltip (`title`), supplementary detail drawn by the browser.
349
+ While the phase is `unauthenticated` (a 401) or `forbidden` (a 403), a slot in the same place holds the node of the host's access failure presenter instead, and the notice draws no band and words nothing itself (see Access Failures).
350
+ The band and the slot overlap neither the header nor the page: they push the page down by their height and 8 px, and a one-line band is 52 px tall (1 + 3 + 44 + 3 + 1), on the 4 px lattice. Its text is the rose tone's on the tone's tint (7.21:1 in the light scheme, 11.09:1 in the dark one); the button is a 44 × 44 px target on the surface (its text 7.92:1 and 12.59:1), outlined by the control outline (4.34:1 and 5.97:1 on the band) and ringed by the package's focus ring (6.22:1 and 9.42:1 on the band).
351
+ When the band or the slot leaves while it holds focus (the retry pressed, or another call of the stream's `retryNow()`, which a component mounting `useContactMapStream` makes for a stream that failed or was refused), focus goes to the search page beside it instead of falling to the body: to the search field, or to the selected page tab while the page shows its settings or its statistics (the field is then not rendered).
352
+ The same holds when one of them replaces the other (`failed` and an access failure, or one kind and the other) while it holds focus. Focus put elsewhere by then stays where it is.
348
353
  - **The announcer** (`ContactMapStreamAnnouncer`): one per view, outside the header and the notice, a visually hidden box of one polite status region (`role="status"`) and one assertive alert region (`role="alert"`), both mounted empty.
349
- It announces only the phase changes after mount, each with the text of the phase it entered, written once as it enters it: `retrying` as a status (`annotationReconnecting`), `failed` and `auth-required` as alerts (`streamLoadFailed`, `streamAuthRequired`), and the other phases empty both regions. A change of the received count within a phase is not announced, and neither is the phase at mount (the annotation and the notice show it). They are the package's only live regions.
354
+ It announces only the phase changes after mount, each with the text of the phase it entered, written once as it enters it: `retrying` as a status (`annotationReconnecting`), `failed` as an alert (`streamLoadFailed`), and the other phases empty both regions, the access failures (`unauthenticated`, `forbidden`) included: the presenter's node speaks for itself, so the failure is not read twice. A change of the received count within a phase is not announced, and neither is the phase at mount (the annotation and the notice show it). They are the package's only live regions.
350
355
 
351
356
  - **注記** (`ContactMapAnnotation`。`renderHeader` が置く `annotation`): 登録件数と企業数、ストリームが待機中か受信中の間は進捗の札、再試行を待つ間は再接続中の札 (`annotationReconnecting`)。読み上げの領域ではなく、操作部品も持たない。
352
- - **失敗の知らせ** (`ContactMapStreamFailureNotice`): 局面が `failed` か `auth-required` の間、見出し (ホストの `renderHeader` か既定の見出し) の直後・検索のページの前の流れの中の帯に、文 (受信済みの件数を持つ `streamLoadFailed` か `streamAuthRequired`) と、ストリームの `retryNow()` を呼ぶ再試行のボタン (`streamRetry`) を見せる。帯は文を名前に持つグループで、文はボタンの説明でもある。読み上げの領域ではない (移り変わりは読み上げの部品が知らせる)。`failed` の文はクライアントの英語のエラー文をツールチップ (`title`) に持つ (ブラウザーが描く補足)。`auth-required` の文は原因を自分で告げるので持たない。
353
- 帯は見出しにもページにも重ならない: ページを帯の高さと 8 px だけ下へ押し、1 行の帯は高さ 52 px (1 + 3 + 44 + 3 + 1) で 4 px の格子に乗る。文字は rose の色調の淡い面の上の色調の文字 (明るい配色で 7.21:1、暗い配色で 11.09:1)。ボタンは面の上の 44 × 44 px の的 (文字は 7.92:1 と 12.59:1) で、操作部品の輪郭 (帯の上で 4.34:1 と 5.97:1) とパッケージのフォーカスの輪 (帯の上で 6.22:1 と 9.42:1) を持つ。
354
- 帯がフォーカスを持ったまま外れると (再試行の押下か、ストリームの `retryNow()` のほかの呼び出し。`useContactMapStream` をマウントする部品は失敗したストリームを再試行する)、フォーカスは body へ落とさず傍らの検索のページへ渡す: 検索欄へ、ページが検索設定か検索統計を見せる間は (検索欄が描かれない) 選ばれたページのタブへ。それまでに別の所へ置かれたフォーカスはそのまま。
355
- - **読み上げの部品** (`ContactMapStreamAnnouncer`): ビューに 1 つ、見出しと知らせの外に置く。画面に出さない箱に控えめな状態の領域 (`role="status"`) と割り込む警告の領域 (`role="alert"`) を 1 つずつ持ち、どちらも空のままマウントする。知らせるのはマウントの後の局面の移り変わりだけで、入った局面の文字を入ったときに 1 度だけ書く: `retrying` は状態 (`annotationReconnecting`)、`failed` と `auth-required` は警告 (`streamLoadFailed`・`streamAuthRequired`)、ほかの局面は両方の領域を空にする。局面の中での受信済みの件数の増減は知らせず、マウントの時点の局面も知らせない (注記と知らせが見せている)。パッケージの読み上げの領域はこの 2 つだけ。
357
+ - **失敗の知らせ** (`ContactMapStreamFailureNotice`): ストリームが諦めたかサーバーが断った間、見出し (ホストの `renderHeader` か既定の見出し) の直後・検索のページの前の流れの中に描き、ほかの局面では何も描かない。
358
+ 局面が `failed` の間は、帯に文 (受信済みの件数を持つ `streamLoadFailed`) と、ストリームの `retryNow()` を呼ぶ再試行のボタン (`streamRetry`) を見せる。帯は文を名前に持つグループで、文はボタンの説明でもある。読み上げの領域ではない (移り変わりは読み上げの部品が知らせる)。文はクライアントの英語のエラー文をツールチップ (`title`) に持つ (ブラウザーが描く補足)。
359
+ 局面が `unauthenticated` (401) か `forbidden` (403) の間は、同じ所の置き場がホストのアクセスの失敗の示し手の node を持ち、知らせは帯を描かず、自分では何も書かない (アクセスの失敗の節を参照)。
360
+ 帯と置き場は見出しにもページにも重ならない: ページを自分の高さと 8 px だけ下へ押し、1 行の帯は高さ 52 px (1 + 3 + 44 + 3 + 1) で 4 px の格子に乗る。文字は rose の色調の淡い面の上の色調の文字 (明るい配色で 7.21:1、暗い配色で 11.09:1)。ボタンは面の上の 44 × 44 px の的 (文字は 7.92:1 と 12.59:1) で、操作部品の輪郭 (帯の上で 4.34:1 と 5.97:1) とパッケージのフォーカスの輪 (帯の上で 6.22:1 と 9.42:1) を持つ。
361
+ 帯か置き場がフォーカスを持ったまま外れると (再試行の押下か、ストリームの `retryNow()` のほかの呼び出し。`useContactMapStream` をマウントする部品は失敗した・断られたストリームを再試行する)、フォーカスは body へ落とさず傍らの検索のページへ渡す: 検索欄へ、ページが検索設定か検索統計を見せる間は (検索欄が描かれない) 選ばれたページのタブへ。フォーカスを持ったまま一方が他方に替わるとき (`failed` とアクセスの失敗、または 2 つの種類どうし) も同じ。それまでに別の所へ置かれたフォーカスはそのまま。
362
+ - **読み上げの部品** (`ContactMapStreamAnnouncer`): ビューに 1 つ、見出しと知らせの外に置く。画面に出さない箱に控えめな状態の領域 (`role="status"`) と割り込む警告の領域 (`role="alert"`) を 1 つずつ持ち、どちらも空のままマウントする。知らせるのはマウントの後の局面の移り変わりだけで、入った局面の文字を入ったときに 1 度だけ書く: `retrying` は状態 (`annotationReconnecting`)、`failed` は警告 (`streamLoadFailed`)、ほかの局面は両方の領域を空にする。アクセスの失敗 (`unauthenticated`・`forbidden`) も空にする (示し手の node が自ら読み上げるので、同じ失敗を 2 度読ませない)。局面の中での受信済みの件数の増減は知らせず、マウントの時点の局面も知らせない (注記と知らせが見せている)。パッケージの読み上げの領域はこの 2 つだけ。
356
363
 
357
- A host that composes the page itself (`ContactMapSearchPage` under its own header) places the same parts: the announcer outside its header and the notice right after it, with the stream's `retryNow`.
358
- ページを自分で組むホスト (自分の見出しの下に `ContactMapSearchPage`) も同じ部品を置く: 読み上げの部品を見出しの外に、知らせを見出しの直後に置き、ストリームの `retryNow` を渡す。
364
+ A host that composes the page itself (`ContactMapSearchPage` under its own header) places the same parts: the announcer outside its header and the notice right after it, with the outlet context's `streamAccessFailureNumber`, the stream's `retryNow` and its access failure presenter.
365
+ ページを自分で組むホスト (自分の見出しの下に `ContactMapSearchPage`) も同じ部品を置く: 読み上げの部品を見出しの外に、知らせを見出しの直後に置き、アウトレットコンテキストの `streamAccessFailureNumber`・ストリームの `retryNow`・自分のアクセスの失敗の示し手を渡す。
359
366
 
360
367
  ```tsx
361
368
  import { ContactMapAnnotation, ContactMapSearchPage, ContactMapStreamAnnouncer, ContactMapStreamFailureNotice, useStreamedContactMapContext } from "@aiquants/contact-map/client"
369
+ // the host's AccessFailurePresenter<ReactNode> of @aiquants/auth-core (one per language)
370
+ import { accessFailure } from "~/access-failure"
362
371
 
363
372
  // rendered inside ContactMapConfigProvider and a router
364
373
  function ContactMapScreen() {
@@ -369,7 +378,7 @@ function ContactMapScreen() {
369
378
  <header>
370
379
  <ContactMapAnnotation recordCount={context.contactMapRecords.length} companyCount={context.companyCount} phase={context.streamPhase} loadedCount={context.loadedCount} totalCount={context.totalCount} />
371
380
  </header>
372
- <ContactMapStreamFailureNotice phase={context.streamPhase} loadedCount={context.loadedCount} errorMessage={context.errorMessage} onRetry={retryNow} />
381
+ <ContactMapStreamFailureNotice phase={context.streamPhase} accessFailureNumber={context.streamAccessFailureNumber} loadedCount={context.loadedCount} errorMessage={context.errorMessage} onRetry={retryNow} accessFailure={accessFailure} />
373
382
  <div className="min-h-0 flex-1">
374
383
  <ContactMapSearchPage streamState={context} />
375
384
  </div>
@@ -378,6 +387,32 @@ function ContactMapScreen() {
378
387
  }
379
388
  ```
380
389
 
390
+ ## Access Failures / アクセスの失敗
391
+
392
+ contact-map keeps no words of its own for an access failure. The host passes its access failure presenter as `accessFailure` (an `AccessFailurePresenter<ReactNode>` of `@aiquants/auth-core`) to `ContactMapAppView`, and to `ContactMapStreamFailureNotice` when it composes the page itself. It is required on both: anything but a function throws a `TypeError` naming the setting (`ContactMapAppView accessFailure`, `ContactMapStreamFailureNotice accessFailure`), and the view reads only the prop it owns, so one inherited from `Object.prototype` is refused like a missing one.
393
+ A page the host composes also passes the outlet context's `streamAccessFailureNumber` to the notice as `accessFailureNumber`, which `ContactMapAppView` passes itself. It is required: anything but a non-negative safe integer throws in every phase, naming `ContactMapStreamFailureNotice accessFailureNumber`, a `TypeError` for a non-number (left out included) and a `RangeError` for `NaN`, `Infinity`, a negative number or a fraction.
394
+
395
+ - The stream client reads the kind from the status alone (`accessFailureKindOfStatus`): a 401 is `unauthenticated` and a 403 `forbidden`, whatever the body says, and any other failed status is retried with backoff. The phase keeps the kind until `retryNow()`, the records received so far stay, and the state's `error` is `null`.
396
+ The state's `accessFailureNumber` (the outlet context's `streamAccessFailureNumber`) counts the refusals: 0 before the first, one more at each 401 or 403, and never reset (a retry, a backoff wait, a `failed` stream and the completion keep it).
397
+ - While the phase is an access failure, the notice's slot (`data-testid="contact-map-stream-access-failure"`, its `data-phase` the kind) holds the node the presenter returns for the occurrence `{ kind, place: "read", deniedSentence: null, retry }`: `kind` is the phase, `place` says the stream is a read, `deniedSentence` is `null` (the presenter words a refused read), and `retry` calls the latest `onRetry`, the stream's `retryNow()` in `ContactMapAppView`.
398
+ - One node per failure, as auth-core's `AccessFailurePresenter` asks of a package: the slot is keyed by `accessFailureNumber` alone. While the number stays, the presenter's node stays mounted and its occurrence, a frozen object by whose identity a presenter may tell one occurrence from the next, stays the same, through re-renders that change the counts, the error text or `onRetry`.
399
+ Every new failure (a new number: the stream refused again, of the same kind or the other) mounts a new node with a new occurrence in a new slot, whatever was rendered between the two failures, so a host that defers or skips the phase between them (a hidden `Activity`, a deferred value) still gets a new node. The notice calls the presenter while rendering, so pass a stable presenter (one per language, for example).
400
+ - Neither the notice nor the announcer words or announces an access failure: the presenter's node carries the words, the actions (signing in again, asking for the permission) and its own announcement.
401
+ - `isStreamingFailed` of `useStreamedContactMapContext()` is `true` in both access failures, as in `failed`: the stream stopped before its end and waits for a retry, so the tree does not keep showing that it is loading.
402
+ - The server answers a request without a user with `accessFailureResponse("unauthenticated")` (see Server Route Setup).
403
+
404
+ contact-map はアクセスの失敗の言葉を自分では持たない。ホストはアクセスの失敗の示し手を `accessFailure` (`@aiquants/auth-core` の `AccessFailurePresenter<ReactNode>`) として `ContactMapAppView` へ渡し、ページを自分で組むときは `ContactMapStreamFailureNotice` へ渡す。どちらでも必須で、関数でない値は設定を名指す `TypeError` (`ContactMapAppView accessFailure`・`ContactMapStreamFailureNotice accessFailure`) を投げる。ビューは props が自身で持つ値だけを読むので、`Object.prototype` から継承した値は渡し忘れと同じく拒む。
405
+ ホストが組むページは、アウトレットコンテキストの `streamAccessFailureNumber` も `accessFailureNumber` として知らせへ渡す (`ContactMapAppView` は自分で渡す)。必須で、0 以上の安全な整数でなければ局面を問わず `ContactMapStreamFailureNotice accessFailureNumber` を名指して投げる (数値でなければ省略を含めて `TypeError`、`NaN`・`Infinity`・負の数・小数は `RangeError`)。
406
+
407
+ - ストリームのクライアントは種類を状態だけから読む (`accessFailureKindOfStatus`): 401 は `unauthenticated`、403 は `forbidden` で、本文が何を告げても変わらない。ほかの失敗の状態はバックオフで再試行する。局面は `retryNow()` まで種類を保ち、受信済みのレコードは残り、状態の `error` は `null`。
408
+ 状態の `accessFailureNumber` (アウトレットコンテキストの `streamAccessFailureNumber`) は断られた回数: 最初の前は 0、401 か 403 のたびに 1 つ進み、戻さない (再試行・バックオフの待ち・`failed` のストリーム・完了でも保つ)。
409
+ - 局面がアクセスの失敗の間、知らせの置き場 (`data-testid="contact-map-stream-access-failure"`。`data-phase` は種類) が、発生 `{ kind, place: "read", deniedSentence: null, retry }` に示し手が返す node を持つ: `kind` は局面、`place` はストリームが読み取りであること、`deniedSentence` は `null` (示し手が読み取りの拒否として書く)、`retry` は最新の `onRetry` (`ContactMapAppView` ではストリームの `retryNow()`) を呼ぶ。
410
+ - auth-core の `AccessFailurePresenter` が包みに求めるとおり、1 つの失敗に 1 つの node: 置き場の鍵は `accessFailureNumber` だけ。番号が変わらない間は、件数・エラー文・`onRetry` が替わる描き直しでも、示し手の node は付いたままで、発生 (凍結したオブジェクト。示し手は同じかで発生を見分けられる) も同じ。
411
+ 新しい失敗 (新しい番号。ストリームがまた断られた。同じ種類でも、もう一方の種類でも) ごとに、2 つの失敗の間に何が描かれたかによらず、新しい置き場に新しい発生とともに新しい node を付ける。間の局面を遅らせるか描かないホスト (隠れた `Activity`・遅らせた値) でも新しい node になる。知らせは描く間に示し手を呼ぶので、変わらない示し手 (例: 言語ごとに 1 つ) を渡す。
412
+ - 知らせも読み上げの部品もアクセスの失敗を書かず、読み上げない: 言葉・操作 (サインインし直し・権限の依頼)・読み上げは示し手の node が持つ。
413
+ - `useStreamedContactMapContext()` の `isStreamingFailed` は、`failed` と同じく 2 つのアクセスの失敗でも `true` (ストリームは終わりの前に止まり再試行を待つので、ツリーは読み込み中と見せ続けない)。
414
+ - サーバーは user の無い要求に `accessFailureResponse("unauthenticated")` で答える (サーバー側ストリーミングルートの設定の節を参照)。
415
+
381
416
  ## Mobile Detail Overlay / モバイルの詳細オーバーレイ
382
417
 
383
418
  When the list or the tree view is a single column (narrower than its two-column threshold), choosing a contact opens its details in an overlay, `SwipeOverlay`: a panel at the right edge, which renders the platform's modal dialog through `@aiquants/swipe-overlay`'s `useSwipeOverlayDialog`.
@@ -471,7 +506,8 @@ Hosts and their tests find the package's overlays, the list's state, the stream'
471
506
  | `data-contact-popup-card` | The long-press popup's card |
472
507
  | `data-selected` (`"true"` / `"false"`) | A list row: whether it is the selected contact, as its `aria-selected` says |
473
508
  | `data-contact-map-row-active` | The list's active option, the row the keyboard is on |
474
- | `data-testid="contact-map-stream-failure-notice"` | The stream failure notice's band; `data-phase` is `"failed"` or `"auth-required"` |
509
+ | `data-testid="contact-map-stream-failure-notice"` | The stream failure notice's band after the stream gave up; `data-phase` is `"failed"` |
510
+ | `data-testid="contact-map-stream-access-failure"` | The stream failure notice's slot for an access failure, holding the presenter's node; `data-phase` is `"unauthenticated"` or `"forbidden"` |
475
511
  | `data-testid="contact-map-retry-button"` | The failure notice's retry button |
476
512
  | `data-testid="contact-map-stream-announcer"` | The stream announcer's visually hidden box, holding one `role="status"` and one `role="alert"` region |
477
513
  | `data-contact-map-search-page` | The search page's root (where the failure notice hands focus as it leaves) |
@@ -488,7 +524,8 @@ Hosts and their tests find the package's overlays, the list's state, the stream'
488
524
  | `data-contact-popup-card` | 長押しのポップアップのカード |
489
525
  | `data-selected` (`"true"` / `"false"`) | 一覧の行。選んだ連絡先か (`aria-selected` と同じ) |
490
526
  | `data-contact-map-row-active` | 一覧のアクティブな選択肢 (キーボードがいる行) |
491
- | `data-testid="contact-map-stream-failure-notice"` | ストリームの失敗の知らせの帯。`data-phase` は `"failed"` か `"auth-required"` |
527
+ | `data-testid="contact-map-stream-failure-notice"` | ストリームが諦めた後の失敗の知らせの帯。`data-phase` は `"failed"` |
528
+ | `data-testid="contact-map-stream-access-failure"` | アクセスの失敗の間の失敗の知らせの置き場 (示し手の node を持つ)。`data-phase` は `"unauthenticated"` か `"forbidden"` |
492
529
  | `data-testid="contact-map-retry-button"` | 失敗の知らせの再試行のボタン |
493
530
  | `data-testid="contact-map-stream-announcer"` | ストリームの読み上げの部品の画面に出さない箱 (`role="status"` と `role="alert"` の領域を 1 つずつ持つ) |
494
531
  | `data-contact-map-search-page` | 検索のページの根 (失敗の知らせが外れるときにフォーカスを渡す先) |
@@ -554,6 +591,7 @@ Every string the client components render on their own (tabs, buttons, headings,
554
591
  | `ContactMapConfigProvider` | `config.openEmailsWithGmail` | `boolean` | Initial value of the settings tab's Gmail toggle; omitted ⇒ `false`. While it is on, an email address links to Gmail's web compose window instead of `mailto:`, and double-clicking (or double-tapping) an address in the popup opens it. |
555
592
  | `ContactMapConfigProvider` | `config.treeWorkerFactory` | `() => Worker` | Builds the tree Worker for a bundler that needs its own construction; every call must return a new Worker, and each hook then has its own session (see the tree paragraphs above). |
556
593
  | `ContactMapConfigProvider` | `config.workerUrls` | `ContactMapWorkerUrls` | A plain object of only `indexWorker`, `levenshteinWorker` and `treeWorker`, each left out or a string with non-whitespace; checked in every render, a server render included (`assertContactMapWorkerUrls`: `TypeError` / `RangeError`); the views read only the checked copy. One `treeWorker` per browser tab (see the tree paragraph above). |
594
+ | `ContactMapAppView` | `accessFailure` | `AccessFailurePresenter<ReactNode>` | Required. The host's access failure presenter of `@aiquants/auth-core` (see Access Failures); anything but a function throws a `TypeError` naming `ContactMapAppView accessFailure`. |
557
595
  | `ContactMapAppView` | `streamEndpoint` | `string` | When given it wins over the surrounding provider's `streamEndpoint`. |
558
596
  | `ContactMapAppView` | `locale` | `ContactMapLocale` | When given it wins over the surrounding provider's `locale`; its errors name `ContactMapAppView locale`. |
559
597
  | `ContactMapAppView` | `labels` | `ContactMapLabelOverrides` | When given the whole object replaces the surrounding provider's `labels` (no key-wise merge); its errors name `ContactMapAppView labels`. |
@@ -567,9 +605,11 @@ Components rendered outside any provider use the `en` catalog. `useContactMapLab
567
605
 
568
606
  ```tsx
569
607
  import { ContactMapAppView } from "@aiquants/contact-map/client"
608
+ // the host's AccessFailurePresenter<ReactNode> of @aiquants/auth-core (one per language)
609
+ import { accessFailure } from "~/access-failure"
570
610
 
571
611
  export default function ContactMapRoute() {
572
- return <ContactMapAppView streamEndpoint="/api/contact_map/stream" locale="ja" labels={{ appTitle: "連絡先マップ" }} />
612
+ return <ContactMapAppView accessFailure={accessFailure} streamEndpoint="/api/contact_map/stream" locale="ja" labels={{ appTitle: "連絡先マップ" }} />
573
613
  }
574
614
  ```
575
615
 
@@ -655,7 +695,6 @@ Function keys are shown with their arguments; the cells show sample output (`cou
655
695
  | `annotationStreamingCount(loaded)` | `"Streaming (1,200 loaded)"` | `"ストリーミング読み込み中 (1,200 件)"` |
656
696
  | `streamLoadFailed(loaded)` | `"Failed to load (1,200 received)"` | `"読み込みに失敗しました (1,200 件受信済)"` |
657
697
  | `annotationReconnecting(loaded)` | `"Reconnecting (1,200 received)"` | `"再接続中 (1,200 件受信済)"` |
658
- | `streamAuthRequired` | `"Session expired: sign in again, then retry"` | `"セッションが切れました。サインインし直してから再試行してください"` |
659
698
  | `streamRetry` | `"Retry"` | `"再試行"` |
660
699
  | `recordUnit(displayed)` | `"records"` | `"件"` |
661
700
  | `companyUnit(displayed)` | `"companies"` | `"社"` |
package/dist/client.d.mts CHANGED
@@ -1,7 +1,8 @@
1
1
  import * as react from "react";
2
2
  import { CSSProperties, ReactNode, RefObject, PointerEvent, MouseEvent } from "react";
3
3
  import { UseFuzzySearchOptions } from "@aiquants/fuzzy-search/react";
4
- import { C as ContactRecord, a as ContactMapStreamPhase, b as ContactMapSearchOutletContext, c as ContactMapOutletContext, d as ContactMapLogger, S as SerializedContactStreamRow } from "./wire-CVZNwmQx.mjs";
4
+ import { C as ContactRecord, a as ContactMapStreamPhase, b as ContactMapSearchOutletContext, c as ContactMapOutletContext, d as ContactMapLogger, S as SerializedContactStreamRow } from "./wire-DxJO8OXK.mjs";
5
+ import { AccessFailurePresenter } from "@aiquants/auth-core";
5
6
  import { DirectoryTreeLabels, DirectoryTreeVirtualScrollOptions } from "@aiquants/directory-tree";
6
7
  import * as _aiquants_virtualscroll from "@aiquants/virtualscroll";
7
8
  import { VirtualScrollLocale } from "@aiquants/virtualscroll";
@@ -91,7 +92,6 @@ type ContactMapOwnLabels = {
91
92
  readonly annotationStreamingCount: (loaded: number) => string;
92
93
  readonly streamLoadFailed: (loaded: number) => string;
93
94
  readonly annotationReconnecting: (loaded: number) => string;
94
- readonly streamAuthRequired: string;
95
95
  readonly streamRetry: string;
96
96
  readonly recordUnit: (displayed: string) => string;
97
97
  readonly companyUnit: (displayed: string) => string;
@@ -400,6 +400,7 @@ declare function assertContactMapWorkerUrls(workerUrls: unknown, surface?: Conta
400
400
  declare function assertContactMapTreeWorkerUrl(treeWorkerUrl: unknown): asserts treeWorkerUrl is string | undefined;
401
401
  declare const layerContactMapWorkerUrls: (provided: ContactMapWorkerUrls | undefined, own: ContactMapWorkerUrls | undefined, surface?: ContactMapWorkerUrlsSurface) => ContactMapWorkerUrls;
402
402
  interface ContactMapAppViewProps {
403
+ accessFailure: AccessFailurePresenter<ReactNode>;
403
404
  renderHeader?: (props: {
404
405
  title: string;
405
406
  annotation: ReactNode;
@@ -476,9 +477,11 @@ interface ContactMapStreamAnnouncerProps {
476
477
  declare const ContactMapStreamAnnouncer: react.NamedExoticComponent<ContactMapStreamAnnouncerProps>;
477
478
  interface ContactMapStreamFailureNoticeProps {
478
479
  phase: ContactMapStreamPhase;
480
+ accessFailureNumber: number;
479
481
  loadedCount: number;
480
482
  errorMessage: string | null;
481
483
  onRetry: () => void;
484
+ accessFailure: AccessFailurePresenter<ReactNode>;
482
485
  }
483
486
  declare const ContactMapStreamFailureNotice: react.NamedExoticComponent<ContactMapStreamFailureNoticeProps>;
484
487
  interface HighlightedTextProps {
@@ -567,6 +570,7 @@ type ContactMapStreamState = {
567
570
  isComplete: boolean;
568
571
  phase: ContactMapStreamPhase;
569
572
  error: Error | null;
573
+ accessFailureNumber: number;
570
574
  };
571
575
  type ContactMapStreamClientDeps = {
572
576
  fetchFn?: typeof fetch;
package/dist/client.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import * as react from "react";
2
2
  import { CSSProperties, ReactNode, RefObject, PointerEvent, MouseEvent } from "react";
3
3
  import { UseFuzzySearchOptions } from "@aiquants/fuzzy-search/react";
4
- import { C as ContactRecord, a as ContactMapStreamPhase, b as ContactMapSearchOutletContext, c as ContactMapOutletContext, d as ContactMapLogger, S as SerializedContactStreamRow } from "./wire-CVZNwmQx.js";
4
+ import { C as ContactRecord, a as ContactMapStreamPhase, b as ContactMapSearchOutletContext, c as ContactMapOutletContext, d as ContactMapLogger, S as SerializedContactStreamRow } from "./wire-DxJO8OXK.js";
5
+ import { AccessFailurePresenter } from "@aiquants/auth-core";
5
6
  import { DirectoryTreeLabels, DirectoryTreeVirtualScrollOptions } from "@aiquants/directory-tree";
6
7
  import * as _aiquants_virtualscroll from "@aiquants/virtualscroll";
7
8
  import { VirtualScrollLocale } from "@aiquants/virtualscroll";
@@ -91,7 +92,6 @@ type ContactMapOwnLabels = {
91
92
  readonly annotationStreamingCount: (loaded: number) => string;
92
93
  readonly streamLoadFailed: (loaded: number) => string;
93
94
  readonly annotationReconnecting: (loaded: number) => string;
94
- readonly streamAuthRequired: string;
95
95
  readonly streamRetry: string;
96
96
  readonly recordUnit: (displayed: string) => string;
97
97
  readonly companyUnit: (displayed: string) => string;
@@ -400,6 +400,7 @@ declare function assertContactMapWorkerUrls(workerUrls: unknown, surface?: Conta
400
400
  declare function assertContactMapTreeWorkerUrl(treeWorkerUrl: unknown): asserts treeWorkerUrl is string | undefined;
401
401
  declare const layerContactMapWorkerUrls: (provided: ContactMapWorkerUrls | undefined, own: ContactMapWorkerUrls | undefined, surface?: ContactMapWorkerUrlsSurface) => ContactMapWorkerUrls;
402
402
  interface ContactMapAppViewProps {
403
+ accessFailure: AccessFailurePresenter<ReactNode>;
403
404
  renderHeader?: (props: {
404
405
  title: string;
405
406
  annotation: ReactNode;
@@ -476,9 +477,11 @@ interface ContactMapStreamAnnouncerProps {
476
477
  declare const ContactMapStreamAnnouncer: react.NamedExoticComponent<ContactMapStreamAnnouncerProps>;
477
478
  interface ContactMapStreamFailureNoticeProps {
478
479
  phase: ContactMapStreamPhase;
480
+ accessFailureNumber: number;
479
481
  loadedCount: number;
480
482
  errorMessage: string | null;
481
483
  onRetry: () => void;
484
+ accessFailure: AccessFailurePresenter<ReactNode>;
482
485
  }
483
486
  declare const ContactMapStreamFailureNotice: react.NamedExoticComponent<ContactMapStreamFailureNoticeProps>;
484
487
  interface HighlightedTextProps {
@@ -567,6 +570,7 @@ type ContactMapStreamState = {
567
570
  isComplete: boolean;
568
571
  phase: ContactMapStreamPhase;
569
572
  error: Error | null;
573
+ accessFailureNumber: number;
570
574
  };
571
575
  type ContactMapStreamClientDeps = {
572
576
  fetchFn?: typeof fetch;