permissions property

Permissions get permissions

Deno's permission management API.

It is a singleton instance of the {@linkcode Permissions} object and is based on the web platform Permissions API, though some proposed parts of the API which are useful in a server side runtime context were removed or abandoned in the web platform specification which is why it was chosen to locate it in the {@linkcode Deno} namespace instead.

By default, if the stdin/stdout is TTY for the Deno CLI (meaning it can send and receive text), then the CLI will prompt the user to grant permission when an un-granted permission is requested. This behavior can be changed by using the --no-prompt command at startup. When prompting the CLI will request the narrowest permission possible, potentially making it annoying to the user. The permissions APIs allow the code author to request a wider set of permissions at one time in order to provide a better user experience.

Requesting already granted permissions will not prompt the user and will return that the permission was granted.

Querying

const status = await Deno.permissions.query({ name: "read", path: "/etc" });
console.log(status.state);
const status = Deno.permissions.querySync({ name: "read", path: "/etc" });
console.log(status.state);

Revoking

import { assert } from "https://deno.land/std/testing/asserts.ts";

const status = await Deno.permissions.revoke({ name: "run" });
assert(status.state !== "granted")
import { assert } from "https://deno.land/std/testing/asserts.ts";

const status = Deno.permissions.revokeSync({ name: "run" });
assert(status.state !== "granted")

Requesting

const status = await Deno.permissions.request({ name: "env" });
if (status.state === "granted") {
 console.log("'env' permission is granted.");
} else {
 console.log("'env' permission is denied.");
}
const status = Deno.permissions.requestSync({ name: "env" });
if (status.state === "granted") {
 console.log("'env' permission is granted.");
} else {
 console.log("'env' permission is denied.");
}

Implementation

_i4.Permissions get permissions => _i3.getProperty(
      this,
      'permissions',
    );