bwh-auth 0.5.0 → 0.6.1

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/index.d.cts CHANGED
@@ -68,6 +68,8 @@ interface AuthCheckboxComponentProps {
68
68
  checked: boolean;
69
69
  onCheckedChange: (checked: boolean) => void;
70
70
  }
71
+ /** A small inline label, e.g. a design-system `Badge`. */
72
+ type AuthBadgeComponentProps = React.HTMLAttributes<HTMLSpanElement>;
71
73
  interface AuthRadioGroupOption {
72
74
  value: string;
73
75
  label: React.ReactNode;
@@ -92,6 +94,10 @@ interface AuthComponentSet {
92
94
  Textarea?: React.ComponentType<AuthTextareaComponentProps>;
93
95
  Checkbox?: React.ComponentType<AuthCheckboxComponentProps>;
94
96
  RadioGroup?: React.ComponentType<AuthRadioGroupComponentProps>;
97
+ /** Optional: the "Sensitive" badge in the scope picker. A `<span>` is rendered when omitted. */
98
+ Badge?: React.ComponentType<AuthBadgeComponentProps>;
99
+ /** Optional: the warning shown for a sensitive scope group. A styled `<p>` is rendered when omitted. */
100
+ Alert?: React.ComponentType<AuthContainerComponentProps>;
95
101
  }
96
102
  type AuthComponents = AuthComponentSet;
97
103
  type AuthComponentOverrides = Partial<AuthComponentSet>;
@@ -236,6 +242,56 @@ declare function isConditionalMediationAvailable(): Promise<boolean>;
236
242
  declare function authenticateWithPasskey({ endpoints, mediation, signal }?: AuthenticateWithPasskeyOptions): Promise<PasskeyAuthenticationResult>;
237
243
  declare function registerPasskey({ endpoints, name, signal }?: RegisterPasskeyOptions): Promise<PasskeyRegistrationResult>;
238
244
 
245
+ /**
246
+ * Pure selection logic for the scope picker. Implications are a picker-only
247
+ * cascade: the credential still stores exactly the ids that end up selected,
248
+ * and the server never infers one scope from another.
249
+ */
250
+ /** scope id => scope ids it needs, e.g. `{ 'billing:write': ['billing:read'] }`. */
251
+ type ScopeImplications = Record<string, string[]>;
252
+ /** Transitive closure of `implications`, with self-references and cycles dropped. */
253
+ declare function closeImplications(implications: ScopeImplications): ScopeImplications;
254
+ /** Keeps only entries whose key and every requirement are offered; drops entries left empty. */
255
+ declare function restrictImplications(implications: ScopeImplications | undefined, offered: Set<string>): ScopeImplications;
256
+ /** Orders `ids` by `catalog`, removing duplicates and ids not in it. */
257
+ declare function inCatalogOrder(ids: Iterable<string>, catalog: string[]): string[];
258
+ /** Ticking: adds the ids and everything they need. */
259
+ declare function withScopes(selected: string[], ids: string[], closed: ScopeImplications): Set<string>;
260
+ /** Unticking: removes the ids and every selected scope that needs one of them. */
261
+ declare function withoutScopes(selected: string[], ids: string[], closed: ScopeImplications): Set<string>;
262
+ /** Selected scopes that need `id`, in catalog order: why `id` is ticked beyond the person's own choice. */
263
+ declare function neededBy(id: string, selected: string[], closed: ScopeImplications): string[];
264
+ declare function sameSelection(a: string[], b: string[]): boolean;
265
+
266
+ /** A named set of related scopes (`scopes` are ids from the sibling scope list). */
267
+ interface ApiCredentialScopeGroup {
268
+ id: string;
269
+ label: string;
270
+ description: string | null;
271
+ /** A sensitive group is one parent checkbox, with its scopes behind a disclosure. */
272
+ sensitive: boolean;
273
+ scopes: string[];
274
+ }
275
+ /** A one-click selection: choosing it replaces the selection with exactly `scopes`. */
276
+ interface ApiCredentialScopePreset {
277
+ id: string;
278
+ label: string;
279
+ description: string;
280
+ scopes: string[];
281
+ }
282
+ interface ScopePickerProps {
283
+ idPrefix: string;
284
+ scopes: ApiCredentialScope[];
285
+ /** Absent or empty: a flat list, as before groups existed. */
286
+ groups?: ApiCredentialScopeGroup[];
287
+ presets?: ApiCredentialScopePreset[];
288
+ implications?: ScopeImplications;
289
+ selected: string[];
290
+ onChange: (next: string[]) => void;
291
+ components: AuthComponentInput;
292
+ }
293
+ declare function ScopePicker({ idPrefix, scopes, groups, presets, implications, selected, onChange, components }: ScopePickerProps): React.JSX.Element;
294
+
239
295
  interface ApiCredentialScope {
240
296
  id: string;
241
297
  description: string;
@@ -247,6 +303,8 @@ interface ApiCredentialToken {
247
303
  created_at: string | null;
248
304
  expires_at: string | null;
249
305
  revoke_href: string;
306
+ /** True for a token that carries an MCP connection scope. */
307
+ connection?: boolean;
250
308
  }
251
309
  interface ApiCredentialApp {
252
310
  id: string;
@@ -266,6 +324,24 @@ interface ApiCredentialIndex {
266
324
  register_app_href: string | null;
267
325
  tokens: ApiCredentialToken[];
268
326
  apps: ApiCredentialApp[];
327
+ /**
328
+ * Grouped picker data, all optional and presentation only: the credential still
329
+ * stores explicit scope ids. `scope_*` serves the OAuth-app form and, unless the
330
+ * matching `token_*` key is present, the token form. Without groups the picker is a flat list.
331
+ */
332
+ scope_groups?: ApiCredentialScopeGroup[];
333
+ scope_presets?: ApiCredentialScopePreset[];
334
+ /** scope id => scope ids it needs: ticking a scope ticks them, unticking one unticks what needs it. */
335
+ scope_implications?: ScopeImplications;
336
+ /** A narrower scope list for personal tokens, when the server offers one. */
337
+ token_scopes?: ApiCredentialScope[];
338
+ token_scope_groups?: ApiCredentialScopeGroup[];
339
+ token_scope_presets?: ApiCredentialScopePreset[];
340
+ token_scope_implications?: ScopeImplications;
341
+ /** Offered to personal tokens only: MCP connection scopes, listed after the token scopes. */
342
+ token_connection_scopes?: ApiCredentialScope[];
343
+ /** The lifetimes a token carrying a connection scope may have; replaces `token_lifetimes` for it. */
344
+ connection_token_lifetimes?: string[];
269
345
  }
270
346
  type IssuedApiCredential = {
271
347
  kind: 'token';
@@ -311,6 +387,12 @@ interface ApiCredentialsSectionProps {
311
387
  request?: ApiCredentialRequest;
312
388
  onSuccess?: (message: string) => void;
313
389
  onError?: (field: string, message: string) => void;
390
+ /**
391
+ * `stacked` (default) puts the token and OAuth-app sections one under the other.
392
+ * `columns` lays them side by side when the container is wide enough (about 960px);
393
+ * narrower containers stack them.
394
+ */
395
+ layout?: 'stacked' | 'columns';
314
396
  }
315
397
  /**
316
398
  * A person's credentials for apps that use the API: personal API tokens (for
@@ -321,8 +403,8 @@ interface ApiCredentialsSectionProps {
321
403
  * in this component's memory; afterwards only the lists are reloaded, so it is
322
404
  * never part of page props or browser history.
323
405
  */
324
- declare function ApiCredentialsSection({ indexUrl, components, links, csrfToken, request, onSuccess, onError }: ApiCredentialsSectionProps): React.JSX.Element;
406
+ declare function ApiCredentialsSection({ indexUrl, components, links, csrfToken, request, onSuccess, onError, layout }: ApiCredentialsSectionProps): React.JSX.Element;
325
407
  /** PT4H → "4 hours", P30D → "30 days", P1Y → "1 year". Unknown shapes are shown as given. */
326
408
  declare function describeDuration(spec: string): string;
327
409
 
328
- export { type ApiCredentialApp, type ApiCredentialEndpointLink, type ApiCredentialIndex, type ApiCredentialRequest, type ApiCredentialRequestResult, type ApiCredentialScope, type ApiCredentialToken, ApiCredentialsSection, type ApiCredentialsSectionProps, type AuthButtonComponent, type AuthButtonComponentInput, type AuthButtonComponentProps, type AuthButtonSize, type AuthButtonVariant, type AuthCheckboxComponentProps, type AuthComponentInput, type AuthComponentOverrides, type AuthComponentSet, type AuthComponentSuperset, type AuthComponents, type AuthContainerComponentProps, type AuthEndpointConfig, type AuthInputComponentProps, type AuthJsonResponse, type AuthLabelComponentProps, type AuthRadioGroupComponentProps, type AuthRadioGroupOption, type AuthSignupField, type AuthSignupValues, type AuthTextareaComponentProps, type AuthValidationErrors, ChangePasswordForm, type IssuedApiCredential, LoginForm, type LoginFormProps, type LoginRememberMeCheckboxProps, type Passkey, PasskeyLoginButton, PasskeySection, PasswordResetRequestForm, type RelyingApplication, ResetPasswordForm, SignupForm, TwoFactorForm, arrayBufferToBase64url, authenticateWithPasskey, base64urlToArrayBuffer, describeDuration, getCsrfToken, getDefaultPasskeyName, isAbortError, isConditionalMediationAvailable, registerPasskey, relyingApplicationsFrom, safeApplicationHref };
410
+ export { type ApiCredentialApp, type ApiCredentialEndpointLink, type ApiCredentialIndex, type ApiCredentialRequest, type ApiCredentialRequestResult, type ApiCredentialScope, type ApiCredentialScopeGroup, type ApiCredentialScopePreset, type ApiCredentialToken, ApiCredentialsSection, type ApiCredentialsSectionProps, type AuthBadgeComponentProps, type AuthButtonComponent, type AuthButtonComponentInput, type AuthButtonComponentProps, type AuthButtonSize, type AuthButtonVariant, type AuthCheckboxComponentProps, type AuthComponentInput, type AuthComponentOverrides, type AuthComponentSet, type AuthComponentSuperset, type AuthComponents, type AuthContainerComponentProps, type AuthEndpointConfig, type AuthInputComponentProps, type AuthJsonResponse, type AuthLabelComponentProps, type AuthRadioGroupComponentProps, type AuthRadioGroupOption, type AuthSignupField, type AuthSignupValues, type AuthTextareaComponentProps, type AuthValidationErrors, ChangePasswordForm, type IssuedApiCredential, LoginForm, type LoginFormProps, type LoginRememberMeCheckboxProps, type Passkey, PasskeyLoginButton, PasskeySection, PasswordResetRequestForm, type RelyingApplication, ResetPasswordForm, type ScopeImplications, ScopePicker, type ScopePickerProps, SignupForm, TwoFactorForm, arrayBufferToBase64url, authenticateWithPasskey, base64urlToArrayBuffer, closeImplications, describeDuration, getCsrfToken, getDefaultPasskeyName, inCatalogOrder, isAbortError, isConditionalMediationAvailable, neededBy, registerPasskey, relyingApplicationsFrom, restrictImplications, safeApplicationHref, sameSelection, withScopes, withoutScopes };
package/dist/index.d.ts CHANGED
@@ -68,6 +68,8 @@ interface AuthCheckboxComponentProps {
68
68
  checked: boolean;
69
69
  onCheckedChange: (checked: boolean) => void;
70
70
  }
71
+ /** A small inline label, e.g. a design-system `Badge`. */
72
+ type AuthBadgeComponentProps = React.HTMLAttributes<HTMLSpanElement>;
71
73
  interface AuthRadioGroupOption {
72
74
  value: string;
73
75
  label: React.ReactNode;
@@ -92,6 +94,10 @@ interface AuthComponentSet {
92
94
  Textarea?: React.ComponentType<AuthTextareaComponentProps>;
93
95
  Checkbox?: React.ComponentType<AuthCheckboxComponentProps>;
94
96
  RadioGroup?: React.ComponentType<AuthRadioGroupComponentProps>;
97
+ /** Optional: the "Sensitive" badge in the scope picker. A `<span>` is rendered when omitted. */
98
+ Badge?: React.ComponentType<AuthBadgeComponentProps>;
99
+ /** Optional: the warning shown for a sensitive scope group. A styled `<p>` is rendered when omitted. */
100
+ Alert?: React.ComponentType<AuthContainerComponentProps>;
95
101
  }
96
102
  type AuthComponents = AuthComponentSet;
97
103
  type AuthComponentOverrides = Partial<AuthComponentSet>;
@@ -236,6 +242,56 @@ declare function isConditionalMediationAvailable(): Promise<boolean>;
236
242
  declare function authenticateWithPasskey({ endpoints, mediation, signal }?: AuthenticateWithPasskeyOptions): Promise<PasskeyAuthenticationResult>;
237
243
  declare function registerPasskey({ endpoints, name, signal }?: RegisterPasskeyOptions): Promise<PasskeyRegistrationResult>;
238
244
 
245
+ /**
246
+ * Pure selection logic for the scope picker. Implications are a picker-only
247
+ * cascade: the credential still stores exactly the ids that end up selected,
248
+ * and the server never infers one scope from another.
249
+ */
250
+ /** scope id => scope ids it needs, e.g. `{ 'billing:write': ['billing:read'] }`. */
251
+ type ScopeImplications = Record<string, string[]>;
252
+ /** Transitive closure of `implications`, with self-references and cycles dropped. */
253
+ declare function closeImplications(implications: ScopeImplications): ScopeImplications;
254
+ /** Keeps only entries whose key and every requirement are offered; drops entries left empty. */
255
+ declare function restrictImplications(implications: ScopeImplications | undefined, offered: Set<string>): ScopeImplications;
256
+ /** Orders `ids` by `catalog`, removing duplicates and ids not in it. */
257
+ declare function inCatalogOrder(ids: Iterable<string>, catalog: string[]): string[];
258
+ /** Ticking: adds the ids and everything they need. */
259
+ declare function withScopes(selected: string[], ids: string[], closed: ScopeImplications): Set<string>;
260
+ /** Unticking: removes the ids and every selected scope that needs one of them. */
261
+ declare function withoutScopes(selected: string[], ids: string[], closed: ScopeImplications): Set<string>;
262
+ /** Selected scopes that need `id`, in catalog order: why `id` is ticked beyond the person's own choice. */
263
+ declare function neededBy(id: string, selected: string[], closed: ScopeImplications): string[];
264
+ declare function sameSelection(a: string[], b: string[]): boolean;
265
+
266
+ /** A named set of related scopes (`scopes` are ids from the sibling scope list). */
267
+ interface ApiCredentialScopeGroup {
268
+ id: string;
269
+ label: string;
270
+ description: string | null;
271
+ /** A sensitive group is one parent checkbox, with its scopes behind a disclosure. */
272
+ sensitive: boolean;
273
+ scopes: string[];
274
+ }
275
+ /** A one-click selection: choosing it replaces the selection with exactly `scopes`. */
276
+ interface ApiCredentialScopePreset {
277
+ id: string;
278
+ label: string;
279
+ description: string;
280
+ scopes: string[];
281
+ }
282
+ interface ScopePickerProps {
283
+ idPrefix: string;
284
+ scopes: ApiCredentialScope[];
285
+ /** Absent or empty: a flat list, as before groups existed. */
286
+ groups?: ApiCredentialScopeGroup[];
287
+ presets?: ApiCredentialScopePreset[];
288
+ implications?: ScopeImplications;
289
+ selected: string[];
290
+ onChange: (next: string[]) => void;
291
+ components: AuthComponentInput;
292
+ }
293
+ declare function ScopePicker({ idPrefix, scopes, groups, presets, implications, selected, onChange, components }: ScopePickerProps): React.JSX.Element;
294
+
239
295
  interface ApiCredentialScope {
240
296
  id: string;
241
297
  description: string;
@@ -247,6 +303,8 @@ interface ApiCredentialToken {
247
303
  created_at: string | null;
248
304
  expires_at: string | null;
249
305
  revoke_href: string;
306
+ /** True for a token that carries an MCP connection scope. */
307
+ connection?: boolean;
250
308
  }
251
309
  interface ApiCredentialApp {
252
310
  id: string;
@@ -266,6 +324,24 @@ interface ApiCredentialIndex {
266
324
  register_app_href: string | null;
267
325
  tokens: ApiCredentialToken[];
268
326
  apps: ApiCredentialApp[];
327
+ /**
328
+ * Grouped picker data, all optional and presentation only: the credential still
329
+ * stores explicit scope ids. `scope_*` serves the OAuth-app form and, unless the
330
+ * matching `token_*` key is present, the token form. Without groups the picker is a flat list.
331
+ */
332
+ scope_groups?: ApiCredentialScopeGroup[];
333
+ scope_presets?: ApiCredentialScopePreset[];
334
+ /** scope id => scope ids it needs: ticking a scope ticks them, unticking one unticks what needs it. */
335
+ scope_implications?: ScopeImplications;
336
+ /** A narrower scope list for personal tokens, when the server offers one. */
337
+ token_scopes?: ApiCredentialScope[];
338
+ token_scope_groups?: ApiCredentialScopeGroup[];
339
+ token_scope_presets?: ApiCredentialScopePreset[];
340
+ token_scope_implications?: ScopeImplications;
341
+ /** Offered to personal tokens only: MCP connection scopes, listed after the token scopes. */
342
+ token_connection_scopes?: ApiCredentialScope[];
343
+ /** The lifetimes a token carrying a connection scope may have; replaces `token_lifetimes` for it. */
344
+ connection_token_lifetimes?: string[];
269
345
  }
270
346
  type IssuedApiCredential = {
271
347
  kind: 'token';
@@ -311,6 +387,12 @@ interface ApiCredentialsSectionProps {
311
387
  request?: ApiCredentialRequest;
312
388
  onSuccess?: (message: string) => void;
313
389
  onError?: (field: string, message: string) => void;
390
+ /**
391
+ * `stacked` (default) puts the token and OAuth-app sections one under the other.
392
+ * `columns` lays them side by side when the container is wide enough (about 960px);
393
+ * narrower containers stack them.
394
+ */
395
+ layout?: 'stacked' | 'columns';
314
396
  }
315
397
  /**
316
398
  * A person's credentials for apps that use the API: personal API tokens (for
@@ -321,8 +403,8 @@ interface ApiCredentialsSectionProps {
321
403
  * in this component's memory; afterwards only the lists are reloaded, so it is
322
404
  * never part of page props or browser history.
323
405
  */
324
- declare function ApiCredentialsSection({ indexUrl, components, links, csrfToken, request, onSuccess, onError }: ApiCredentialsSectionProps): React.JSX.Element;
406
+ declare function ApiCredentialsSection({ indexUrl, components, links, csrfToken, request, onSuccess, onError, layout }: ApiCredentialsSectionProps): React.JSX.Element;
325
407
  /** PT4H → "4 hours", P30D → "30 days", P1Y → "1 year". Unknown shapes are shown as given. */
326
408
  declare function describeDuration(spec: string): string;
327
409
 
328
- export { type ApiCredentialApp, type ApiCredentialEndpointLink, type ApiCredentialIndex, type ApiCredentialRequest, type ApiCredentialRequestResult, type ApiCredentialScope, type ApiCredentialToken, ApiCredentialsSection, type ApiCredentialsSectionProps, type AuthButtonComponent, type AuthButtonComponentInput, type AuthButtonComponentProps, type AuthButtonSize, type AuthButtonVariant, type AuthCheckboxComponentProps, type AuthComponentInput, type AuthComponentOverrides, type AuthComponentSet, type AuthComponentSuperset, type AuthComponents, type AuthContainerComponentProps, type AuthEndpointConfig, type AuthInputComponentProps, type AuthJsonResponse, type AuthLabelComponentProps, type AuthRadioGroupComponentProps, type AuthRadioGroupOption, type AuthSignupField, type AuthSignupValues, type AuthTextareaComponentProps, type AuthValidationErrors, ChangePasswordForm, type IssuedApiCredential, LoginForm, type LoginFormProps, type LoginRememberMeCheckboxProps, type Passkey, PasskeyLoginButton, PasskeySection, PasswordResetRequestForm, type RelyingApplication, ResetPasswordForm, SignupForm, TwoFactorForm, arrayBufferToBase64url, authenticateWithPasskey, base64urlToArrayBuffer, describeDuration, getCsrfToken, getDefaultPasskeyName, isAbortError, isConditionalMediationAvailable, registerPasskey, relyingApplicationsFrom, safeApplicationHref };
410
+ export { type ApiCredentialApp, type ApiCredentialEndpointLink, type ApiCredentialIndex, type ApiCredentialRequest, type ApiCredentialRequestResult, type ApiCredentialScope, type ApiCredentialScopeGroup, type ApiCredentialScopePreset, type ApiCredentialToken, ApiCredentialsSection, type ApiCredentialsSectionProps, type AuthBadgeComponentProps, type AuthButtonComponent, type AuthButtonComponentInput, type AuthButtonComponentProps, type AuthButtonSize, type AuthButtonVariant, type AuthCheckboxComponentProps, type AuthComponentInput, type AuthComponentOverrides, type AuthComponentSet, type AuthComponentSuperset, type AuthComponents, type AuthContainerComponentProps, type AuthEndpointConfig, type AuthInputComponentProps, type AuthJsonResponse, type AuthLabelComponentProps, type AuthRadioGroupComponentProps, type AuthRadioGroupOption, type AuthSignupField, type AuthSignupValues, type AuthTextareaComponentProps, type AuthValidationErrors, ChangePasswordForm, type IssuedApiCredential, LoginForm, type LoginFormProps, type LoginRememberMeCheckboxProps, type Passkey, PasskeyLoginButton, PasskeySection, PasswordResetRequestForm, type RelyingApplication, ResetPasswordForm, type ScopeImplications, ScopePicker, type ScopePickerProps, SignupForm, TwoFactorForm, arrayBufferToBase64url, authenticateWithPasskey, base64urlToArrayBuffer, closeImplications, describeDuration, getCsrfToken, getDefaultPasskeyName, inCatalogOrder, isAbortError, isConditionalMediationAvailable, neededBy, registerPasskey, relyingApplicationsFrom, restrictImplications, safeApplicationHref, sameSelection, withScopes, withoutScopes };