Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby
10.9 KB
Raw Blame

Operating the FinanceKit device publisher

This guide covers Sure's server-side ingestion of FinanceKit uploads. It applies to foreground "Sync now" in alpha builds and to optional background delivery by the iOS client. Both use the same enrollment, upload, receipt, and repair protocol; background delivery is not required to begin alpha testing.

Sure's server-side worker and scheduled inbox sweep are required for either delivery mode. They apply accepted batches, retry processing, complete downstream account updates, and remove expired payload bytes. These server jobs are separate from the iOS app's ability to run in the background.

FinanceKit needs no server-side configuration to switch on. There is no feature flag and no family allowlist: any deployment running this code serves the publisher endpoints. Whether a build offers Wallet sync at all is decided in the iOS client through StoreKit, which the server cannot observe and does not try to.

What it does require:

  • an active family administrator to enroll, because a publisher writes into accounts the whole family reads. Every upload re-checks this, so a deactivated, demoted or reassigned enroller stops publishing; and
  • the scheduled FinancekitInboxJob sweep in addition to jobs enqueued when a batch arrives.

Nothing beyond admin gates it. The mapped accounts are further confined to those the enrolling user may write, so an admin cannot publish into an account they have no access to.

No Apple Wallet entitlement, private key, or FinanceKit framework is installed on the server. Sure never receives the user's Apple credentials. The iOS app obtains Wallet authorization directly from Apple and uploads only the accounts the user selected and consented to share.

Deployment

Deploy the migration, application, worker, and scheduler. The migration introduces publisher connections, stable account lineages, immutable batch receipts, source transaction identities, balance observations, and conflicts. The endpoints are live as soon as the application is, so treat the deploy itself as the enablement step and run the checks below before announcing it.

After deploy:

  1. Confirm the high-priority job queue and recurring scheduler are healthy.
  2. Enroll and activate a synthetic publisher over HTTPS, using a disposable test family.
  3. Upload sequences 2 then 1 and confirm the inbox applies them in order.
  4. Retry identical bytes and confirm the receipt is stable and no ledger row duplicates.
  5. Rotate the credential and confirm the prior credential cannot upload or call normal APIs.
  6. Replace the publisher and confirm the canonical account, source identities, and tombstones are reused.
  7. Induce a bad predecessor and confirm the connection enters repair_required; repair must create a new generation and stream.
  8. Confirm health reports device contact, acceptance, import, and downstream completion separately.
  9. Confirm applied, permanently failed, and revoked payload bytes are removed after seven days.

Monitor queue depth, oldest accepted batch age, repair_required connections, and downstream lag. Diagnostics may include publisher, batch, sequence, generation, and typed error codes. They must not include credentials, raw request bodies, transaction descriptions, merchant names, amounts, account names, or server authentication headers.

Transaction dates

posted_at is optional, including for booked Apple Card transactions. When supplied, it must still be a valid timestamp no later than the capture timestamp. Ledger dates retain their existing precedence: posted_at, otherwise the required transacted_at, converted into the mapped account's ledger timezone.

Wallet in settings

Bank sync lists Apple Wallet as a US / UK bank provider. Existing connections appear under Your Connections with sync status, acceptance and import timestamps, and links to accounts the viewer can access. Wallet accounts also appear in Accounts.

Accounts can be unlinked from the web UI. Because a publisher credential covers all selected Wallet accounts, unlinking one disconnects that Wallet connection and makes its accounts manual. This revokes the credential and queued uploads while preserving accounts, balances, transactions, and source identities. The iOS client can start a new enrollment with a new enrollment ID and map its Apple source account IDs again; existing accounts and imported transactions are reused without requiring the old connection or stream state.

Disconnect dispositions

DELETE /api/v1/financekit/connections/{id} takes an optional disposition query parameter saying what happens to the data the connection imported. The dispositions a build supports are advertised as connection_dispositions in the capabilities response, so a client feature-detects rather than hardcoding.

retain is the default and the behaviour above: the connection is revoked and every account, balance and transaction stays. The response is 204 No Content, unchanged for clients that send no disposition. The web unlink flow always retains — a person unlinking one account has not consented to delete the data in the others the connection covered.

