Permissions
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.
Errors
PermissionsError
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;
}PermissionsErrorReason type
Union of browser Permissions API error reasons represented by the service.
Signature
type PermissionsErrorReason = PermissionsInvalidStateError | PermissionsTypeError;PermissionsInvalidStateError
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;
}PermissionsTypeError
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
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
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
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
>;
}
Tagged error wrapping a browser Permissions API failure reason.