@capgo/capacitor-permissions 0.0.0-stage → 8.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,3 +1,434 @@
1
- # Temporary Holding Version
1
+ # @capgo/capacitor-permissions
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ <a href="https://capgo.app/"><img src="https://capgo.app/readme-banner.svg?repo=Cap-go/capacitor-permissions" alt="Capgo - Instant updates for Capacitor" /></a>
4
+
5
+ <div align="center">
6
+ <h2><a href="https://capgo.app/?ref=plugin_permissions"> ➡️ Get Instant updates for your App with Capgo</a></h2>
7
+ <h2><a href="https://capgo.app/consulting/?ref=plugin_permissions"> Missing a feature? We’ll build the plugin for you 💪</a></h2>
8
+ </div>
9
+
10
+ **@capgo/capacitor-permissions** gives Capacitor apps one TypeScript API to check and request runtime permissions on iOS, Android, and web. Instead of wiring each feature plugin separately or guessing platform-specific status codes, you work with a single set of permission names and normalized states (`granted`, `denied`, `blocked`, `limited`, `unavailable`). Native manifests stay lean: the plugin ships without `uses-permission` entries or forced Info.plist strings, so store review only sees what your app declares.
11
+
12
+ ### Features
13
+
14
+ - One `PermissionName` enum for camera, location, notifications, media, contacts, and more across platforms
15
+ - `check`, `request`, `checkMultiple`, and `requestMultiple` with shared `AppPermissionState` results
16
+ - Android `shouldShowRationale` before re-prompting after a denial
17
+ - `openSettings` for application or notification settings when access is blocked
18
+ - `requestPreciseLocation` for full accuracy on iOS and `ACCESS_FINE_LOCATION` on Android
19
+ - Web implementation via the browser Permissions API for supported types
20
+ - Optional `scripts/apply-permissions.mjs` to add only the Android and iOS declarations you need
21
+
22
+ ### Use cases
23
+
24
+ - Gate a screen until camera or microphone access is granted
25
+ - Run a startup audit with `checkMultiple` and show a single onboarding flow for missing permissions
26
+ - Send users to system settings when status is `blocked` after `openSettings`
27
+ - Request notification permission before registering push tokens
28
+ - Upgrade from reduced to precise location when a map feature needs it
29
+
30
+ <p align="center">
31
+ <img src="./screenshots/android-request.webp" alt="Android emulator showing the camera permission dialog" width="280" />
32
+ <img src="./screenshots/android-granted.webp" alt="Example app reporting camera permission as granted" width="280" />
33
+ </p>
34
+
35
+ ## Compatibility
36
+
37
+ | Plugin version | Capacitor compatibility | Maintained |
38
+ | -------------- | ----------------------- | ---------- |
39
+ | v8.\*.\* | v8.\*.\* | ✅ |
40
+ | v7.\*.\* | v7.\*.\* | On demand |
41
+ | v6.\*.\* | v6.\*.\* | On demand |
42
+
43
+ Policy:
44
+
45
+ - New plugins start at version `8.0.0` (Capacitor 8 baseline).
46
+ - Backward compatibility for older Capacitor majors is supported on demand.
47
+
48
+ ## Install
49
+
50
+ ```bash
51
+ npm install @capgo/capacitor-permissions
52
+ npx cap sync
53
+ ```
54
+
55
+ With Bun:
56
+
57
+ ```bash
58
+ bun add @capgo/capacitor-permissions
59
+ bunx cap sync
60
+ ```
61
+
62
+ ## iOS setup
63
+
64
+ The plugin does not inject usage descriptions into your app. For each `PermissionName` you call at runtime, add the matching keys to `ios/App/App/Info.plist` (customize the user-facing strings):
65
+
66
+ | Permission | Info.plist keys |
67
+ | ---------- | ---------------- |
68
+ | `camera` | `NSCameraUsageDescription` |
69
+ | `microphone` | `NSMicrophoneUsageDescription` |
70
+ | `photoLibrary` | `NSPhotoLibraryUsageDescription` |
71
+ | `photoLibraryAddOnly` | `NSPhotoLibraryAddUsageDescription` |
72
+ | `contacts` | `NSContactsUsageDescription` |
73
+ | `calendar` | `NSCalendarsUsageDescription`, `NSCalendarsFullAccessUsageDescription` |
74
+ | `reminders` | `NSRemindersUsageDescription`, `NSRemindersFullAccessUsageDescription` |
75
+ | `locationWhenInUse` | `NSLocationWhenInUseUsageDescription` |
76
+ | `locationAlways` | `NSLocationWhenInUseUsageDescription`, `NSLocationAlwaysAndWhenInUseUsageDescription` |
77
+ | `bluetooth` | `NSBluetoothAlwaysUsageDescription` |
78
+ | `motion` | `NSMotionUsageDescription` |
79
+ | `speechRecognition` | `NSSpeechRecognitionUsageDescription`, `NSMicrophoneUsageDescription` |
80
+ | `appTrackingTransparency` | `NSUserTrackingUsageDescription` |
81
+
82
+ `notifications` on iOS uses the system notification permission flow; no extra usage string is required for the API itself. Permissions such as `activityRecognition`, `phone`, `sms`, and Android-style media splits are not applicable on iOS and report `unavailable` when checked.
83
+
84
+ You can apply the keys above automatically from the plugin repo:
85
+
86
+ ```bash
87
+ node node_modules/@capgo/capacitor-permissions/scripts/apply-permissions.mjs \
88
+ --project . \
89
+ --permissions camera,microphone,notifications,locationWhenInUse,photoLibrary
90
+ ```
91
+
92
+ (Point `--project` at your Capacitor app root, the folder that contains `ios/` and `android/`.)
93
+
94
+ ## Android setup
95
+
96
+ The library `AndroidManifest.xml` declares **no** `<uses-permission>` entries. Add only what your app uses to `android/app/src/main/AndroidManifest.xml`. The plugin targets **minSdk 24** (Android 7.0) unless your project overrides `minSdkVersion`.
97
+
98
+ | Permission | Typical `uses-permission` names |
99
+ | ---------- | -------------------------------- |
100
+ | `camera` | `android.permission.CAMERA` |
101
+ | `microphone`, `speechRecognition` | `android.permission.RECORD_AUDIO` |
102
+ | `photoLibrary`, `mediaImages` | `READ_MEDIA_IMAGES`, `READ_MEDIA_VISUAL_USER_SELECTED`, `READ_EXTERNAL_STORAGE` (legacy) |
103
+ | `photoLibraryAddOnly` | `WRITE_EXTERNAL_STORAGE` (legacy) |
104
+ | `contacts` | `READ_CONTACTS` |
105
+ | `calendar` | `READ_CALENDAR`, `WRITE_CALENDAR` |
106
+ | `locationWhenInUse` | `ACCESS_COARSE_LOCATION`, `ACCESS_FINE_LOCATION` |
107
+ | `locationAlways` | above plus `ACCESS_BACKGROUND_LOCATION` |
108
+ | `bluetooth` | `BLUETOOTH`, `BLUETOOTH_ADMIN`, `BLUETOOTH_CONNECT`, `BLUETOOTH_SCAN` |
109
+ | `motion`, `activityRecognition` | `ACTIVITY_RECOGNITION` |
110
+ | `notifications` | `POST_NOTIFICATIONS` (Android 13+) |
111
+ | `phone` | `READ_PHONE_STATE` |
112
+ | `sms` | `READ_SMS`, `RECEIVE_SMS` |
113
+ | `mediaAudio` | `READ_MEDIA_AUDIO`, `READ_EXTERNAL_STORAGE` |
114
+ | `mediaVideo` | `READ_MEDIA_VIDEO`, `READ_EXTERNAL_STORAGE` |
115
+
116
+ `reminders` and `appTrackingTransparency` are not Android runtime permissions in this API and return `unavailable`.
117
+
118
+ Use the same `apply-permissions.mjs` script as on iOS to merge declarations into your app manifest.
119
+
120
+ ## Web setup
121
+
122
+ No manifest changes. Supported permissions use `navigator.permissions` and related APIs (`camera`, `microphone`, `notifications`, `locationWhenInUse`; `locationAlways` maps to foreground geolocation only). Others return `unavailable`. `openSettings` is not implemented on web.
123
+
124
+ ## Usage
125
+
126
+ ```typescript
127
+ import { Permissions } from '@capgo/capacitor-permissions';
128
+
129
+ export async function ensureCamera(): Promise<boolean> {
130
+ const { status } = await Permissions.check({ permission: 'camera' });
131
+ if (status === 'granted') {
132
+ return true;
133
+ }
134
+ const { status: afterRequest } = await Permissions.request({ permission: 'camera' });
135
+ return afterRequest === 'granted';
136
+ }
137
+ ```
138
+
139
+ Check several permissions before showing an onboarding screen:
140
+
141
+ ```typescript
142
+ const { statuses } = await Permissions.checkMultiple({
143
+ permissions: ['camera', 'microphone', 'notifications'],
144
+ });
145
+ const missing = Object.entries(statuses).filter(([, s]) => s !== 'granted');
146
+ ```
147
+
148
+ When Android reports `denied`, show context before requesting again:
149
+
150
+ ```typescript
151
+ const { shouldShow } = await Permissions.shouldShowRationale({ permission: 'camera' });
152
+ if (shouldShow) {
153
+ // Show your own explanation UI, then:
154
+ await Permissions.request({ permission: 'camera' });
155
+ }
156
+ ```
157
+
158
+ If status is `blocked`, send the user to settings:
159
+
160
+ ```typescript
161
+ await Permissions.openSettings({ type: 'application' });
162
+ ```
163
+
164
+ ## Example app
165
+
166
+ The `example-app/` project exercises every `PermissionName`. Apply declarations, sync native projects, then:
167
+
168
+ ```bash
169
+ cd example-app
170
+ bun install
171
+ bun run start
172
+ ```
173
+
174
+ ## API
175
+
176
+ <docgen-index>
177
+
178
+ * [`check(...)`](#check)
179
+ * [`request(...)`](#request)
180
+ * [`checkMultiple(...)`](#checkmultiple)
181
+ * [`requestMultiple(...)`](#requestmultiple)
182
+ * [`shouldShowRationale(...)`](#shouldshowrationale)
183
+ * [`openSettings(...)`](#opensettings)
184
+ * [`requestPreciseLocation()`](#requestpreciselocation)
185
+ * [`getPluginVersion()`](#getpluginversion)
186
+ * [Interfaces](#interfaces)
187
+ * [Type Aliases](#type-aliases)
188
+
189
+ </docgen-index>
190
+
191
+ <docgen-api>
192
+ <!--Update the source file JSDoc comments and rerun docgen to update the docs below-->
193
+
194
+ Cross-platform permissions API for Capacitor apps.
195
+
196
+ ### check(...)
197
+
198
+ ```typescript
199
+ check(options: PermissionOptions) => Promise<PermissionStatusResult>
200
+ ```
201
+
202
+ Check the current status of one permission without prompting the user.
203
+
204
+ | Param | Type |
205
+ | ------------- | --------------------------------------------------------------- |
206
+ | **`options`** | <code><a href="#permissionoptions">PermissionOptions</a></code> |
207
+
208
+ **Returns:** <code>Promise&lt;<a href="#permissionstatusresult">PermissionStatusResult</a>&gt;</code>
209
+
210
+ --------------------
211
+
212
+
213
+ ### request(...)
214
+
215
+ ```typescript
216
+ request(options: PermissionOptions) => Promise<PermissionStatusResult>
217
+ ```
218
+
219
+ Request one permission from the user. On Android, shows the system dialog when needed.
220
+
221
+ | Param | Type |
222
+ | ------------- | --------------------------------------------------------------- |
223
+ | **`options`** | <code><a href="#permissionoptions">PermissionOptions</a></code> |
224
+
225
+ **Returns:** <code>Promise&lt;<a href="#permissionstatusresult">PermissionStatusResult</a>&gt;</code>
226
+
227
+ --------------------
228
+
229
+
230
+ ### checkMultiple(...)
231
+
232
+ ```typescript
233
+ checkMultiple(options: MultiplePermissionOptions) => Promise<MultiplePermissionStatusResult>
234
+ ```
235
+
236
+ Check several permissions without prompting.
237
+
238
+ | Param | Type |
239
+ | ------------- | ------------------------------------------------------------------------------- |
240
+ | **`options`** | <code><a href="#multiplepermissionoptions">MultiplePermissionOptions</a></code> |
241
+
242
+ **Returns:** <code>Promise&lt;<a href="#multiplepermissionstatusresult">MultiplePermissionStatusResult</a>&gt;</code>
243
+
244
+ --------------------
245
+
246
+
247
+ ### requestMultiple(...)
248
+
249
+ ```typescript
250
+ requestMultiple(options: MultiplePermissionOptions) => Promise<MultiplePermissionStatusResult>
251
+ ```
252
+
253
+ Request several permissions sequentially so dialogs are not shown on top of each other.
254
+
255
+ | Param | Type |
256
+ | ------------- | ------------------------------------------------------------------------------- |
257
+ | **`options`** | <code><a href="#multiplepermissionoptions">MultiplePermissionOptions</a></code> |
258
+
259
+ **Returns:** <code>Promise&lt;<a href="#multiplepermissionstatusresult">MultiplePermissionStatusResult</a>&gt;</code>
260
+
261
+ --------------------
262
+
263
+
264
+ ### shouldShowRationale(...)
265
+
266
+ ```typescript
267
+ shouldShowRationale(options: PermissionOptions) => Promise<ShouldShowRationaleResult>
268
+ ```
269
+
270
+ Whether Android should show a rationale before requesting again.
271
+ Returns `{ shouldShow: false }` on iOS and web.
272
+
273
+ | Param | Type |
274
+ | ------------- | --------------------------------------------------------------- |
275
+ | **`options`** | <code><a href="#permissionoptions">PermissionOptions</a></code> |
276
+
277
+ **Returns:** <code>Promise&lt;<a href="#shouldshowrationaleresult">ShouldShowRationaleResult</a>&gt;</code>
278
+
279
+ --------------------
280
+
281
+
282
+ ### openSettings(...)
283
+
284
+ ```typescript
285
+ openSettings(options?: OpenSettingsOptions | undefined) => Promise<void>
286
+ ```
287
+
288
+ Open the application or notification settings screen.
289
+ Rejects on web with `UNIMPLEMENTED`.
290
+
291
+ | Param | Type |
292
+ | ------------- | ------------------------------------------------------------------- |
293
+ | **`options`** | <code><a href="#opensettingsoptions">OpenSettingsOptions</a></code> |
294
+
295
+ --------------------
296
+
297
+
298
+ ### requestPreciseLocation()
299
+
300
+ ```typescript
301
+ requestPreciseLocation() => Promise<PermissionStatusResult>
302
+ ```
303
+
304
+ Ask for precise location.
305
+ On iOS, requests temporary full accuracy when already authorized when-in-use.
306
+ On Android, requests `ACCESS_FINE_LOCATION`.
307
+ On web, returns the geolocation permission status after prompting when possible.
308
+
309
+ **Returns:** <code>Promise&lt;<a href="#permissionstatusresult">PermissionStatusResult</a>&gt;</code>
310
+
311
+ --------------------
312
+
313
+
314
+ ### getPluginVersion()
315
+
316
+ ```typescript
317
+ getPluginVersion() => Promise<PluginVersionResult>
318
+ ```
319
+
320
+ Returns the platform implementation version marker.
321
+
322
+ **Returns:** <code>Promise&lt;<a href="#pluginversionresult">PluginVersionResult</a>&gt;</code>
323
+
324
+ --------------------
325
+
326
+
327
+ ### Interfaces
328
+
329
+
330
+ #### PermissionStatusResult
331
+
332
+ Result for a single permission status.
333
+
334
+ | Prop | Type | Description |
335
+ | ------------ | ----------------------------------------------------------------- | -------------------------------------------- |
336
+ | **`status`** | <code><a href="#apppermissionstate">AppPermissionState</a></code> | Current status for the requested permission. |
337
+
338
+
339
+ #### PermissionOptions
340
+
341
+ Options for checking or requesting a single permission.
342
+
343
+ | Prop | Type | Description |
344
+ | ---------------- | --------------------------------------------------------- | ----------------------- |
345
+ | **`permission`** | <code><a href="#permissionname">PermissionName</a></code> | Permission to evaluate. |
346
+
347
+
348
+ #### MultiplePermissionStatusResult
349
+
350
+ Result for several permission statuses.
351
+
352
+ | Prop | Type | Description |
353
+ | -------------- | ------------------------------------------------------------------------------------------------------------- | --------------------------------- |
354
+ | **`statuses`** | <code><a href="#record">Record</a>&lt;string, <a href="#apppermissionstate">AppPermissionState</a>&gt;</code> | Map of permission name to status. |
355
+
356
+
357
+ #### MultiplePermissionOptions
358
+
359
+ Options for checking or requesting several permissions.
360
+
361
+ | Prop | Type | Description |
362
+ | ----------------- | ----------------------------- | --------------------------------- |
363
+ | **`permissions`** | <code>PermissionName[]</code> | Permissions to evaluate in order. |
364
+
365
+
366
+ #### ShouldShowRationaleResult
367
+
368
+ Result for Android rationale checks.
369
+
370
+ | Prop | Type | Description |
371
+ | ---------------- | -------------------- | ---------------------------------------------------------------------------------------------------------- |
372
+ | **`shouldShow`** | <code>boolean</code> | True only when Android would show a rationale dialog before requesting again. Always false on iOS and web. |
373
+
374
+
375
+ #### OpenSettingsOptions
376
+
377
+ Options for opening system settings.
378
+
379
+ | Prop | Type | Description |
380
+ | ---------- | ----------------------------------------------------- | --------------------------------------------------------- |
381
+ | **`type`** | <code><a href="#settingstype">SettingsType</a></code> | Which settings screen to open. Defaults to `application`. |
382
+
383
+
384
+ #### PluginVersionResult
385
+
386
+ Plugin version payload.
387
+
388
+ | Prop | Type | Description |
389
+ | ------------- | ------------------- | --------------------------------------------------------------------------------------------------- |
390
+ | **`version`** | <code>string</code> | Version identifier returned by the platform implementation (`native` on mobile, `web` in browsers). |
391
+
392
+
393
+ ### Type Aliases
394
+
395
+
396
+ #### AppPermissionState
397
+
398
+ Normalized permission status returned by every platform implementation.
399
+
400
+ - `granted`: the user allowed full access.
401
+ - `denied`: the user has not granted access yet, or Android can show a rationale.
402
+ - `blocked`: the user denied access and the app cannot prompt again without settings.
403
+ - `limited`: partial access (for example iOS limited photo library or reduced location accuracy).
404
+ - `unavailable`: the permission is not supported on this platform or not declared in the app manifest.
405
+
406
+ <code>'granted' | 'denied' | 'blocked' | 'limited' | 'unavailable'</code>
407
+
408
+
409
+ #### PermissionName
410
+
411
+ Logical permission identifiers shared across iOS, Android, and web.
412
+
413
+ Android-only names include `activityRecognition`, `phone`, `sms`, `mediaAudio`, `mediaImages`, and `mediaVideo`.
414
+ iOS-only names include `reminders` and `appTrackingTransparency`.
415
+ Web supports a subset via browser APIs (`camera`, `microphone`, `notifications`, `locationWhenInUse`).
416
+ On web, `locationAlways` is an alias of foreground geolocation only; browsers do not expose background location permission.
417
+
418
+ <code>'camera' | 'microphone' | 'photoLibrary' | 'photoLibraryAddOnly' | 'contacts' | 'calendar' | 'reminders' | 'locationWhenInUse' | 'locationAlways' | 'bluetooth' | 'motion' | 'notifications' | 'speechRecognition' | 'appTrackingTransparency' | 'activityRecognition' | 'phone' | 'sms' | 'mediaAudio' | 'mediaImages' | 'mediaVideo'</code>
419
+
420
+
421
+ #### Record
422
+
423
+ Construct a type with a set of properties K of type T
424
+
425
+ <code>{
4
426
  [P in K]: T;
5
427
  }</code>
428
+
429
+
430
+ #### SettingsType
431
+
432
+ Settings screen type for `openSettings`.
433
+
434
+ <code>'application' | 'notifications'</code>
435
+
436
+ </docgen-api>
@@ -0,0 +1,68 @@
1
+ ext {
2
+ junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
3
+ androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.7.1'
4
+ androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.3.0'
5
+ androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.7.0'
6
+ androidxCoreKTXVersion = project.hasProperty('androidxCoreKTXVersion') ? rootProject.ext.androidxCoreKTXVersion : '1.17.0'
7
+ }
8
+
9
+ buildscript {
10
+ ext.kotlin_version = project.hasProperty("kotlin_version") ? rootProject.ext.kotlin_version : '2.2.20'
11
+ repositories {
12
+ google()
13
+ mavenCentral()
14
+ }
15
+ dependencies {
16
+ classpath 'com.android.tools.build:gradle:8.13.0'
17
+ classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
18
+ }
19
+ }
20
+
21
+ apply plugin: 'com.android.library'
22
+ apply plugin: 'kotlin-android'
23
+
24
+ android {
25
+ namespace = "app.capgo.permissions"
26
+ compileSdk = project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 36
27
+ defaultConfig {
28
+ minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 24
29
+ targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 36
30
+ versionCode 1
31
+ versionName "1.0"
32
+ testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
33
+ }
34
+ buildTypes {
35
+ release {
36
+ minifyEnabled false
37
+ proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
38
+ }
39
+ }
40
+ lint {
41
+ abortOnError = false
42
+ }
43
+ compileOptions {
44
+ sourceCompatibility JavaVersion.VERSION_21
45
+ targetCompatibility JavaVersion.VERSION_21
46
+ }
47
+ }
48
+
49
+ kotlin {
50
+ jvmToolchain(21)
51
+ }
52
+
53
+ repositories {
54
+ google()
55
+ mavenCentral()
56
+ }
57
+
58
+ dependencies {
59
+ implementation fileTree(dir: 'libs', include: ['*.jar'])
60
+ implementation project(':capacitor-android')
61
+ implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
62
+ implementation "androidx.core:core-ktx:$androidxCoreKTXVersion"
63
+ testImplementation "junit:junit:$junitVersion"
64
+ testImplementation 'org.robolectric:robolectric:4.14.1'
65
+ testImplementation 'androidx.test:core:1.7.0'
66
+ androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
67
+ androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
68
+ }
@@ -0,0 +1,2 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android">
2
+ </manifest>