discard revokes the connection and then removes what it imported. It answers 202 Accepted with the connection payload: a year of card history is not deleted inside a request, so the work runs in the background and the client polls the connection until purge_completed_at is set. Per Wallet account:

  • An account FinanceKit created is destroyed, with everything on it.
  • An account FinanceKit was linked to is emptied of entries sourced from FinanceKit and handed back to sync, which recomputes its balance from the history the family had before FinanceKit arrived. The account itself stays.
  • Source identities, balance observations and conflicts for that lineage are deleted, and the lineage is marked discarded so a later enrollment starts clean rather than reusing it.

Two consequences worth stating plainly. A discard removes imported entries even where the family later reconciled, excluded, split or edited them — a partial deletion would be worse than none, having told them the data was gone. And where an imported transaction had been matched into a transfer, the transfer record and its fees go with it; the transaction on the other account survives, unpaired.

An account lineage that another live connection still publishes into is left entirely alone, which is what happens during a device replacement window when two connections reference one lineage. The connection row itself survives as a revoked receipt; it holds no financial values, and its batch payloads were dropped at revocation.

Discard is irreversible, and the request outlives the job that carries it out: the intent is recorded on the connection, and the FinanceKit inbox sweep finishes any purge whose job was lost.

Debugging uploads

Super admins can open /settings/debug?provider_key=financekit and filter further by family, level, or source. Events share connection_id, publisher_id, generation, stream_id, and next_sequence. Accepted batches also include batch_id, capture_id, sequence/chunk information, payload size, and event count.

  • upload_accepted means Sure stored the upload; it does not mean ledger import has completed. An accepted sequence ahead of next_sequence is waiting for its predecessor; a multi-chunk capture waits for all its chunks.
  • upload_rejected records a typed protocol error and HTTP status when an authenticated upload fails validation. Identical accepted retries reuse their receipt without another acceptance log.
  • capture_imported records the resulting sync ID and counts, including records requiring conflict review.
  • import_retry includes the attempt count, retry deadline, error code, and exception class. import_failed means repair is required; import_blocked covers failures before a batch could be selected.
  • downstream_completed means account updates and rules were scheduled. downstream_failed includes the affected account/provider link when available; the inbox sweep retries this stage.

These diagnostics deliberately omit exception messages and financial payloads. Requests rejected before reaching the batch inbox (such as invalid publisher credentials or content type) do not create these model-level events.

Sample accounts

The standard demo account and transaction phases include a synthetic Apple Wallet connection with Apple Card (CreditCard), Apple Cash, and Nancy's Apple Cash (Depository, subtype cash). It includes a year of card purchases/payments and cash purchases/top-ups, plus pending activity, source identities, balance observations, and acceptance/import timestamps. Apple Cash receives a simulated 1% Daily Cash reward the day after each day's booked Apple Card purchases (excluding pending charges and payments), categorized as Cash Back. Six small gifts link the parent's Apple Cash to Nancy's account. Nancy spends some of each gift on candy, movies, after-school snacks, and ice cream: a few categorized purchases per month, with a positive running balance. These additions also populate older demo enrollments in place; stable source IDs prevent duplicate rewards, gifts, and purchases on reruns.

To add just these accounts to an existing demo family without replacing its data:

FAMILY_ID=<demo-family-uuid> bin/rails demo_data:financekit

Alternatively use DEMO_EMAIL=<demo-user-email> (defaults to the configured demo email). SEED=42 controls the generated amounts and merchants. Reruns preserve the existing demo enrollment and transactions, and upgrade older synthetic data with merchant-specific categories and paired transfers. Apple Card payments and Apple Cash top-ups come from the demo owner's manual Chase Premier Checking account; if absent, a funded Wallet Demo Checking account is created. Subsequent reruns preserve category edits and do not duplicate either transfer leg. Wallet demo data is included in every environment by both the full generator and sample-data reset flow. It does not change user permissions. These records simulate imported data; no iOS device is required.

Capacity and retention

Protocol 2 limits each publisher to 20 selected accounts, 500 events per batch, 1 MiB of JSON, and 100 accepted/processing batches. Each capture is limited to 100 chunks so the complete capture fits in the inbox. A client can upload larger histories using multiple consecutive captures.

Exact payload bytes are retained for seven days after apply, permanent failure, or revocation for response-loss recovery and operational investigation. Canonical financial data and source identity records follow Sure's normal family retention and deletion behavior, except where a client disconnects with disposition=discard (see Disconnect dispositions), which removes them for that connection. Family financial-data reset removes FinanceKit connections, lineages, observations, identities, conflicts, and batch receipts for that family.