Calls, events and orgs
Calls and views
Section titled “Calls and views”let answer = try await client.call(app, "send_message", ["message": "hi"]) // POST /apps/{app}/intentsanswer.index; answer.result; answer.eventslet read = try await client.view(app, "get_messages", [:]) // POST /apps/{app}/views- A call carries an idempotency key (
node:c-…unless you pass one). While the node answers503or cannot be reached, the same request with the same key is sent again: 6 retries, 200 ms doubling to 2 s, or the node’sRetry-Afterwhen longer (CloudRetryOptions). ThenUnavailableError, whosecommittedis.noor.unknown. - An app’s own refusal is
AppErrorwithappCodeandfields. callJSON/viewJSONtake and return JSON bytes, every number as written (au64beyond 2^53);CloudContextContractuses them.
Events
Section titled “Events”for try await event in client.events(app, from: 0) { … } // GET /apps/{app}/events, sealed SSEEach event has id (index:seq), kind and data. Cancel the task (or stop
iterating) to close the stream.
Orgs, teams, invites
Section titled “Orgs, teams, invites”| Call | Route |
|---|---|
orgs.create(name:recoveryKey:), orgs.get(org:), orgs.metadata(org:metadata:) |
/orgs, /orgs/{org} |
setRecoveryKey(org, publicKey:, passkey:), startRecovery(org, seed:), orgs.recoveryCancel(org:passkey:), orgs.recoveryFinish(org:passkey:) |
/orgs/{org}/recovery… |
orgs.teamCreate(org:name:join:), orgs.teamGet, updateTeam, orgs.teamDelete |
/orgs/{org}/teams/… |
orgs.setMember, orgs.removeMember, orgs.teamSetMember, orgs.teamRemoveMember, orgs.capabilities (each with passkey:) |
/orgs/{org}/members, …/capabilities |
orgs.inviteCreate(org:role:teams:passkey:) → .token (inv_…) |
POST /orgs/{org}/invites |
orgs.inviteRedeem(token:) |
POST /invites/{token}/redeem |
apps.create(name:package:org:grants:) (grants: [try AppGrant.team(id).generated]) |
POST /apps |
auth.me() lists the account’s organizations; orgs.get(org:) answers the organization, its teams, members and their metadata; OrgInfo(json: try JSONValue(encoding: org)) reads it as MeroKit’s type.
An owner who loses every passkey gets the organization back with its recovery seed (core rc.9+). The seed never leaves the device: the node stores only its public key and checks a signature the seed makes for the recovering account.
let seed = RecoverySeed()showToOwner(seed.text) // 64 hex digits in groups of eight; keep it offlinelet org = try await client.orgs.create(name: "Acme", recoveryKey: seed.publicKey).orgId
// Every passkey lost: sign up again with a new passkey, thenlet times = try await fresh.startRecovery(org, seed: try RecoverySeed(text: written))// 72 hours later (the owner may orgs.recoveryCancel; members see OrgInfo.recovery?.pending)_ = try await fresh.orgs.recoveryFinish(org: org, passkey: newPasskey) // RecoveryNotReady before readyAtRotating the key (setRecoveryKey) cancels a recovery under way, and the old
seed is refused from then on.
Updates
Section titled “Updates”apps.update(app:) 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):
let u = try await client.apps.update(app: app) // GET /apps/{app}/updateif let available = u.available { available._class // .green or .red (`class` in the JSON) available.reasons // why it is red: [Components.Schemas.UpdateReason] available.egress // where data can go after it (before, after, added, removed); nil when unknown available.signerChanged // nil when unknown available.summary // 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
(egress, stateVersionChanged, newMethods, removedMethods,
signerChanged) is nil: show it as unknown, never as unchanged. A session
bound to an app’s package asks for the upgrade on the
consent page
(ConsentRequest.upgrade(app:toVersion:returnTo:)).
The organization’s owner and admins decide how updates apply (Update policies) and may undo one for a week (Restore points and undo):
import MeroAPItypealias Policy = Operations.OrgPolicySet.Input.Body.JsonPayload.PolicyPayload_ = try await client.orgs.policySet(org: org, policy: Policy(autoApply: .never, holdHours: 24, secondApprover: true), passkey: passkey)// or client.apps.policySet(app:policy:passkey:) for one app (Operations.AppPolicySet…PolicyPayload)_ = try await client.apps.approveUpgrade(app: app, version: "1.1.0", passkey: passkey) // the first of two_ = try await other.apps.upgrade(app: app, version: "1.1.0", passkey: otherPasskey) // another owner or adminlet undo = try await client.apps.undoView(app: app) // available, reason, apps (what each part loses)_ = try await client.apps.undo(app: app, passkey: passkey)let waiting = try await client.orgs.updates(org: org) // every app with an update or an approval waitingWhen u.unit is true the instance’s own apps move with it: approve with
approveUpgrade(app:version:unit: true, passkey:) and apply with
upgradeUnit(app:version:passkey:)
(A second approver).
Public links
Section titled “Public links”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; the visitor’s client signs each
request with its own key:
let made = try await client.apps.publicLinkCreate(app: app, label: "Feedback", ratePerMinute: 60, passkey: passkey) // made.token is shown once; made.link is its idlet links = try await client.apps.publicLinkList(app: app)_ = try await client.apps.publicLinkRevoke(app: app, link: made.link, passkey: passkey)
// The visitor: no sign-in. Keep the seed (newVisitorSeed()) in the keychain to stay the same visitor.let visitorClient = CalimeroClient(CalimeroClientOptions(baseUrl: nodeURL, policy: .production))let visitor = try await visitorClient.useVisitor(link: made.token, seed: newVisitorSeed())// visitor.publicKey is how the app names the visitor; visitor.link names the linklet answer = try await visitorClient.call(app, "submit", ["text": "Hi"])expiresAt: (Unix seconds) is optional. useVisitor(link:seed:) 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 (Public links).
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.
Blobs and presence
Section titled “Blobs and presence”apps.blobUpload(app:body:contentType:) (the node stores the blob with the
contentType you name and answers downloads with it; leave it out and it is
sent as application/octet-stream), apps.blobDownload(app:id:grant:)
(grant: no session, a grant one of the app’s runs handed out),
blobContent(app, id, grant:) (bytes and content type), listBlobs,
blobInfo, apps.blobDelete(app:id:) on
/apps/{app}/blobs; appXcalls(app) for a component app’s outbox and dead
letters; publishPresence, presence,
presenceStream on /apps/{app}/presence.
let png = try Data(contentsOf: imageURL)let blob = try await client.apps.blobUpload(app: app, body: png, contentType: "image/png")let content = try await client.blobContent(app, blob.blobId) // content.contentType == "image/png"Sealed files
Section titled “Sealed files”A component app’s sealed file is stored under a key of its own that only the
app’s code and an export read; its owner and its organization’s members upload
and export it. uploadFile(app, data) sends it to /apps/{app}/files (a file
past 16 MiB as an upload session of parts) and answers its id, the
plaintext’s size and sha256. exportFile(app, id) downloads it: the node
answers only ciphertext and the file’s data key wrapped to a key the client
made for this export, and every segment, the size and the plaintext’s SHA-256
are checked before it is believed (ExportError when they are not).
exportFile(app, id, to:) hands the plaintext to a closure in chunks of at
most 64 KiB instead; when it throws, discard what the closure received.
let file = try await client.uploadFile(app, report)let back = try await client.exportFile(app, file.id) // == reporttry await client.exportFile(app, file.id, to: { handle.write($0) })Pipeline receipts
Section titled “Pipeline receipts”pipelineReceipt(app, run) reads an ended pipeline run’s signed receipt, and
verifyPipelineReceipt(app, run, answer) checks it as core’s client does,
under the client’s policy: every replica of the app attests its receipt key
(verifyAppCluster(app)), the answering replica signed the receipt, it is for
that app and run, every job report is signed by its job key, and each job key
is attested by a job node of the cluster. A failed check is a ReceiptError.