Capabilities and grants#
A capability is the app's access to something outside it: notifications, a web service, a schedule, the camera. The definition names a contract, such as core:http, never a provider: the host connects one. Nothing happens outside the app unless a grant request covers it and someone entitled to answer said yes. A first web read needs the next two sections and the sourced entries of state; look up the rest in the reference at the end.
A capability and its grant request#
JSON
{
"weather": {
"contract": "core:http",
"description": "The weather service the forecast comes from.",
"config": { "origin": "https://weather.example.com" }
}
}
JSON
{
"readForecast": {
"capability": "weather",
"scopes": ["http.read"],
"reason": "Read the forecast for the city you choose. Only the city's name is sent.",
"where": "input.path == '/v1/forecast'",
"rate": { "count": 48, "per": "P1D" }
}
}
The key of a capability (weather) is its alias: steps call weather.get, and grant requests name weather.
| Capability field | What it is |
|---|---|
contract |
Required. core: and the contract's name. |
description |
Required. Why the app uses it, in the person's words. |
config |
The contract's settings, such as the origin of a web service. May read only env. |
required |
Default true. With false the app opens without it, and capabilities. says whether it is there. |
| Grant request field | What it is |
|---|---|
capability |
The alias it covers. |
scopes |
The contract's scopes it asks for; each operation needs one. Ask for the fewest. |
operations |
Optional: only these operations within the scopes. |
reason |
Required. Shown to the person before they answer: say what is read or done, and what is not. |
where |
An expression over input (the operation's input) and env: a call is allowed only when it holds. |
rate |
At most count calls per duration. |
duration |
The longest the permission lasts, such as P90D. |
required |
Default true. With false the app opens without it (see below). |
Every operation the app uses must be covered by a request for its scope (grant.uncovered without one), and a scope the contract lacks is grant.unknownScope.
Web services and web images#
A core:http capability reaches exactly one origin, an https address such as https://weather.example.com, and paths under it. Narrow the request with where on input.path. A response is a core:HttpResponse: a read that the service answers with an error status still succeeds, so test status.
A web address in a remote prop, such as an image's source, makes the host fetch it. That needs an http.read grant on a capability whose origin is that address's origin: the check reports egress.ungranted for a literal address with no such grant, and egress.originMismatch for one on another origin. A file a person gave the app needs none, and so does a picture the app carries, "asset:<name>" (see controls).
When the person is asked#
| The request | Is asked |
|---|---|
| Every scope "given by use" (choosing a file, taking a photo, sharing) | Never: the person's own act each time is the consent. |
A code module ("code") |
Never: it runs in the host's sandbox and reaches nothing. A host may ask all the same. |
| A capability the host serves from sample data, or keeps inside the app | Never, on that host: a demonstration service, or a service the host keeps inside the app, is not asked for. Never count on it: another host asks. |
"required": true (the default) |
When the app is first opened, before it opens. |
"required": false |
When something the person does first needs it. When several people share the app, the reference host asks the owner as the app opens instead, for every request the owner answers. |
With one person, an optional request that nothing a person does needs is never asked. A call made by a rule that time or an event started asks nobody: it fails with grant.denied, so what depends on the permission never happens, and nobody sees an error. A host may ask sooner; never count on it.
So:
- Leave a request required unless the app is useful without it.
- When it is optional, give the person a control whose action uses it, shown only while the request is unanswered. The plant care app asks for its schedule when the first plant is added (
addPlantcallswakeAt), and for notifications when the person presses "Turn on reminders", whose action sends a first notification. No step asks for a permission on its own: the question comes with a call that needs it. A host that shows notifications only inside the app gives them without asking, and the button never shows there.
JSON
{
"control": "core:button",
"when": "!grants.reminders.held && !grants.reminders.declined",
"props": { "label": "Turn on reminders", "icon": "notification" },
"on": { "press": { "run": "turnOnReminders" } }
}
When the point of the app is its reminders, say on the screen that they are off until the person turns them on:
JSON
{ "control": "core:text", "when": "!grants.reminders.held", "props": { "value": "=grants.reminders.declined ? 'Reminders are off. You can turn them on in the permissions of the app.' : 'Reminders are off until you turn them on.'", "style": "caption" } }
- A call can be refused. When the person says no, the call fails with
grant.denied. Give such acallanonErrorso the action still does the rest. grants.<name>.heldistruewhile the permission is in force;grants.<name>.declinedwhile a no stands.
Who answers#
Most capabilities act for the app as a whole: the owner answers once, for everyone who uses it. Capabilities marked "personal" below (files, media, location, clipboard, share) act for one person, and each person answers for themselves.
Working while nobody has the app open#
every rules, flow timers (after) and timed refreshes run only while a person has the app open, unless the app holds a grant on a capability with the background trait: in the core catalog, core:scheduler. An every rule without one is warned about (trigger.noBackground) unless it says "foreground": true, meaning it is meant to run only while the app is open. The scheduler also lets the app wake itself at a time it chooses (wakeAt), and a rule follows the wake event: see the plant care example.
The grant must be held before the app is closed. Make its request required, or have an act of the person's call the scheduler first, as adding a plant does.
Notifications#
notify.send notifies the person on whose behalf the work runs: the one who pressed the button, or the person a rule acts for. notify.sendTo notifies someone else, by id, and needs the scope notify.others. Give view to open a view when the notification is opened.
Using an operation#
An operation is used by a call step (see actions) or, when it only reads, by a sourced state entry (see state), with the input the reference below lists.
Every core capability#
| Capability | Operations | Events |
|---|---|---|
core:notify |
send, sendTo |
none |
core:scheduler |
wakeAt, cancel |
wake |
core:http |
get, send |
none |
core:files |
pick, read, save |
none |
core:media |
capturePhoto, captureAudio |
none |
core:location |
current |
none |
core:directory |
me, get, manager, members, find |
none |
core:records |
list, get, count, aggregate, create, update, delete |
changed |
core:share |
send |
none |
core:clipboard |
write, read |
none |
Scopes marked "given by use" are never asked: the person's own act at that moment is the consent. Every other scope is asked. "Personal" means each person answers for themselves.
core:notify#
Send a notification to the person using the app, or to another named person, such as a reminder, an alert or a request for approval.
- Scope
notify.self(low): Send you notifications. - Scope
notify.others(medium): Send notifications to other people on your behalf. - Operation
send(notify.self, external): inputtitlestring (required);bodystring;viewstring;viewInputobject;urgency"low" | "normal" | "high" (default "normal"); output string. Notify the current user: the person the acting principal is or acts for, never an agent or the app. - Operation
sendTo(notify.others, external): inputtostring (required);titlestring (required);bodystring;viewstring;viewInputobject;urgency"low" | "normal" | "high" (default "normal"); output string. Notify another principal, by id, on behalf of the current user: the person the acting principal is or acts for, never an agent or the app.
core:scheduler#
Let the app run while nobody has it open.
- Traits:
background. - Scope
scheduler.background(medium): Let this app run while nobody has it open: its repeating rules, deadlines and scheduled data refreshes run unattended, it responds to events from its other capabilities and to changes such as coming back online, and it can wake itself at times it sets. - Operation
wakeAt(scheduler.background, write): inputatdatetime (required);keystring (required); output datetime. Wake the app once at the given time, raising the wake event on behalf of the person for whom it is scheduled. - Operation
cancel(scheduler.background, write): inputkeystring (required); output boolean. Cancel a pending wake by its key. - Event
wake(scheduler.background): payloadkeystring,atdatetime. A scheduled wake arrived.
core:http#
Read from or send to one web service.
- Traits:
egress. - Config:
originstring (required);auth"none" | "host" (default "none"). - Scope
http.read(high): Read data from the named web service, and show images and other content from it in this app. - Scope
http.send(high): Send data from this app to the named web service. - Operation
get(http.read, read): inputpathstring (default "/");queryobject;headersobject; output HttpResponse. Fetch a resource from the service without changing anything. - Operation
send(http.send, external): inputmethod"POST" | "PUT" | "PATCH" | "DELETE" (default "POST");pathstring (default "/");queryobject;headersobject;bodyany;encoding"json" | "form" | "text" (default "json"); output HttpResponse. Send data to the service, such as submitting a form or creating an item there.
core:files#
Work with the user's own files: ask them to choose files, read what they chose, and save new files where they decide.
- Traits:
offline,personal. - Scope
files.pick(low, given by use): Ask you to choose files for this app. - Scope
files.read(medium, given by use): Read the contents of files given to this app: files you choose, photos and recordings you take, files it saved, and files that other people using it shared with you. - Scope
files.save(medium, given by use): Save files to a place you choose. - Operation
pick(files.pick, read, interactive): inputacceptFileKind[] (default ["any"]);multipleboolean (default false); output FileRef[]. Ask the person the app is acting for to choose one or more files, on a surface of theirs that is open; with none, the call fails with capability.unavailable. - Operation
read(files.read, read): inputfileFileRef (required);as"text" | "json" | "records" | "base64" (default "text"); output any. Read the contents of a file whose reference the host issued to this app instance: by pick, by save, by a capture, or for a file an agent handed to the host. - Operation
save(files.save, write, interactive): inputnamestring (required);contentany (required);as"text" | "json" | "records" | "base64" (default "text");mediaTypestring; output FileRef?. Ask the person the app is acting for to choose a place, on a surface of theirs that is open, and save a new file there; with no such surface, the call fails with capability.unavailable.
core:media#
Capture a photo or a short audio clip with the device, with the user taking the photo or making the recording themselves.
- Traits:
offline,personal. - Scope
media.camera(high, given by use): Use your camera when you choose to take a photo. - Scope
media.microphone(high, given by use): Use your microphone when you choose to record. - Operation
capturePhoto(media.camera, read, interactive): inputfacing"any" | "front" | "back" (default "any"); output FileRef?. Open the camera for the person the app is acting for to take one photo, on a surface of theirs that is open; with none, the call fails with capability.unavailable. - Operation
captureAudio(media.microphone, read, interactive): inputmaxDurationduration; output FileRef?. Let the person the app is acting for record one audio clip, on a surface of theirs that is open; with none, the call fails with capability.unavailable.
core:location#
Find where the device is right now, once per request.
- Traits:
personal. - Scope
location.current(high): See where your device is when the app asks. - Operation
current(location.current, read): inputprecision"approximate" | "precise" (default "approximate");maxAgeduration; output GeoPoint. Get the device's current position.
core:directory#
Look up people and their roles: who the current user is, who their manager is, who holds a role, and who matches a name.
- Traits:
multiUser. - Scope
directory.self(low): See your own name and roles. - Scope
directory.read(medium): See the names, roles and reporting lines of people in your organization. - Operation
me(directory.self, read): input none; output Principal. Get the current user as the directory knows them: the person the acting principal is or acts for, never an agent or the app. - Operation
get(directory.read, read): inputidstring (required); output Principal?. Get a principal by id. - Operation
manager(directory.read, read): inputofstring; output Principal?. Get the manager of a principal, or, when of is absent, of the current user: the person the acting principal is or acts for, never an agent or the app. - Operation
members(directory.read, read): inputrolestring (required); output Principal[]. List the principals that hold a role. - Operation
find(directory.read, read): inputtextstring (required);limitinteger 1 to 100 (default 20); output Principal[]. Find people whose name matches some text, for choosing an assignee or approver.
core:records#
Read and change a collection of records kept somewhere else, such as tickets in a tracker, rows in a spreadsheet or rows in a database table.
- Config:
collectionstring (required). - Scope
records.read(medium): Read records in the collection. - Scope
records.write(medium): Add and change records in the collection. - Scope
records.delete(high): Remove records from the collection. - Operation
list(records.read, read, paged): inputfilterRecordCondition[] (default []);sortSortKey[] (default []);limitinteger 1 to 500 (default 50);cursorstring?; output RecordPage. List records that pass every condition, in the requested order, one page at a time. - Operation
get(records.read, read): inputidstring (required); output Record?. Get one record by id. - Operation
count(records.read, read): inputfilterRecordCondition[] (default []); output RecordCount. Count the records that pass every condition. - Operation
aggregate(records.read, read): inputfilterRecordCondition[] (default []);groupBystring[] (default []);measuresobject (required);limitinteger 1 to 1000 (default 100); output RecordAggregate. Group the records that pass every condition and compute measures for each group. - Operation
create(records.write, write): inputfieldsobject (required); output Record. Add a new record. - Operation
update(records.write, write): inputidstring (required);fieldsobject (required); output Record. Change some fields of a record. - Operation
delete(records.delete, write): inputidstring (required); output boolean. Remove a record. - Event
changed(records.read): payloadidstring,change"created" | "updated" | "deleted",recordRecord?. A record in the collection was added, changed or removed, by this app or anyone else.
core:share#
Hand text, a link or files to the device's share mechanism, so the user picks where they go.
- Traits:
personal. - Scope
share.send(low, given by use): Offer content from this app for you to share wherever you choose. - Operation
send(share.send, external, interactive): inputtitlestring;textstring;urlstring;filesFileRef[]; output boolean. Open the share mechanism with the given content for the person the app is acting for, on a surface of theirs that is open; with none, the call fails with capability.unavailable.
core:clipboard#
Copy text to the clipboard, and, with a separate and more sensitive permission, read what is on it.
- Traits:
personal. - Scope
clipboard.write(low): Copy text to your clipboard. - Scope
clipboard.read(high): Read whatever text is on your clipboard, which may have come from other apps. - Operation
write(clipboard.write, write): inputtextstring (required); output boolean. Put text on the clipboard, replacing what was there. - Operation
read(clipboard.read, read): input none; output string?. Get the text currently on the clipboard, or null if it holds no text.
Next#
sample-datato run an app that uses a service without one.actionsforcall,onErrorandonce.rulesfor following capability events.