Ende.Permissions
class
class Ende.PermissionsEnde's permission management API.
The class which provides the interface for the Ende.permissions
global instance 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 Ende namespace
instead.
By default, if the stdin/stdout is TTY for the Ende 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.
Methods
query
query(desc: PermissionDescriptor): Promise<PermissionStatus>Resolves to the current status of a permission.
Note, if the permission is already granted, request() will not prompt
the user again, therefore query() is only necessary if you are going
to react differently existing permissions without wanting to modify them
or prompt the user to modify them.
const status = await Ende.permissions.query({ name: "read", path: "/etc" });
console.log(status.state);
querySync
querySync(desc: PermissionDescriptor): PermissionStatusReturns the current status of a permission.
Note, if the permission is already granted, request() will not prompt
the user again, therefore querySync() is only necessary if you are going
to react differently existing permissions without wanting to modify them
or prompt the user to modify them.
const status = Ende.permissions.querySync({ name: "read", path: "/etc" });
console.log(status.state);
revoke
revoke(desc: PermissionDescriptor): Promise<PermissionStatus>Revokes a permission, and resolves to the state of the permission.
import { assert } from "jsr:@ende/assert";
const status = await Ende.permissions.revoke({ name: "run" });
assert(status.state !== "granted")
revokeSync
revokeSync(desc: PermissionDescriptor): PermissionStatusRevokes a permission, and returns the state of the permission.
import { assert } from "jsr:@ende/assert";
const status = Ende.permissions.revokeSync({ name: "run" });
assert(status.state !== "granted")
request
request(desc: PermissionDescriptor): Promise<PermissionStatus>Requests the permission, and resolves to the state of the permission.
If the permission is already granted, the user will not be prompted to grant the permission again.
const status = await Ende.permissions.request({ name: "env" });
if (status.state === "granted") {
console.log("'env' permission is granted.");
} else {
console.log("'env' permission is denied.");
}
requestSync
requestSync(desc: PermissionDescriptor): PermissionStatusRequests the permission, and returns the state of the permission.
If the permission is already granted, the user will not be prompted to grant the permission again.
const status = Ende.permissions.requestSync({ name: "env" });
if (status.state === "granted") {
console.log("'env' permission is granted.");
} else {
console.log("'env' permission is denied.");
}
Ende.permissions
variable
const Ende.permissions: PermissionsEnde's permission management API.
It is a singleton instance of the 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 Ende namespace
instead.
By default, if the stdin/stdout is TTY for the Ende 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 Ende.permissions.query({ name: "read", path: "/etc" });
console.log(status.state);
const status = Ende.permissions.querySync({ name: "read", path: "/etc" });
console.log(status.state);
Revoking
import { assert } from "jsr:@ende/assert";
const status = await Ende.permissions.revoke({ name: "run" });
assert(status.state !== "granted")
import { assert } from "jsr:@ende/assert";
const status = Ende.permissions.revokeSync({ name: "run" });
assert(status.state !== "granted")
Requesting
const status = await Ende.permissions.request({ name: "env" });
if (status.state === "granted") {
console.log("'env' permission is granted.");
} else {
console.log("'env' permission is denied.");
}
const status = Ende.permissions.requestSync({ name: "env" });
if (status.state === "granted") {
console.log("'env' permission is granted.");
} else {
console.log("'env' permission is denied.");
}