Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

node-mac-permissions

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-mac-permissions - npm Package Compare versions

Comparing version 1.4.0 to 2.0.0

.github/workflows/lint.yml

25

index.js

@@ -1,2 +0,2 @@

const permissions = require('bindings')('permissions.node')
const permissions = require('bindings')('permissions.node');

@@ -13,20 +13,12 @@ function getAuthStatus(type) {

'location',
'screen'
]
'screen',
];
if (!validTypes.includes(type)) {
throw new TypeError(`${type} is not a valid type`)
throw new TypeError(`${type} is not a valid type`);
}
return permissions.getAuthStatus.call(this, type)
return permissions.getAuthStatus.call(this, type);
}
function askForMediaAccess(type) {
if (!['microphone', 'camera'].includes(type)) {
throw new TypeError(`${type} must be either 'camera' or 'microphone'`)
}
return permissions.askForMediaAccess.call(this, type)
}
module.exports = {

@@ -37,6 +29,7 @@ askForCalendarAccess: permissions.askForCalendarAccess,

askForRemindersAccess: permissions.askForRemindersAccess,
askForCameraAccess: permissions.askForCameraAccess,
askForMicrophoneAccess: permissions.askForMicrophoneAccess,
askForScreenCaptureAccess: permissions.askForScreenCaptureAccess,
askForAccessibilityAccess: permissions.askForAccessibilityAccess,
askForMediaAccess,
getAuthStatus
}
getAuthStatus,
};
{
"name": "node-mac-permissions",
"version": "1.4.0",
"version": "2.0.0",
"description": "A native node module to manage system permissions on macOS",

@@ -9,3 +9,4 @@ "main": "index.js",

"clean": "node-gyp clean",
"format": "clang-format -i permissions.mm",
"lint": "prettier --check index.js",
"format": "clang-format -i permissions.mm && prettier --write index.js",
"test": "./node_modules/.bin/mocha --reporter spec"

@@ -38,4 +39,5 @@ },

"mocha": "^6.2.2",
"node-gyp": "^6.0.1"
"node-gyp": "^6.0.1",
"prettier": "^2.0.4"
}
}

@@ -123,28 +123,58 @@ [![MIT license](https://img.shields.io/badge/License-MIT-blue.svg)](https://lbesson.mit-license.org/)

## `permissions.askForMediaAccess(type)`
## `permissions.askForCameraAccess()`
* `type` String - The type of media to which you are requesting access. Can be `microphone` or `camera`.
Returns `Promise<String>` - Current permission status; can be `authorized`, `denied`, or `restricted`.
Returns `Promise<String>` - Whether or not the request succeeded or failed; can be `authorized` or `denied`.
Checks the authorization status for camera access. If the status check returns:
Your app must provide an explanation for its use of capture devices using the `NSCameraUsageDescription` or `NSMicrophoneUsageDescription` `Info.plist` keys; Calling this method or attempting to start a capture session without a usage description raises an exception.
- `not determined`, the camera access authorization will prompt the user to authorize or deny. The Promise is resolved after the user selection with either `authorized` or `denied`.
- `denied`, the `Security & Privacy` System Preferences window is opened with the Camera privacy key highlighted. On open of the `Security & Privacy` window, the Promise is resolved as `denied`.
- `restricted`, the Promise is resolved as `restricted`.
Your app must provide an explanation for its use of capture devices using the `NSCameraUsageDescription` `Info.plist` key; Calling this method or attempting to start a capture session without a usage description raises an exception.
```
<key>`NSCameraUsageDescription</key>
<key>NSCameraUsageDescription</key>
<string>Your reason for wanting to access the Camera</string>
<key>`NSMicrophoneUsageDescription</key>
```
**Note:**
- `status` will be resolved back as `authorized` prior to macOS 10.14 High Sierra, as access to the camera and microphone was unilaterally allowed until that version.
Example:
```js
const { askForCameraAccess } = require("node-mac-permissions");
const status = await askForCameraAccess();
```
## `permissions.askForMicrophoneAccess()`
Returns `Promise<String>` - Current permission status; can be `authorized`, `denied`, or `restricted`.
Checks the authorization status for microphone access. If the status check returns:
- `not determined`, the microphone access authorization will prompt the user to authorize or deny. The Promise is resolved after the user selection with either `authorized` or `denied`.
- `denied`, the `Security & Privacy` System Preferences window is opened with the Microphone privacy key highlighted. On open of the `Security & Privacy` window, the Promise is resolved as `denied`.
- `restricted`, the Promise is resolved as `restricted`.
Your app must provide an explanation for its use of capture devices using the `NSMicrophoneUsageDescription` `Info.plist` key; Calling this method or attempting to start a capture session without a usage description raises an exception.
```
<key>NSMicrophoneUsageDescription</key>
<string>Your reason for wanting to access the Microphone</string>
```
**Note:** `status` will be resolved back as `authorized` prior to macOS 10.14 High Sierra, as access to the camera and microphone was unilaterally allowed until that version.
**Note:**
- `status` will be resolved back as `authorized` prior to macOS 10.14 High Sierra, as access to the camera and microphone was unilaterally allowed until that version.
Example:
```js
const { askForMediaAccess } = require('node-mac-permissions')
const { askForMicrophoneAccess } = require("node-mac-permissions");
for (const type of ['microphone', 'camera']) {
askForMediaAccess(type).then(status => {
console.log(`Access to media type ${type} is ${status}`)
})
}
const status = await askForMicrophoneAccess();
```

@@ -173,1 +203,13 @@

```
## FAQ
Q. I'm seeing an error like the following when using webpack:
```sh
App threw an error during load
TypeError: Cannot read property 'indexOf' of undefined
at Function.getFileName (webpack-internal:///./node_modules/bindings/bindings.js:178:16)
```
A. This error means that webpack packed this module, which it should not. To fix this, you should configure webpack to use this module externally, e.g explicitly not pack it.
const { expect } = require('chai')
const {
getAuthStatus,
askForMediaAccess
} = require('../index')

@@ -35,12 +34,2 @@

})
describe('askForMediaAccess(type, callback)', () => {
it ('throws on invalid media types', () => {
expect(() => {
askForMediaAccess('bad-type').then(status =>{
console.log(status)
})
}).to.throw(/bad-type must be either 'camera' or 'microphone'/)
})
})
})

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc