Skip to content
Effect 4.0 is here. One ecosystem. Zero dependencies.

Permissions unstable

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.

7 exports Since v4.0.0 Source

Errors

Since v4.0.0

Tagged error wrapping a browser Permissions API failure reason.

Signature

declare class PermissionsError extends YieldableError<this> & {
readonly _tag: "PermissionsError";
} & Readonly<{
readonly reason: PermissionsErrorReason;
}> {
constructor(props: {
readonly reason: PermissionsErrorReason;
});
readonly "~@effect/platform-browser/Permissions/PermissionsError": "~@effect/platform-browser/Permissions/PermissionsError";
message: string;
}
Since v4.0.0

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

Signature

type PermissionsErrorReason = PermissionsInvalidStateError | PermissionsTypeError

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

Signature

declare class PermissionsInvalidStateError extends YieldableError<this> & {
readonly _tag: "InvalidStateError";
} & Readonly<{
readonly cause: unknown;
}> {
constructor(args: {
readonly cause: unknown;
});
message: string;
}
Since v4.0.0

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

Signature

declare class PermissionsTypeError extends YieldableError<this> & {
readonly _tag: "TypeError";
} & Readonly<{
readonly cause: unknown;
}> {
constructor(args: {
readonly cause: unknown;
});
message: string;
}

Layers

layer

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

Services

Permissions

unstable
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: Service<Permissions, Permissions>

Permissions

interface unstable
Since v4.0.0

Wrapper on the Permission API (navigator.permissions) with methods for querying status of permissions.

Signature

interface Permissions {
readonly "~@effect/platform-browser/Permissions": "~@effect/platform-browser/Permissions";
readonly query: <Name extends PermissionName>(name: Name) => Effect<Omit<PermissionStatus, "name"> & {
name: Name;
}, PermissionsError>;
}