Skip to content

robledo ​

@c9up/robledo: over-the-air updates for a ream app's mobile build, signed by ream android:publish, served by the app, verified on the phone and rolled back when they never reach their first screen. Guide: Over-the-air updates.

Installation ​

bash
pnpm add @c9up/robledo

Add () => import('@c9up/robledo/provider') to the providers in reamrc.ts, and set mobile.updates there for the app build. The app built by ream android:* gets the native module through autolinking.

Entry points ​

ImportContents
@c9up/robledoThe server side: the Robledo class, its config type, the route helper and the error class.
@c9up/robledo/providerRobledoProvider (default export): binds Robledo and hands it the host router.
@c9up/robledo/services/mainThe application's Robledo instance (default export), usable once the provider booted.
@c9up/robledo/mobileThe app's side, run on the phone: check, download and stage updates, and confirm the running one.

Exports ​

@c9up/robledo ​

ExportKindDescription
RobledoclassServes the updates ream android:publish signed and wrote under the app's robledo/ directory.
RobledoConfiginterfaceThe robledo config.
LatestUpdateinterface{ manifest: string; signature: string }: the newest update's manifest text and its signature.
registerRobledoRoutesfunctionMounts robledo's two routes on a router.
RobledoRouterinterfaceThe router shape the routes need: get(path, handler).
RobledoHttpContextinterfaceThe part of an HTTP context the routes use.
errorsnamespaceThe package's errors, one class per code, see Errors

Robledo ​

The server signs nothing and holds no key: each update is checked on the phone against the key built into the app.

