bwh-auth 0.4.0 → 0.6.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
@@ -231,6 +231,40 @@ It talks to the auth package's credential service (`oauth_server.credentials`) t
231
231
  - **Requests** send the session cookie and `X-CSRF-TOKEN`. A 401 or 419 response becomes "sign in again".
232
232
  - **While the server reports issuing unavailable** (OAuth switched off), the create forms are hidden, and revoke and delete still work.
233
233
  - **Token lifetimes** are ISO-8601 durations from the server, displayed as text (`PT4H` shows as "4 hours").
234
+ - **Your own HTTP client:** pass `request` to send every credential request through it, so it gets the same session-expiry handling as the rest of the app. `request(method, url, body)` resolves with `{ ok: true, status, payload }` (the parsed JSON; the component reads its `data` when present) or `{ ok: false, status, message }`, and the message is shown. With `request`, sending the CSRF token is the client's job; without it, the built-in `fetch` is used as above.
235
+ - **Your own form controls:** besides the required components, `components` may include `Textarea`, `Checkbox` (`{ id, checked, onCheckedChange }`) and `RadioGroup` (`{ name, value, onValueChange, options: [{ value, label }] }`). Each one you omit is rendered as the native element.
236
+
237
+ ```tsx
238
+ <ApiCredentialsSection
239
+ indexUrl="/account/api-credentials"
240
+ components={{ ...components, Textarea, Checkbox: AppCheckbox, RadioGroup: AppRadioGroup }}
241
+ request={(method, url, body) => myClient.send(method, url, body)}
242
+ />
243
+ ```
244
+
245
+ ### Grouped scope picker
246
+
247
+ When the index carries scope groups, both forms replace the flat checkbox list with a grouped picker. Every key is optional, and everything here is presentation: the credential stores exactly the scope ids that end up ticked, and the form posts `scopes` as explicit ids only (never a group or preset id).
248
+
249
+ | Index key | Shape | Used by |
250
+ | --- | --- | --- |
251
+ | `scope_groups` | `[{ id, label, description \| null, sensitive, scopes: [ids] }]` | OAuth-app form; token form unless `token_scope_groups` is present |
252
+ | `scope_presets` | `[{ id, label, description, scopes: [ids] }]` | likewise, with `token_scope_presets` |
253
+ | `scope_implications` | `{ "billing:write": ["billing:read"] }` | likewise, with `token_scope_implications` |
254
+ | `token_scopes` | `[{ id, description }]` | A narrower scope list for the token form (default: `scopes`) |
255
+ | `token_scope_groups`, `token_scope_presets`, `token_scope_implications` | as above | Token form |
256
+ | `token_connection_scopes`, `connection_token_lifetimes` | `[{ id, description }]`, ISO-8601 durations | Token form only: connection scopes are listed after the token scopes, and a token carrying one is offered `connection_token_lifetimes` instead of `token_lifetimes` |
257
+
258
+ - **No groups: nothing changes.** The picker renders the flat list exactly as before (no presets, no summary).
259
+ - **Presets** are a row of buttons. Clicking one replaces the selection with exactly that preset's scopes. `aria-pressed` is true only while the selection equals the preset exactly; a line below shows its description, or "Custom selection" otherwise. There is no "select all".
260
+ - **Groups** render as one `<fieldset>` each, in an auto-fill grid (`minmax(min(100%, 300px), 1fr)`, so phones get one column) with 44px touch targets. Scopes the groups do not name collect in a final "Other permissions" group. A preset that names a scope the surface does not offer is not shown.
261
+ - **Sensitive groups** render as one parent checkbox (checked when all its scopes are ticked, `indeterminate` and `aria-checked="mixed"` when some are), a "Sensitive" badge and the group description as a warning. Clicking the parent ticks or clears every scope in the group. An "Adjust individual ... permissions" button (`aria-expanded`) reveals the group's scopes as ordinary checkboxes.
262
+ - **Implications** are a picker-only cascade. Ticking a scope also ticks everything it needs (transitively); unticking a scope also unticks every scope that needs it. Presets and the sensitive parent apply the cascade too. A scope that a ticked scope needs shows a muted "needed by ..." note. The server never infers one scope from another, so existing grants do not widen.
263
+ - **Summary:** "This credential will request N permissions:" followed by the explicit ids.
264
+
265
+ New optional `components` for the picker, each falling back to a native element: `Badge` (the "Sensitive" label) and `Alert` (the sensitive-group warning). Presets and the disclosure use your `Button` (`variant="default"`/`"outline"`/`"ghost"`, `aria-pressed`, `aria-expanded`). Scope checkboxes use `Checkbox` when injected; the sensitive parent is always a native `<input type="checkbox">`, because it needs `indeterminate` and `aria-checked="mixed"`.
266
+
267
+ `ScopePicker`, the group and preset types, and the pure helpers in `scope-selection` (`closeImplications`, `withScopes`, `withoutScopes`, ...) are exported for apps that build their own forms.
234
268
 
235
269
  ## Endpoint Defaults
236
270