Skip to content

Commit cd31da9

Browse files
committed
feat: initial commit
0 parents  commit cd31da9

File tree

9 files changed

+1841
-0
lines changed

9 files changed

+1841
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
*.log
3+
build

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019 Shelley Vohr
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# node-mac-permissions
2+
3+
```js
4+
$ npm i node-mac-permissions
5+
```
6+
7+
This native Node.js module allows you to manage an app's access to:
8+
9+
* Contacts
10+
* Full Disk Access
11+
* Calendar
12+
* Photos
13+
14+
## API
15+
16+
## `permissions.getAuthStatus(type)`
17+
18+
* `type` - The type of system component to which you are requesting access. Can be one of `contacts`, `full-disk-access`, `photos`, or `calendar`.
19+
20+
Returns `String` - Can be one of 'Not Determined', 'Denied', 'Authorized', or 'Restricted'.
21+
22+
Checks the authorization status of the application to access `type` on macOS.
23+
24+
Return Value Descriptions:
25+
* 'Not Determined' - The user has not yet made a choice regarding whether the application may access `type` data.
26+
* 'Not Authorized' - The application is not authorized to access `type` data. The user cannot change this application’s status, possibly due to active restrictions such as parental controls being in place.
27+
* 'Denied' - The user explicitly denied access to `type` data for the application.
28+
* 'Authorized' - The application is authorized to access `type` data.
29+
30+
**Note:** Access to `contacts` will always return a status of 'Authorized' prior to macOS 10.13 High Sierra, as access to contacts was unilaterally allowed until that version.

binding.gyp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"targets": [{
3+
"target_name": "permissions",
4+
"sources": [ ],
5+
"conditions": [
6+
['OS=="mac"', {
7+
"sources": [
8+
"permissions.mm"
9+
],
10+
}]
11+
],
12+
'include_dirs': [
13+
"<!@(node -p \"require('node-addon-api').include\")"
14+
],
15+
'libraries': [],
16+
'dependencies': [
17+
"<!(node -p \"require('node-addon-api').gyp\")"
18+
],
19+
'defines': [ 'NAPI_DISABLE_CPP_EXCEPTIONS' ],
20+
"xcode_settings": {
21+
"OTHER_CPLUSPLUSFLAGS": ["-std=c++14", "-stdlib=libc++", "-mmacosx-version-min=10.10"],
22+
"OTHER_LDFLAGS": ["-framework CoreFoundation -framework AppKit -framework Contacts -framework EventKit -framework Photos"]
23+
}
24+
}]
25+
}

index.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const permissions = require('bindings')('permissions.node')
2+
3+
function getAuthStatus(type) {
4+
const validTypes = ['contacts', 'calendar', 'photos', 'full-disk-access']
5+
if (!validTypes.includes(type)) {
6+
throw new TypeError(`${type} is not a valid type`)
7+
}
8+
9+
return permissions.getAuthStatus.call(this, type)
10+
}
11+
12+
module.exports = {
13+
getAuthStatus
14+
}

0 commit comments

Comments
 (0)