Permissions.ts
Permissions.ts overview
Section titled “Permissions.ts overview”Effect service for the browser Permissions API.
This module defines a Permissions service backed by
navigator.permissions. The service exposes query, which returns the
browser PermissionStatus for a permission name. Failed browser operations
are represented as PermissionsError values with InvalidStateError or
TypeError reasons, and layer provides the browser-backed service.
Since v4.0.0
Exports Grouped by Category
Section titled “Exports Grouped by Category”errors
Section titled “errors”PermissionsError (class)
Section titled “PermissionsError (class)”Tagged error wrapping a browser Permissions API failure reason.
Signature
declare class PermissionsError { constructor(props: { readonly reason: PermissionsErrorReason })}Since v4.0.0
[ErrorTypeId] (property)
Section titled “[ErrorTypeId] (property)”Signature
readonly [ErrorTypeId]: "~@effect/platform-browser/Permissions/PermissionsError"PermissionsErrorReason (type alias)
Section titled “PermissionsErrorReason (type alias)”Union of browser Permissions API error reasons represented by the service.
Signature
type PermissionsErrorReason = PermissionsInvalidStateError | PermissionsTypeErrorSince v4.0.0
PermissionsInvalidStateError (class)
Section titled “PermissionsInvalidStateError (class)”Error reason for an InvalidStateError raised by the browser Permissions API.
Signature
declare class PermissionsInvalidStateErrorSince v4.0.0
PermissionsTypeError (class)
Section titled “PermissionsTypeError (class)”Error reason for a TypeError raised by the browser Permissions API.
Signature
declare class PermissionsTypeErrorSince v4.0.0
layers
Section titled “layers”Provides the Permissions service using the browser navigator.permissions API.
When to use
Use when you need a live browser Permissions service backed by the ambient
navigator.permissions implementation.
Details
query delegates to navigator.permissions.query({ name }) and wraps
rejected browser operations in PermissionsError.
Signature
declare const layer: Layer.Layer<Permissions, never, never>Since v4.0.0
models
Section titled “models”Permissions (interface)
Section titled “Permissions (interface)”Wrapper on the Permission API (navigator.permissions) with methods for
querying status of permissions.
Signature
export interface Permissions { readonly [TypeId]: typeof TypeId
/** * Returns the state of a user permission on the global scope. */ readonly query: <Name extends PermissionName>( name: Name ) => Effect.Effect< // `name` is identical to the name passed to Permissions.query // https://developer.mozilla.org/en-US/docs/Web/API/PermissionStatus Omit<PermissionStatus, "name"> & { name: Name }, PermissionsError >}Since v4.0.0
services
Section titled “services”Permissions
Section titled “Permissions”Service tag for browser permission querying.
When to use
Use when you need to require or provide browser permission querying through Effect’s context.
Signature
declare const Permissions: Context.Service<Permissions, Permissions>Since v4.0.0