Skip to content

Latest commit

 

History

115 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PERMISSIONS

license: MIT npm: v0.2.3 runtime: bun typescript: strict eslint: checked prettier: checked build: checked tests: checked docs: paradox

Cross-platform permission registry and runtime helpers for Expo, React Native, and React Native Web apps, with unified request/check APIs for camera, media, location, notifications, microphone, and other web/native capabilities.

Usage

Basic permissions runtime example.

Create a permission client, provide it at the app root, and use usePermission to read, refresh, and request a normalized permission state.

Source: examples/basic/App.tsx

import {
  createFakePermissionClient,
  Permission,
  PermissionsProvider,
  usePermission,
} from '@ankhorage/permissions';

const permissionClient = createFakePermissionClient({
  initialStates: [{ permission: Permission.Camera, status: 'denied' }],
  requestStates: [{ permission: Permission.Camera, status: 'granted' }],
});

export default function BasicPermissionsExample() {
  return (
    <PermissionsProvider client={permissionClient}>
      <CameraPermissionExample />
    </PermissionsProvider>
  );
}

function CameraPermissionExample() {
  const camera = usePermission(Permission.Camera, { refreshOnMount: true });

  return (
    <>
      <p>Camera permission: {camera.status}</p>
      <button
        type="button"
        disabled={camera.granted}
        onClick={() => {
          void camera.request();
        }}
      >
        Request camera permission
      </button>
    </>
  );
}

Expo permissions runtime example.

Create the Expo permission client from the optional Expo entrypoint, provide it at the app root, and call request() only from an explicit user action.

Source: examples/expo/App.tsx

import { Permission, PermissionsProvider, usePermission } from '@ankhorage/permissions';
import { createPermissionClient } from '@ankhorage/permissions/expo';

const permissionClient = createPermissionClient();

export default function ExpoPermissionsExample() {
  return (
    <PermissionsProvider client={permissionClient}>
      <CameraPermissionExample />
    </PermissionsProvider>
  );
}

function CameraPermissionExample() {
  const camera = usePermission(Permission.Camera, { refreshOnMount: true });

  return (
    <>
      <p>Camera permission: {camera.status}</p>
      <button
        type="button"
        disabled={camera.granted}
        onClick={() => {
          void camera.request();
        }}
      >
        Request camera permission
      </button>
    </>
  );
}

Generated documentation

Public API

Utilities

createFakePermissionClient
createFakePermissionClient(options?: FakePermissionClientOptions) => FakePermissionClient

Creates a deterministic in-memory client for tests and examples.

Fake clients make permission flows testable without native devices, browser prompts, simulators, or network access.

Module: src/testing/index.ts Source: src/testing/index.ts:61:1 Related symbols: FakePermissionClient, FakePermissionClientOptions

createPermissionClient
createPermissionClient() => PermissionClient

Creates a permission client backed by Expo SDK modules.

Denials that Expo cannot request again are normalized to blocked. Limited media-library access and provisional or ephemeral iOS notification access are normalized to usable limited states, where granted remains true. The client requires expo-linking for settings recovery and rejects with a stable error when the operating-system settings page cannot be opened.

Expo modules are loaded only when a client operation uses them. The package root and Expo manifest metadata remain free of native module imports.

Module: src/expo/client.ts Source: src/expo/client.ts:42:1 Related symbols: PermissionClient

createPermissionManager
createPermissionManager(client: PermissionClient) => PermissionManager

Creates a permission manager from a runtime-specific client.

The manager validates permission names and normalizes client results. Native app configuration remains a separate build-time concern.

Module: src/manager/createPermissionManager.ts Source: src/manager/createPermissionManager.ts:21:1 Related symbols: PermissionClient, PermissionManager

createWebPermissionClient
createWebPermissionClient(options?: WebPermissionClientOptions) => PermissionClient

Creates a browser permission client using guarded structural globals.

Unsupported web APIs resolve to status: 'unavailable'. The adapter does not import DOM types and does not assume it is running in a browser.

Module: src/web/index.ts Source: src/web/index.ts:80:1 Related symbols: PermissionClient, WebPermissionClientOptions

Permission

Common runtime permissions supported by the registry.

The registry is intentionally platform-neutral. Adapters translate each permission into whatever a browser, React Native app, Expo app, or test environment can actually check or request.

Module: src/registry/permissions.ts Source: src/registry/permissions.ts:9:1

PermissionsProvider
PermissionsProvider({
  children,
  client,
  manager,
}: PermissionsProviderProps) => ReactNode

Provides a permission manager to React hooks.

React helpers are framework-neutral. They depend on React only and do not import browser, Expo, or React Native permission APIs.

Related types: PermissionsProviderProps

Props
Prop Type Required Default Description
children ReactNode | undefined no —
client PermissionClient | undefined no —
manager PermissionManager | undefined no —

About

Cross-platform permission registry and runtime helpers for Expo, React Native, and React Native Web apps, with unified request/check APIs for camera, media, location, notifications, microphone, and other web/native capabilities.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages