Skip to content
Public template

About

TypeScript and Bun starter template for RentnerProxy apps.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

RentnerProxy app template (TypeScript)

Use this template or fork it to start a RentnerProxy app. Greeting is a small Bun backend with a packaged React UI. It saves one greeting per installation, follows the host theme and language, and asks the host to confirm a change. It also hooks into the platform's Proxy Hosts table: a Greeting column and a row action whose dialog the platform draws with its own components.

For CPU-heavy or memory-sensitive apps, app-template-rs offers the same app with a Rust backend and the same UI.

Run locally

Use AMD64 or ARM64 Linux, Bun 1.4.4, GNU tar and zstd.

bun install --frozen-lockfile --ignore-scripts
bun run dev
bun run check
bun run test
bun run build

Open the loopback URL printed by bun run dev. The local Platform stub starts the real backend with synthetic installation data and hosts the UI in an isolated iframe. Use the controls to switch theme, language or route, simulate readiness changes, or replace the iframe. The greeting survives a restart in .app-dev/data.

The stub also serves the core.sock platform API from the published contract: context, authorization checks, notifications, audit events, owned proxy host changes as durable operations, and the event stream. Operations it does not simulate answer 501 notImplemented. To give the app a database, set APP_DEV_DATABASE_URL to the superuser URL of a disposable PostgreSQL 18. The stub then provisions the database and runs the migrations like the platform. bun run test runs the database test when APP_TEST_DATABASE_URL points to such a server.

To see the UI drawn the way the platform draws installed apps, start a platform checkout's dev server with APP_UI_DEV_DIR set to this repository's absolute dist/dev-ui path and APP_UI_DEV_API set to the stub URL followed by dev/v1/platform-call, then open /dev/app-ui there as the owner. Choose UI bridge 1.3.0 and the keys greeting-read,greeting-write; the page surface shows the Greeting page, the host row dialog surface the row action for the proxy host UUID you enter. The preview forwards app operations to the stub with those keys, and the stub checks them against api/openapi.json like the platform does.

bun run build writes a .tar.zst development archive under dist/ with a synthetic source identity. GitHub CI builds the same package on both Linux architectures and attaches development archives with the tested repository ID and commit.

Adapt the app

  • Change the namespaced app ID, version, display metadata and requested permissions in app.config.json. The build validates it against @rentnerproxy/app-contracts.
  • Define app operations and their permissions in api/openapi.json. The example separates greeting-read and greeting-write. This document describes only the app's own operations; the platform protocol comes from the contract package. Its x-rentnerproxy-native-ui block lets the platform render the overview form and details table natively.
  • Implement operations in src/server/ and the static React UI in src/features/Greeting/. The UI requests operations through the typed MessageChannel bridge.
  • Extend platform surfaces in x-rentnerproxy-extensions of api/openapi.json. The example declares an app.page for the Greeting page, a proxyHosts.table.column answered by get-host-greetings with one cell per visible host, and a proxyHosts.table.rowAction that opens src/features/HostGreeting/. That dialog is drawn with @rentnerproxy/app-ui: the app renders UI kit elements in its hidden frame and the platform draws them as its own dialog, including the form draft, Save, Discard, Close and the unsaved-change lock. The host operations declare proxy.hosts.read.v1 access, so the platform checks each host and drops the cells of hosts a user may not see; the manifest requests that grant.
  • Every app operation carries an Idempotency-Key, and the platform may deliver the same request again, for example after a lost response. save-greeting sets an absolute value, so a repeat is harmless. An operation whose repeat would change state again, such as one that appends, counts or sends something, must store each key with its result in the same transaction as the change and answer a repeat with the stored result.
  • A repository created from this template does not inherit its labels. In a new RentnerProxy repository, copy the labels that .github/labeler.yml and Dependabot use before the first pull request: gh label clone RentnerProxy/app-template-ts --repo RentnerProxy/<repository>. Outside the RentnerProxy organization, the labeling, autofix and PR maintenance jobs are skipped.

Platform passes the bootstrap descriptor on stdin and authorizes access to the private app.sock and core.sock sockets. The backend verifies its own installation context with GET /platform/v1/context before it announces readiness. Greeting stores its greeting in its private working directory.

The requires ranges in app.config.json decide the protocol versions the app runs with. The platform negotiates the lower bound of each range, at most the version it implements, and tells the app exactly those versions in the bootstrap and the platform context. src/server/bootstrap.ts derives the same versions with negotiateVersions from the contract package, refuses any other and reports the negotiated appProtocol at readiness. Keep >=1.0.0 <2.0.0 to run on every platform of major 1. Raise a lower bound only when the app uses a feature of that protocol; platforms below it then refuse to install the app. The example requires uiBridge >=1.3.0 <2.0.0, because the platform draws the row action from UI kit elements from UI bridge 1.3.0 on; an app without UI kit elements can keep >=1.0.0.

src/server/platform-client.ts calls core.sock through the contract's typed request and response descriptors. Give every change an idempotency key from newIdempotencyKey() and reuse it for retries, also after a restart; the client repeats such calls itself when the platform is briefly unavailable. waitForOperation() polls durable operations, and followPlatformEvents() resumes the event stream from the last processed cursor and calls your resynchronization when the cursor expired (410). A PlatformApiError with staleGeneration (412, or a rejected credential or generation) means a newer generation replaced this process: stop background work instead of retrying.

Data and migrations

The platform provisions a PostgreSQL database for apps that declare data. It runs the declared migrations/**.sql steps in one transaction as a separate schema owner and records the reached version. Steps must be plain SQL without transaction control or psql commands. Version 0 means a new installation; each step leads from fromVersion to the target. The example targets version 2 from both 0 and 1, because Greeting 1.0 kept version 1 in files only. Bump targetVersion, readVersions and writeVersions together and add a step for every version that installations may have.

At runtime, openAppDatabase() in src/server/database.ts connects with Bun's SQL client as the runtime role from RENTNERPROXY_APP_DATABASE_URL_FILE. That role may only read and change rows in the app schema, such as the example table app.greeting_history.

Package and submit

The build produces bin/app, a generated app.json with target and source identity, api/openapi.json, ui/ assets, migrations/, and LICENSE. The Marketplace candidate build uses the same bun run build entrypoint and supplies APP_PACKAGE_DIR, APP_TARGET, APP_SOURCE_REPOSITORY_ID and APP_SOURCE_COMMIT.

Push the intended revision to a public GitHub repository. Submit its owner/repo and the full commit SHA from git rev-parse HEAD, along with the app ID, version, and targets. Marketplace builds the submitted source in isolation. Its approval and signed catalog workflow uses the exact approved package digests. Version submissions · Signed catalog

About

TypeScript and Bun starter template for RentnerProxy apps.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages