Skip to content

Jobs, network and connections ​

Network ​

Screens, views, blocks and jobs have no network of their own. To reach a website, list its host in the manifest and fetch through Sorus:

json
"network": ["letterboxd.com", "*.example.com"]
js
const response = await pages.fetch('https://letterboxd.com/you/rss/')
if (response.ok) parse(response.text())
  • A host is reached if it's listed exactly, or falls under a *. entry.
  • The person sees the hosts before installing, and approves them.
  • fetch(url, { method, headers, body }) returns status, ok, headers, and the body as text(), json() or bytes().
  • A request times out after 30 seconds; responses are capped at 10 MB.

Connections ​

A connection is the person's account on another service. They give Sorus the secret; Sorus adds it to your requests to that service's hosts. Your code never sees it.

json
"connections": [
  {
    "id": "github",
    "title": "GitHub",
    "hosts": ["api.github.com"],
    "auth": { "kind": "bearer" },
    "help": "https://github.com/settings/personal-access-tokens"
  }
]
Key
id, titleIts key, and its name in Sorus.
hostsWhere the secret may go. At least one.
auth{ "kind": "bearer" }, { "kind": "header", "name": "X-Api-Key" }, or { "kind": "query", "name": "token" }.
helpOptional https:// link to where to get a secret.
js
if ((await pages.connections.status('github')) === null) {
  await pages.connections.connect('github') // Sorus's dialog
}
const issues = await pages.fetch('https://api.github.com/issues', { connection: 'github' })

The person can also connect and disconnect from the app's ⋯ menu.

Jobs ​

A job is a script Sorus runs in the background, such as a sync.

json
"jobs": [{ "id": "rss", "title": "Sync recent diary", "entry": "jobs/rss.js", "every": 60 }]
Key
id, titleIts key, and its name in Sorus.
entryA .js or .mjs script in the folder.
everyMinutes between runs, at least 15. Leave it out to run only when asked.
  • Jobs run while Sorus is open. Sorus checks every minute for jobs that are due.
  • The person can run one now from the app's ⋯ menu.
  • pages.job.id says which job is running.
  • Call pages.finish(summary) when done; the summary goes to the console. A job still running after 5 minutes is stopped.
js
import { connect } from '/__pages/sdk.js'

const pages = await connect()
try {
  const added = await sync(pages)
  pages.finish(`Added ${added}`)
} catch (error) {
  console.error(error)
  pages.finish('Failed')
}

Storage ​

pages.storage keeps small values for the extension on this device, such as a username or when it last synced:

js
await pages.storage.set('username', 'ana')
const username = await pages.storage.get('username')