Registration
An app that syncs has an app id and, optionally, a manifest. The manifest gives the consent page your app's name, icon and requested permissions. Registering a manifest is optional: users can approve an app that has none.
App id
The app id identifies your app on every server. Generate one with the civ command from jsr:@civility/cli:
deno install jsr:@civility/cli -Afg --unstable-cron --name=civ
civ id
It prints app- followed by 24 base32 characters. Put it in your CloudStore config as cloud.appId.
- Do not generate a new id for an existing app without moving to it as described in Changing the app id. Grants, tokens and synced data are tied to the id, so a new id on its own cuts every user off from their data.
- The id is public. It ships in your app's code, like an OAuth
client_id. Access comes from the token the user grants. - Every user of your app shares the id. On a server, each account that connects the app gets its own separate copy of the app's data, tokens and permissions.
Changing the app id
To move an existing app to a new id, keep the local storage ids as they are and list the old app id in formerAppIds:
const cloud = new CloudStore({
id: 'my-app', // local storage: unchanged
storage: { db: new IDBStorage({ id: 'my-app' }) },
cloud: { appId: 'app-k3m7q2x4p6w5z7n3b2v4c6h5', formerAppIds: ['my-app'] },
})
if (!await cloud.resume() && cloud.reauthorization) {
// Signed in under the old id: ask the user to sign in again.
await cloud.authorize({ serverUrl: cloud.reauthorization.serverUrl, scope })
}
- A device signed in under the old id gets
falsefromrestore(), withcloud.reauthorizationset (also announced as areauthorizeevent). Its old token belongs to the old id and is not used. - After the user signs in again, the next sync uploads the device's data to the new id on the same account. A second device merges with what the first one moved, without asking.
- The old app's data stays on the server until the user deletes the old app.
- Keep the old id in
formerAppIdsfor as long as devices may still run a build that used it.
Manifest
{
"name": "My App",
"description": "A short description of the app",
"homepageUrl": "https://myapp.example",
"requestedPermissions": [
{ "store": "*", "level": "read" }
]
}
| Field | Required | Notes |
|---|---|---|
name |
yes | 1 to 200 characters. |
description |
yes* | Up to 2000 characters. |
requestedPermissions |
yes* | { store, level } or { capability } entries. See below. |
homepageUrl |
no | http(s) URL. |
iconUrl |
no | http(s) URL. |
services |
no | [{ scope, reason, optional? }]. See Services. |
exposes |
no | Collections other apps may read: { [collection]: { type, access: 'read', label? } }. |
requests |
no | Other apps' data this app asks to read: [{ type, access: 'read', reason, optional? }]. |
changeRetentionDays |
no | How long the server keeps this app's change history. Whole number, 0 or more. |
* Required by the AppManifest TypeScript type. In JSON you may leave them out; description defaults to "" and requestedPermissions to [].
A store permission is { "store": "<name or *>", "level": "read" | "write" | "delete" }. A capability is { "capability": "identity:sign" | "sessions:manage" }.
validateManifest(input) from @civility/cloud returns { ok, issues }, where each issue is { path, message }.
Register the manifest
From the app
Pass the manifest to CloudStore. It is registered on the first sync.
authorize() also sends the manifest with the sign-in request, so the pages a new user sees (the Create & Authorize step and the approval page after it) already show your app's name, and the approval page the services it asks for. The account elements hand the same manifest to a custom authorize strategy such as authorizeNative, as options.manifest. This applies while the server has no manifest stored for the app; once one is stored, the stored one is shown. A manifest that is invalid, or larger than 4096 characters when encoded, is not sent, and those first pages then show the app id.
import { type AppManifest, CloudStore } from '@civility/cloud'
const manifest: AppManifest = {
name: 'My App',
description: 'A short description of the app',
requestedPermissions: [{ store: '*', level: 'write' }],
}
const cloud = new CloudStore({
// ...
cloud: { appId: APP_ID, manifest },
})
With the API
# Create the app id.
curl -X POST https://server.example/api/v1/apps \
-H 'Authorization: Bearer <token>' \
-H 'Content-Type: application/json' \
-d '{"id": "app-k3m7q2x4p6w5z7n3b2v4c6h5", "name": "My App"}'
# Attach the manifest.
curl -X POST https://server.example/api/v1/apps/app-k3m7q2x4p6w5z7n3b2v4c6h5/register \
-H 'Authorization: Bearer <token>' \
-H 'Content-Type: application/json' \
-d '{"manifest": {"name": "My App"}}'
Approved origins
For each user, the server keeps the origins the user has approved for your app. When your app id signs in from an origin the user has not approved, the consent page asks again and names the new origin, even if no new permissions are requested. Approving adds the origin. Users can remove an origin on the app's page on their server.
So if you move your app to a new domain, each user approves the new origin once.