Skip to content

Apps

val appId = client.apps.create(
name = "general",
`package` = "com.calimero.chat", // installed from the registry if missing
org = orgId,
grants = listOf(AppGrant.Team(teamId)), // or Org, Account(…), Anyone; none: the owner
initArgs = buildJsonObject { put("name", "general") },
).appId

A raw bundle (client.packages.bundlePut, then apps.create(bundle = hash)) and .mpk uploads (client.packages.upload) work only on a --dev cluster; production installs only from the registry (client.packages.install).

apps.update says whether a newer release is available and what it changes, judged over the app and every app its release created with it (Where an update may send data):

val u = client.apps.update(app = appId)
u.available?.let { a ->
a.propertyClass // the JSON `class`: PropertyClass.GREEN or RED
a.reasons // why it is red: [{ code: "egressAdded", … }, …]
a.egress // before, after, added, removed; null when unknown
a.signerChanged // null when unknown
a.summary // the update in one plain line, for a banner
}
u.mayApprove // whether this caller may approve it

An update the node cannot classify (a release the app runs is no longer installed) is red with an unclassified reason, and what it would compare is null: show it as unknown, never as unchanged.

The organization’s owner and admins decide how updates apply (Update policies) and may undo one for a week (Restore points and undo); each change is a passkey step-up:

client.orgs.policySet(org = orgId, policy = Explicit(UpgradePolicyBodyPolicy(
secondApprover = true, autoApply = UpgradePolicyBodyPolicy.AutoApply.NEVER, holdHours = 24)))
// or apps.policySet(app = appId, policy = Explicit(UpgradePolicyBodyPolicy(…))) for one app;
// Explicit(null) drops it
client.apps.approveUpgrade(app = appId, version = "1.1.0") // the first of two
otherAdmin.apps.upgrade(app = appId, version = "1.1.0") // another owner or admin's client
client.apps.undoView(app = appId) // what an undo would lose (lostWrites)
client.apps.undo(app = appId)
client.orgs.updates(org = orgId) // every app with an update or an approval waiting

A public link lets anyone with its token call the app’s #[app::public] methods without an account (Public links). Whoever may change the app’s access makes one, with a passkey step-up; the visitor’s client signs each request with its own key:

val created = client.apps.publicLinkCreate(app = appId, label = "Feedback", ratePerMinute = 60)
created.token // shown once: hand it to visitors
client.apps.publicLinkList(app = appId).links // terms and creator, never a token
client.apps.publicLinkRevoke(app = appId, link = created.link)
// The visitor: no sign-in. Keep the seed (newVisitorSeed()) in encrypted preferences to stay the same visitor.
val visitorClient = CalimeroClient(CalimeroClientOptions(baseUrl = clusterUrl, policy = CloudPolicy.production))
val visitor = visitorClient.useVisitor(link = created.token, seed = newVisitorSeed())
visitor.publicKey // how the app names the visitor
visitorClient.apps.intents(app = appId, method = "submit", args = args)

useVisitor signs every request afresh (Bearer vis1.…, valid within 5 minutes of the node’s clock), and only the app’s #[app::public] methods answer it; useApiKey or useSession replaces it. forget() drops it without a request; signOut() does too, but first tries the revoke, which the node refuses with 403 VISITOR_ONLY (a visitor has no session), and throws that after the credential is gone.

val call = client.apps.intents(app = appId, method = "send_message", args = args) // index, result, events, receipt
val view = client.apps.views(app = appId, method = "get_messages", args = args) // index, result; consistency = STALE reads any replica

intents mints an idempotency key (node:c-…) unless you give one, and retries a 503 or a dropped connection with the same key (6 times, 200 ms doubling to 2 s). When it gives up it throws UnavailableError, whose committed is Committed.No (the node said it did not run) or Committed.Unknown. An app’s own refusal is AppError(appCode, fields).

client.events(appId, from = 0).collect { event -> /* event.kind, event.data */ }

A sealed server-sent event stream; cancel the collecting coroutine to close it.

val blob = client.uploadBlob(appId, bytes, "image/png") // BlobInfo(blobId base58, id hex, size)
val back = client.downloadBlob(appId, blob.blobId)
val content = client.blobContent(appId, blob.blobId) // bytes + the content type served
val shared = client.downloadBlobGranted(appId, blobId, grant) // a run's grant: no session needed
val outbox = client.apps.xcalls(app = appId) // a component app's pending xcalls, dead letters
client.publishPresence(appId, seq = 1, state = "typing".encodeToByteArray())
client.presence(appId)

A component app’s sealed files are encrypted on the node; only the app’s owner and its organization’s members may read them, and the node hands out only ciphertext:

val file = client.uploadFile(appId, bytes) // FileInfo(id, blobId, size, sha256, index)
val large = client.uploadFile(appId, java.io.File(path)) // past 16 MiB: an upload session, read part by part
val plain = client.exportFile(appId, file.id) // in memory
client.exportFileTo(appId, file.id, FileSink.of(output)) // streamed, one 64 KiB chunk at a time

An export asks the node to wrap the file’s data key to a key made for that call, checks every segment against the file’s id before opening it, and the size and plaintext SHA-256 at the end (core’s Client::export_file_to). A check that fails is an ExportError (BAD_ANSWER, NOT_THE_FILE, TAMPERED, TOO_LARGE); discard what the sink got then, since it may be a prefix. Cancel the coroutine to stop a download.

val cluster = client.verifyAppCluster(appId) // each replica's attested receipt key, the governance
val answer = client.pipelineReceipt(appId, runId) // { receipt, node, signature }, version 2
val receipt = client.verifyPipelineReceipt(appId, runId, answer)

verifyPipelineReceipt checks, under the client’s own CloudPolicy, that an attested replica’s receipt key signed the receipt, that it is for that app and run, and that every job’s report is signed by a job key a job node’s quote binds to the cluster; a failure is a ReceiptVerificationException naming what failed (core’s calimero-client, mero-js receipts.ts).