MemberSignatureDescription
constructornew Robledo(config?: RobledoConfig, resolvePath?: (path: string) => string)resolvePath resolves against the app's root. Throws E_ROBLEDO_INVALID_PREFIX for a bad prefix.
directoryreadonly directory: stringThe resolved directory of published updates.
prefixreadonly prefix: stringThe routes' prefix.
latestlatest(platform: string, runtime: string): Promise<LatestUpdate | null>The newest update published for this platform (android, ios) and runtime, or null.
filePathfilePath(platform: string, runtime: string, id: string, segments: readonly string[]): string | nullWhere a file of an update is on disk, or null for a path that is not one (unknown platform, malformed runtime or id, a segment leaving the update's files/).
registerRoutesregisterRoutes(): voidPuts the two routes on the router; call it from a preload so they exist before the server listens. Calling it again does nothing.
hasRegisteredRouteshasRegisteredRoutes(): booleanWhether registerRoutes ran.

The routes:

RouteAnswer
GET <prefix>/:platform/:runtime/latestThe newest update as JSON (cache-control: no-store), or 204 when there is none.
GET <prefix>/:platform/:runtime/:id/files/*One of its files, cached as immutable; 404 for a path that is not one.

registerRobledoRoutes ​

FunctionSignatureDescription
registerRobledoRoutesregisterRobledoRoutes(router: RobledoRouter, robledo: Robledo): voidMounts the routes on router directly, for a host that wires them itself.

@c9up/robledo/provider ​

ExportKindDescription
RobledoProviderprovider (default)register() binds the Robledo singleton from the robledo config; boot() gives it the router binding when there is one. It mounts no route itself.
RobledoAppContextinterfaceWhat the provider reads of the application: container, config, makePath.

@c9up/robledo/services/main ​

ExportKindDescription
defaultconstThe application's Robledo. Before the provider booted, any property access throws E_ROBLEDO_NOT_BOOTED.
ts
// start/routes.ts
import robledo from '@c9up/robledo/services/main'

robledo.registerRoutes()

@c9up/robledo/mobile ​

ExportKindDescription
checkForUpdatefunctionAsks the server for a newer update and stages it for the next start.
markReadyfunctionTells robledo the running update reached its first screen.
updateStatusfunctionWhat the native side knows: server, runtime, platform, current and pending update.
CheckResulttypeWhat checkForUpdate resolves to.
UpdateStatusinterfaceWhat updateStatus returns.
NativeRobledointerfaceThe native module, structurally: status(), verify(manifest, signature), receive(path, file), finish(), ready().
MAX_LATEST_BYTESconst1048576: the largest latest answer checkForUpdate reads.
PARALLEL_DOWNLOADSconst4: how many files checkForUpdate fetches at once.
NATIVE_MODULE_NAMEconst"NativeRobledo".
errorsnamespaceThe same namespace as @c9up/robledo's, see Errors
FunctionSignatureDescription
checkForUpdatecheckForUpdate(options?: { fetch?: Fetch }): Promise<CheckResult>Fetches <url>/<platform>/<runtime>/latest (at most MAX_LATEST_BYTES), and has the native side check the manifest first: its signature, runtime, platform, and that it is newer than every update this phone accepted. Only then does it download the files the manifest lists, PARALLEL_DOWNLOADS at a time, each refused as soon as it runs past its signed size, and hand each one to the native side as it arrives, which checks its digest. The update takes effect at the next start. fetch defaults to the global one.
markReadymarkReady(): voidKeeps the running update. An update that never calls it is abandoned at the start after, and the previous one runs again.
updateStatusupdateStatus(): UpdateStatusReads the native status.
ts
type CheckResult =
  | { kind: 'none' }
  | { kind: 'current'; id: string }
  | { kind: 'staged'; id: string }
UpdateStatus fieldTypeDescription
urlstringThe update server the app was built with.
runtimeVersionstringThe app's native runtime.
platformstringThe platform.
currentstring | nullThe update running now, or null for the bundle inside the app.
pendingstring | nullAn update staged for the next start.

Configuration ​

The robledo key, from config/robledo.ts or the config store.

OptionTypeDefaultDescription
directorystring'robledo'Where the published updates are, from the app's root.
prefixstring'/__robledo'The routes' prefix: starts with / and does not end with one.

The app side reads mobile.updates (url, publicKey) in reamrc.ts at build time; see the guide.

Container bindings ​

TokenResolves to
RobledoThe Robledo singleton.
'robledo'The same instance.

Errors ​

CodeRaised when
E_ROBLEDO_INVALID_PREFIXThe routes' prefix does not start with /, or ends with one.
E_ROBLEDO_NOT_BOOTED@c9up/robledo/services/main is used before the provider booted.
E_ROBLEDO_NO_NATIVE_MODULEThe app has no NativeRobledo module: it was not built with robledo installed.
E_ROBLEDO_BAD_RESPONSEThe server answered an update check, or a file download, with something other than an update.
E_ROBLEDO_REFUSEDThe phone refused the update: bad signature, altered file, wrong runtime, another app's update.
E_ROBLEDO_NOT_NEWERThe update is not newer than the newest this phone accepted, or than the bundle inside the app: an old update served again. Publish a rollback as a new update.

Migration ​

  • RobledoError is gone: test error.code, or error instanceof errors.E_ROBLEDO_* with import { errors } from '@c9up/robledo' (or from @c9up/robledo/mobile on the phone).
  • The RobledoErrorCode type is gone: error.code is a string.
  • A phone now refuses an update whose createdAt is not later than the newest it accepted (E_ROBLEDO_NOT_NEWER). To roll back, do not point latest back at an old update: publish the old code again with ream android:publish, which signs it as a new update.
  • checkForUpdate has the manifest's signature checked before it downloads anything, and refuses a file larger than its signed size or a latest answer over MAX_LATEST_BYTES (E_ROBLEDO_BAD_RESPONSE).
  • NativeRobledo has verify, receive and finish in place of stage: a test that fakes the native module implements those.
  • The phone also reads embeddedCreatedAt and appId from the ream-updates.json that ream android:build writes into the app. With embeddedCreatedAt, an update older than the bundle inside a store release is refused, so a store release is never replaced by an older update. With appId, an update signed for another app is refused (the signed manifest names its app). An app built before these fields existed has neither check: rebuild it, then publish its updates with the same version of the CLI.

See also ​