Sync Worker: deploy, connect and upgrade
Describes Hatoba 0.8.6.
The sync Worker is a small Cloudflare Worker with a D1 database. The app talks only to the Worker, and both hold ciphertext only. The Cloudflare free plan usually covers personal use. The wizard is on the Cloud Sync page (Cloud Sync). Step 2 (Connect) depends on the method chosen in step 1.
Method 1: Deploy a Worker from Hatoba
Hatoba creates the Worker and the D1 database in the user’s Cloudflare account through the Cloudflare API, with an API token it uses only during the deployment. The token stays in memory, is never saved, and is dropped when the wizard is left or the vault locks.
Other labels: The token needs two permissions, Database name.
-
Deploy with an API Token: the token needs two permissions, “Account · Workers Scripts · Edit” and “Account · D1 · Edit”. Create a token in Cloudflare opens the Cloudflare token form with both filled in. Limit Account Resources to one account and set a short expiry, or delete the token after deploying. Paste the token into API Token. Account ID (optional) is needed only for an account-owned token; for a normal token Hatoba finds the account itself (find the ID under Workers & Pages → Account Details). Then Continue.
-
Review the Deployment: choose the Cloudflare account if the token reaches several. If the account has no workers.dev subdomain yet, choose one under workers.dev subdomain (it becomes part of every Worker URL in the account). Worker and database names (expandable) default to
hatoba-syncandhatoba: lowercase letters, digits and hyphens for the Worker (up to 63 characters), plus underscores for the database (up to 60). The page lists what will be created or reused. Nothing changes in the account until Deploy. -
Deploy runs the steps with one progress row each:
- Check the token and account
- Look for an existing Worker and database
- Create the database
- Create the tables
- Upload the Worker
- Set the setup token
- Turn on the workers.dev URL
- Wait for the Worker to answer
A step with nothing to do shows not needed. The run ends with Sync Worker Deployed or Deployment Stopped.
-
When the Worker is live (Sync Worker Deployed), Continue goes to the master password step (Cloud Sync). Hatoba sets up the cloud vault itself and then deletes the Worker’s setup token secret.
Safety rules: Hatoba never overwrites a Worker that is not a Hatoba sync Worker, nor a Worker that already holds a vault, nor a database that holds other data (it picks a free name such as hatoba-2). Existing empty Hatoba pieces from an earlier attempt are reused.
If the Worker name already holds a vault (for example one deployed from another device), the review says so and the main button is Connect instead of Deploy: nothing is deployed, and the master password step joins this device to that vault (Cloud Sync, “Join a cloud vault”). To deploy a separate Worker instead, choose another name under Worker and database names. If that Worker has no workers.dev URL (the account has no subdomain, or the Worker is reachable only on a custom domain), Connect stays off: join it with Connect a deployed Worker and its URL instead.
If a step fails, the page shows the error:
- Retry continues from the step that failed. Remove what Hatoba created deletes only the Worker and database this deployment created; nothing that existed before is touched.
- A new workers.dev subdomain can take a few minutes before the Worker answers. The page then waits with Check again.
- Error texts for tokens, permissions and names are in Troubleshooting: Cloud Sync and Cloudflare.
Other labels: Back.
Method 2: Connect a deployed Worker
For a Worker the user deployed with the Deploy to Cloudflare button or with wrangler. The step is titled Deploy the Sync Worker.
- Deploy to Cloudflare (One-click deploy) opens Cloudflare in the browser, which creates the Worker and the D1 database. Or open Deploy manually with wrangler and run its commands in order in the repository’s
workers/syncfolder (npm install,npx wrangler d1 create hatoba,npx wrangler d1 migrations apply hatoba --remote,npx wrangler secret put SETUP_TOKEN,npx wrangler deploy). Full deployment guide opens the guide. - Enter the Worker URL (for example
https://hatoba-sync.<name>.workers.dev) and the Setup Token you set withwrangler secret put SETUP_TOKEN; it is used only for the first setup. Test Connection shows Connected with the Worker version and latency. - A Worker without a vault needs the Setup Token to continue. If it already has a vault, Test Connection says “Connected · the cloud already holds a vault”, no Setup Token is needed, and Continue leads to joining that vault (Cloud Sync, “Join a cloud vault”).
Method 3: Use an API Token (direct D1)
Titled Enter an API Token. Nothing is deployed; the app calls the D1 HTTP API directly.
Other labels: Choose a database.
- Enter the Account ID and an API Token that has only “Account · D1 · Edit”, then Verify Token. Pick the Database (it must already exist; create one first with
wrangler d1 create hatoba). Edit token in Cloudflare appears when the token lacks the D1 permission. A database that already holds a vault shows “This database already holds a vault. Continue to join it from this device.” - Such a token can usually edit every D1 database in the account. It is kept only in this device’s credential store. Prefer a Worker unless that is acceptable.
Upgrading the Worker
The app compares the Worker’s version with the one it carries whenever the Cloud Sync page opens and at sync time. The status page then shows one of:
- “A sync Worker update is available”: sync keeps working. Update Worker starts the upgrade; Dismiss hides the notice until the next Worker version.
- Worker update required: this version of Hatoba cannot sync with the old Worker. Sync pauses (local changes stay on the device and upload after the update) until the Worker is updated.
- Hatoba update required: the Worker is newer than this app supports. Update Hatoba (Check for updates opens Settings → About). Hatoba never replaces a newer Worker with an older one.
Other labels: Updating the Sync Worker, Sync Worker Updated, Update Stopped, Check the Worker and its database, Update the tables.
Update Worker opens Update the Sync Worker. Enter an API token with the same two permissions, an Account ID if asked, and the Worker name if the Worker uses a custom domain (otherwise it is the first part of its workers.dev URL). Continue, check Review the Update (it shows the table changes and the version change), then Update. Progress rows follow; Retry continues after a failure, and the Worker keeps working meanwhile. The cloud vault and its data are not touched.
If the Worker was deployed with the Deploy to Cloudflare button, Cloudflare redeploys it from the user’s repository on its next push, which undoes an in-app update. In that case update workers/sync in the repository by the Upgrade steps in the deployment guide.