Skip to content

Permissions.ts

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



Tagged error wrapping a browser Permissions API failure reason.

Signature

declare class PermissionsError {
constructor(props: { readonly reason: PermissionsErrorReason })
}

Source

Since v4.0.0

Signature

readonly [ErrorTypeId]: "~@effect/platform-browser/Permissions/PermissionsError"

Source

Union of browser Permissions API error reasons represented by the service.

Signature

type PermissionsErrorReason = PermissionsInvalidStateError | PermissionsTypeError

Source

Since v4.0.0

Error reason for an InvalidStateError raised by the browser Permissions API.

Signature

declare class PermissionsInvalidStateError

Source

Since v4.0.0

Error reason for a TypeError raised by the browser Permissions API.

Signature

declare class PermissionsTypeError

Source

Since v4.0.0

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>

Source

Since v4.0.0

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
>
}

Source

Since v4.0.0

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>

Source

Since v4.0.0