qube_rails 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +321 -0
  3. data/README.md +406 -76
  4. data/app/assets/javascripts/qube_rails/question.js +469 -43
  5. data/app/assets/stylesheets/qube_rails.css +1349 -912
  6. data/app/controllers/qube_rails/connections_controller.rb +42 -9
  7. data/app/controllers/qube_rails/questions_controller.rb +39 -7
  8. data/app/controllers/qube_rails/runs_controller.rb +4 -3
  9. data/app/controllers/qube_rails/storyboard_controller.rb +1 -1
  10. data/app/models/qube_rails/connection.rb +131 -9
  11. data/app/models/qube_rails/quickbooks_record.rb +22 -0
  12. data/app/models/qube_rails/run.rb +28 -10
  13. data/app/views/qube_rails/_error.html.erb +2 -2
  14. data/app/views/qube_rails/_manage_connection.html.erb +19 -0
  15. data/app/views/qube_rails/_question.html.erb +4 -1
  16. data/app/views/qube_rails/question/_choice.html.erb +34 -11
  17. data/app/views/qube_rails/question/_disclosure.html.erb +7 -0
  18. data/app/views/qube_rails/question/_exit_button.html.erb +8 -0
  19. data/app/views/qube_rails/question/_field.html.erb +4 -3
  20. data/app/views/qube_rails/question/_footer.html.erb +12 -4
  21. data/app/views/qube_rails/question/_inline_search.html.erb +12 -0
  22. data/app/views/qube_rails/question/_pick.html.erb +29 -6
  23. data/app/views/qube_rails/question/_picks.html.erb +2 -1
  24. data/app/views/qube_rails/question/_question.html.erb +31 -7
  25. data/app/views/qube_rails/question/_submit.html.erb +9 -0
  26. data/app/views/qube_rails/question/fields/_boolean.html.erb +2 -2
  27. data/app/views/qube_rails/question/fields/_number.html.erb +2 -2
  28. data/app/views/qube_rails/question/fields/_rows.html.erb +17 -4
  29. data/app/views/qube_rails/question/fields/_search.html.erb +6 -3
  30. data/app/views/qube_rails/question/fields/_select.html.erb +6 -5
  31. data/app/views/qube_rails/question/fields/_text.html.erb +2 -2
  32. data/app/views/qube_rails/question/rows/_segmented.html.erb +3 -1
  33. data/app/views/qube_rails/run_status/_detail.html.erb +5 -1
  34. data/app/views/qube_rails/run_status/_status.html.erb +5 -2
  35. data/app/views/qube_rails/storyboard/show.html.erb +4 -3
  36. data/config/locales/en.yml +30 -1
  37. data/config/routes.rb +2 -0
  38. data/db/migrate/20261031000000_add_qube_connection_type_and_run_headline.rb +12 -0
  39. data/db/migrate/20261124000000_add_qube_company_file_change.rb +17 -0
  40. data/lib/generators/qube_rails/templates/connection_events.rb.tt +17 -1
  41. data/lib/generators/qube_rails/templates/initializer.rb.tt +12 -4
  42. data/lib/qube_rails/configuration.rb +5 -2
  43. data/lib/qube_rails/connection_events.rb +70 -7
  44. data/lib/qube_rails/engine.rb +1 -0
  45. data/lib/qube_rails/link_check.rb +274 -0
  46. data/lib/qube_rails/operation.rb +116 -32
  47. data/lib/qube_rails/question_view.rb +293 -35
  48. data/lib/qube_rails/request.rb +2 -0
  49. data/lib/qube_rails/rows_view.rb +18 -5
  50. data/lib/qube_rails/run_status_view.rb +12 -7
  51. data/lib/qube_rails/storyboard/ask_about_add.json +9 -11
  52. data/lib/qube_rails/storyboard/choose.json +10 -7
  53. data/lib/qube_rails/storyboard/enum_select.json +5 -4
  54. data/lib/qube_rails/storyboard/missing_record.json +11 -14
  55. data/lib/qube_rails/storyboard/name_clash.json +51 -21
  56. data/lib/qube_rails/storyboard/near_match.json +18 -15
  57. data/lib/qube_rails/storyboard/number_boolean.json +5 -4
  58. data/lib/qube_rails/storyboard/record_search.json +15 -16
  59. data/lib/qube_rails/storyboard/refusal.json +15 -18
  60. data/lib/qube_rails/storyboard/rows.json +45 -31
  61. data/lib/qube_rails/storyboard.rb +28 -7
  62. data/lib/qube_rails/sync_status.rb +16 -3
  63. data/lib/qube_rails/version.rb +1 -1
  64. data/lib/qube_rails/view_helpers.rb +4 -2
  65. data/lib/qube_rails.rb +11 -2
  66. metadata +10 -2
data/README.md CHANGED
@@ -52,8 +52,9 @@ Relative to where the engine is mounted (`"/"` above):
52
52
 
53
53
  | Route | What it does |
54
54
  | --- | --- |
55
- | `POST quickbooks/connections` | Connect, for the signed-in account (`current_account`). Sends its newest connection that has never connected (`pending` or `setup_cancelled`) back through setup, so clicking Connect again doesn't pile up connections. Makes a new one (the row, then QuBe Sync's connection with the row's webhook URL and `config.connection_type`, `"realtime"` by default since workflows run only on realtime connections, then its `qube_id`, with an optional `name`) when the account has none, or with `new=1`. Redirects (303) to the setup. With `simulated=1`, outside production, it makes a new connection to a simulated QuickBooks company file instead, connected as it's made, and redirects back: for testing with no Windows computer. In production that answers 404. |
55
+ | `POST quickbooks/connections` | Connect, for the signed-in account (`current_account`). Sends its newest connection that isn't connected yet (`pending`, a connection set up again after a company file change included, or `setup_cancelled`) back through setup, so clicking Connect again doesn't pile up connections. Makes a new one (the row, then QuBe Sync's connection with the row's webhook URL and its type, then its `qube_id`, with an optional `name`) when the account has none of that type, or with `new=1`. The type is the `type` param, `realtime` or `standard`, else `config.connection_type` (`"realtime"` by default, since workflows run only on realtime connections); any other `type` answers 422. The row keeps it as `connection_type`. Redirects (303) to the setup. With `simulated=1`, outside production, it makes a new connection to a simulated QuickBooks company file instead, connected as it's made, and redirects back: for testing with no Windows computer. In production that answers 404. |
56
56
  | `POST quickbooks/connections/:id/onboarding` | One of the signed-in account's connections, back through setup, with its webhook URL brought up to date (or made at QuBe Sync, for a row QuBe Sync never answered). Another account's connection answers 404. |
57
+ | `POST quickbooks/connections/:id/company_file` | "Use a different company file" for one of the signed-in account's connections: its webhook URL brought up to date, its links renewed (`POST /api/v2/connections/:id/onboarding-url`), and a redirect (303) to its `links.company_file`, QuBe Sync's page for switching it to another company file (its onboarding link if QuBe Sync gives none). A simulated connection, one QuBe Sync never answered, or another account's answers 404. |
57
58
  | `DELETE quickbooks/connections/:id` | Disconnects one of the signed-in account's connections: QuBe Sync deletes its connection (already gone counts), then the row goes, with its runs, requests and QuickBooks links. Refused while a run or request hasn't ended; another account's connection answers 404. Show its message with `render "qube_rails/error"`. |
58
59
  | `POST webhooks/qube/runs/:id` | A run's webhooks. |
59
60
  | `POST webhooks/qube/connections/:id` | A connection's webhooks. |
@@ -61,7 +62,7 @@ Relative to where the engine is mounted (`"/"` above):
61
62
  | `POST qube/questions/runs/:id` | Your user's answer to the run's question, from the partial. Behind your sign-in and CSRF. |
62
63
  | `GET qube/questions/runs/:id/search` | A record field's matches, as JSON. Behind your sign-in. |
63
64
  | `POST qube/runs/:id/redeliver` | A run that looks stuck (`Run#looks_stuck?`: confirmed, not ended, and quiet for 10 minutes while running or waiting on a question this app never got): asks QuBe Sync to send its latest event again, from the run status partial's "Check for updates" button. Behind your sign-in and CSRF, and `authorize_question`. |
64
- | `POST qube/runs/:id/retry_start` | A start QuBe Sync never confirmed, sent again with the same reference, from the run status partial. Behind your sign-in and CSRF, and `authorize_question`. |
65
+ | `POST qube/runs/:id/retry_start` | A start QuBe Sync never confirmed, or one refused as `realtime_required`, sent again with the same reference, from the run status partial. Behind your sign-in and CSRF, and `authorize_question`. |
65
66
  | `GET qube/storyboard`, `GET qube/storyboard/:screen` | Every screen the partials show, from sample data, in your layout ([Styling](#styling)). Only while `config.storyboard` is true (404 otherwise); behind your sign-in. Its search (`GET qube/storyboard/:screen/search`) answers from the samples and its forms post to a no-op (`POST qube/storyboard/:screen/answer`): nothing reaches QuBe Sync or the database. |
66
67
 
67
68
  The webhook routes verify the signature (401 if it doesn't check out), answer 404 when the row
@@ -72,7 +73,8 @@ connection id against the row (a request's event, its id).
72
73
  Onboarding and the question routes inherit your `ApplicationController` (the `parent_controller`
73
74
  setting), so its sign-in and CSRF protection apply. Your views reach the routes through the
74
75
  engine's proxy: `qube_rails.connections_path`, `qube_rails.connection_onboarding_path(connection)`,
75
- `qube_rails.connection_path(connection)` (with `method: :delete`).
76
+ `qube_rails.connection_company_file_path(connection)`, `qube_rails.connection_path(connection)`
77
+ (with `method: :delete`).
76
78
 
77
79
  Two buttons cover it: Connect, for an account setting up its first company file (or finishing a
78
80
  setup it started), and, once it has one, Connect another company file:
@@ -92,6 +94,20 @@ Connect redirects to QuBe Sync's setup, on another site, so its forms need `data
92
94
  in an app with Turbo (Rails 7 and later): Turbo submits a form with `fetch`, which the browser
93
95
  won't follow to another origin, and the button would do nothing.
94
96
 
97
+ Once a connection is set up, keep its setup within your customer's reach: they need it when
98
+ QuickBooks moves to another computer, the Web Connector entry is removed, or they want this
99
+ connection on another company file. On the page that shows its QuickBooks status:
100
+
101
+ ```erb
102
+ <%= render "qube_rails/manage_connection", connection: connection %>
103
+ ```
104
+
105
+ It shows "Set up QuickBooks again" (`connection_onboarding_path`) and, unless the connection is
106
+ simulated, "Use a different company file" (`connection_company_file_path`), both with Turbo off,
107
+ while the connection is connected or stalled (`Connection#set_up?`), and nothing otherwise: offer
108
+ Connect then. Both links carry the onboarding token and expire with it, so each button renews
109
+ them when clicked rather than keeping one.
110
+
95
111
  ## Settings
96
112
 
97
113
  In `config/initializers/qube_rails.rb`, the only place the engine reads your app from:
@@ -112,10 +128,11 @@ end
112
128
  | `authorize_question` | `->(controller, record, run) { true }` when the signed-in user may answer or search that run's question. The run carries its `operation` and its `connection` (whose `owner` connected it). Only `true` allows; anything else answers 404 (search: `[]` with 404), as for a missing run, and is logged. | allows only when `current_account` owns the run's connection (compared by type and id, so a nil or unsaved account never matches) |
113
129
  | `enqueue` | `->(delivery) { ... }`, handing `{ kind:, id:, body: }` (kind `"run"` or `"connection"`) to a queue | ActiveJob: `QubeRails::WebhookJob` on `queue` |
114
130
  | `queue` | the ActiveJob queue | `:default` |
131
+ | `connection_type` | the type Connect makes connections as: `"realtime"` (workflows run only on these) or `"standard"` (for an app that only queues requests); anything else raises `ArgumentError`. Connect's `type` param overrides it per click. | `"realtime"` |
115
132
  | `job_attempts` | how many times `QubeRails::WebhookJob` runs a delivery whose work raised, with a growing wait, before it logs an error and raises to your adapter (read when the job class loads) | `10` |
116
133
  | `dedupe` | where each run's taken notification delivery ids are kept: `once(run, delivery_id) { }`, or `seen?(key)` / `remember(key)` | `QubeRails::DatabaseDedupe`: the engine's `qube_notifications` table, in the handler's transaction |
117
134
  | `parent_controller` | the controller onboarding and the questions inherit | `"ApplicationController"` |
118
- | `ui_classes` | your CSS classes for the engine's screens, by piece (`{ button: "btn btn-primary" }`), added beside the `qube-` classes ([Styling](#styling)); an unknown piece raises, naming them | `{}` |
135
+ | `ui_classes` | your CSS classes for the engine's screens, by piece (`{ button: "rounded-md bg-indigo-600 px-3 py-2 text-white" }`), added beside the `qube-` classes ([Styling](#styling)); an unknown piece raises, naming them | `{}` |
119
136
  | `storyboard` | whether `GET qube/storyboard` shows every screen with sample data | `Rails.env.development?` |
120
137
  | `api_key` | | `QUBE_API_KEY` |
121
138
  | `base_url` | | `QUBE_URL`, else `https://qubesync.com` |
@@ -208,10 +225,15 @@ dropped ...") and returns.
208
225
 
209
226
  A `QubeRails::Connection` is one company file: `owner` (your account), `qube_id` (QuBe Sync's
210
227
  id, nil until it answers), `name`, `status` (`pending`, `connected`, `setup_cancelled`,
211
- `stalled`), `stall_reason` and `revision`. `QubeRails::Connection.owned_by(account)` lists an
212
- account's.
228
+ `stalled`), `stall_reason`, `revision`, `connection_type` (`realtime`, `standard` or
229
+ `simulated`), `company_file_changed_at` (when the customer last switched it to another
230
+ company file) and `company_file_revision` (that switch's event revision). `QubeRails::Connection.owned_by(account)` lists an account's.
231
+
232
+ A connection's type can't be changed through the API: the customer upgrades a standard one to
233
+ realtime from its page in the QuBe Sync dashboard. Its next event carries the new type, and
234
+ `connection.refresh_type!` reads it at once (`GET /api/v2/connections/:id`).
213
235
 
214
- Its own events (QUBE_WEBHOOK_URL/connections/<id>) update `status`, `stall_reason` and `revision`
236
+ Its own events (QUBE_WEBHOOK_URL/connections/<id>) update `status`, `stall_reason`, `connection_type` and `revision`
215
237
  when the event is for that connection (`qube_id`) and newer than the last one applied, under the
216
238
  row's lock. Then your class runs, with `connection` and `owner`.
217
239
 
@@ -231,6 +253,109 @@ So a row id used again (MySQL 5.7 after a restart, a restored database) never ta
231
253
  connection. The unpaged listing is acceptable because it only runs for a row without an id,
232
254
  which is rare: a lost create, or an event that beat the save.
233
255
 
256
+ `connection.company_file_changed` comes when the customer chooses "Use a different company file"
257
+ on the connection's setup page. The connection id stays the same, and every ListID, TxnID and
258
+ EditSequence stored for it is the old file's. The "new" file is often the same company (renamed,
259
+ moved, restored from a backup, copied to a new server) and keeps its ids, so they aren't thrown
260
+ away: they're checked. In the same transaction as the status and revision, the engine:
261
+
262
+ - sets `status` back to `pending` (it is set up again, so the Web Connector is installed again
263
+ from the setup page; `connection.connected` follows when it checks in) and clears
264
+ `stall_reason`;
265
+ - marks the connection's `qube_quickbooks_records` rows stale (`stale_since`). A stale link is
266
+ kept but never used: `qb_id_for`, `find_linked`, `quickbooks_record`, `in_quickbooks` and
267
+ `sync_status` don't see it, so `quickbooks_ref` refers to the record by name and no request goes
268
+ out with an old id (`connection.stale_links` lists them);
269
+ - deletes its sync marks, so the next sync's `last_synced_at` is nil;
270
+ - sets `company_file_changed_at`: a run from before it no longer counts for `sync_status`, so a
271
+ record sent to the old file reads `:not_sent` until its link is checked, and a check queued
272
+ before it settles nothing (its answer may be the old file's) and is asked again;
273
+ - sets `company_file_revision` to the event's revision.
274
+
275
+ Events can arrive out of order. A `connection.company_file_changed` that comes after a later event
276
+ (a retried delivery landing after `connection.connected`) still forgets the old file when its
277
+ revision is newer than `company_file_revision`: the links go stale and are checked, and your
278
+ `company_file_changed` hook runs (so you set aside ids you keep yourself), but `status` and
279
+ `revision` are left alone. A redelivery of one already applied does nothing.
280
+
281
+ Then your `company_file_changed(event)` runs (by default it logs). Set aside any QuickBooks ids
282
+ your app keeps itself for that connection, and tell the customer to finish the setup.
283
+
284
+ When `connection.connected` comes, the engine checks the stale links against the file the
285
+ connection opens now (`QubeRails::LinkCheck`): a plain request per kind (`customer.query`,
286
+ `invoice.query`...) asking for up to 50 of its ids at once, by ListID, or by TxnID for a
287
+ transaction, and the next 50 when that answer is in. Which id a kind's query takes comes from the
288
+ qube_sync gem (`Operations::INDEX`'s `id_param`), or from the engine's own lists on an older gem;
289
+ a kind that can't be looked up by id (company, preferences, a kind your app named itself) is never
290
+ queried: its links are kept as missing (below) as soon as the check starts, and reported in
291
+ `links_checked` like a checked batch. For each id:
292
+
293
+ - found with the same name (a list record's FullName, a transaction's RefNumber, compared
294
+ ignoring case and spacing; blank and blank are the same): the link is kept, current again, with
295
+ the answer's EditSequence. A link kept without a name (`name: nil`) is kept on its id alone;
296
+ - found under another name: the link is held for review (`review_since`, and `review_name`, the
297
+ name QuickBooks has now; `connection.review_links`), unused, and its record waits (below) until
298
+ your app settles it;
299
+ - not found: the link is kept as missing (`missing_since`, `connection.missing_links`), unused
300
+ like a stale one, so the record reads as not in QuickBooks and is matched by name (or asks your
301
+ user) when it's next sent. The next company file change makes it stale again and checks it,
302
+ so a customer who picked the wrong file and switches back gets their links back.
303
+
304
+ Why a found id isn't enough: QuickBooks stamps every ListID and TxnID with its record's creation
305
+ time (`<hex counter>-<TimeCreated as unix seconds>`, checked on QuickBooks Enterprise 24 for
306
+ customers, items, accounts and invoices), so two files sharing an id share an origin: one was
307
+ copied or restored from the other. After a copy the files go their own ways, and people reuse a
308
+ record by renaming it, so an id found under another name may be another record now. Your
309
+ customer decides:
310
+
311
+ ```ruby
312
+ connection.review_links.each do |link|
313
+ # Ask: is link.record (kept as link.name) the record QuickBooks now calls link.review_name?
314
+ end
315
+ connection.confirm_link(link) # yes: current again, with QuickBooks' name
316
+ connection.reject_link(link) # no: missing, so the record is matched by name or added when sent
317
+ ```
318
+
319
+ Until a record's link is settled (current, missing, or replaced by a run), nothing is sent for it:
320
+ `Operation.start` and `Request.queue` raise `QubeRails::LinkBeingChecked` while it's being checked
321
+ and `QubeRails::LinkNeedsReview` while it waits for review (both `NotReady`), so retry them from a
322
+ job. A record with no link goes as before. The next company file change makes stale again every
323
+ link, under review and missing ones too, and checks them all.
324
+
325
+ QuickBooks answers a query by id with a 500 warning when an id isn't there, naming only the
326
+ first missing one, and still returns every id it has, so an id the answer leaves out is missing. An answer the engine can't trust (a row it didn't ask for, an odd shape) settles
327
+ nothing, and is logged. A check is safe to run twice: it asks only about links still stale, a
328
+ delivery is taken once, and a second `connected` while a check is going reuses it. A run that
329
+ links a record on the new file makes its link current at once. A link whose check fails (or
330
+ whose answer can't be trusted, or whose queue or next batch couldn't be sent) stays stale. It's
331
+ asked about again on the connection's next event, by `connection.check_stale_links`, or when your
332
+ app sends one of its records: before raising `LinkBeingChecked`, `Operation.start` and
333
+ `Request.queue` queue the kind's check again if its last one ended (or never got an answer) more
334
+ than `LinkCheck::RETRY_AFTER` (5 minutes) ago.
335
+
336
+ After each batch, `links_checked(kind:, found:, relinked:, review:, missing:, stale_left:)` runs on
337
+ your class (by default it logs). `relinked` and `missing` are the links (`link.record` is your
338
+ record); `review` is `{ link:, record:, old_name:, new_name: }` for each link held for review;
339
+ `stale_left` is 0 once every check is done. Tell the customer what was found again, and ask about
340
+ the ones to review. Two things to watch:
341
+
342
+ - When most found ids of a kind are under review, the new file is a copy that has drifted a long
343
+ way from the old one: warn the customer before they confirm links one by one.
344
+ - A missing transaction needs your user's review before it's sent again: a RefNumber is often
345
+ blank or shared, so no name match will find it, and sending it adds it again.
346
+
347
+ A restored backup is the common case. Records edited after the backup are relinked in their
348
+ older state, so send again what changed since the backup; records created after it aren't
349
+ found and are added again when next sent, which is right for a restore.
350
+
351
+ Match records by name before adding them (a workflow such as `add_transaction` finds or asks
352
+ before it creates), and send past transactions only for a range your customer picks. QuBe Sync
353
+ fails the connection's waiting requests and cancels its live runs, each with its own webhook:
354
+ build that work again from your records after `connection.connected`, never resend it as it was.
355
+
356
+ A connection set up again is `pending`, so Connect sends it back through setup rather than making
357
+ another.
358
+
234
359
  ```ruby
235
360
  module QuickbooksDesktop
236
361
  class ConnectionEvents < QubeRails::ConnectionEvents
@@ -253,6 +378,17 @@ module QuickbooksDesktop
253
378
  def resumed(event)
254
379
  log_event(event)
255
380
  end
381
+
382
+ # Its QuickBooks links are stale until they're checked: set your own ids aside too, and ask
383
+ # them to finish the setup.
384
+ def company_file_changed(event)
385
+ AccountMailer.quickbooks_finish_setup(owner, connection).deliver_later
386
+ end
387
+
388
+ # A batch of its stale links was looked up on the new file; stale_left is 0 once all are.
389
+ def links_checked(kind:, found:, relinked:, review:, missing:, stale_left:)
390
+ AccountMailer.quickbooks_links_checked(owner, connection, kind, review, missing).deliver_later
391
+ end
256
392
  end
257
393
  end
258
394
  ```
@@ -264,7 +400,9 @@ QuickBooks gives out ListIDs from one counter per family, so an id is unique onl
264
400
  family of one company file (verified on QuickBooks Enterprise 24.0): customers, vendors,
265
401
  employees and other names share one, every item type shares another, each other list (accounts,
266
402
  classes, terms...) has its own, and the same counter value turns up in several families.
267
- TxnIDs are kept per transaction type.
403
+ TxnIDs are kept per transaction type. Pass `name:` (a list record's FullName, a transaction's
404
+ RefNumber): after a company file change a found id is kept only when it still has that name.
405
+ Only current links are read; stale, missing and under-review ones aren't.
268
406
 
269
407
  ```ruby
270
408
  connection.link(customer, kind: "customer", qb_id: list_id, edit_sequence: "171", name: "Riverbend Electric")
@@ -314,18 +452,21 @@ module QuickbooksDesktop
314
452
  })
315
453
  end
316
454
 
317
- # How the run ended: event.outcome says which, event.output holds the result. Keep the
318
- # QuickBooks ids it carries on the connection.
319
- def ended(event)
320
- # The records the add named, found or made, by the input's path: linked, so the next run
321
- # refers to them by id. A cancelled ending can carry some too.
322
- link_references(event) do |path, _entry|
323
- if path == "customer_ref"
324
- record.customer
325
- elsif (line = path[/\Ainvoice_line_add\.(\d+)\.item_ref\z/, 1])
326
- record.lines[line.to_i]&.item
327
- end
455
+ # Which of your records each QuickBooks record links to, by where the input named it.
456
+ def linked_record(path, _entry)
457
+ if path == "customer_ref"
458
+ record.customer
459
+ elsif (line = path[/\Ainvoice_line_add\.(\d+)\.item_ref\z/, 1])
460
+ record.lines[line.to_i]&.item
328
461
  end
462
+ end
463
+
464
+ # How the run ended: event.outcome says which, and event.output has that outcome's own keys
465
+ # (add_transaction's added: record and links). Keep the QuickBooks ids on the connection.
466
+ def ended(event)
467
+ # Every record the add named, by the input's path (output.refs), linked so the next run
468
+ # refers to it by id. A cancelled ending carries the ones settled before it stopped.
469
+ link_references(event) { |path, entry| linked_record(path, entry) }
329
470
  return unless event.outcome == "added"
330
471
 
331
472
  txn = event.dig("output", "record") || {}
@@ -339,8 +480,10 @@ module QuickbooksDesktop
339
480
  record.update!(status: "failed")
340
481
  end
341
482
 
342
- # What a running workflow sends along (a sync's pages): taken once per delivery_id.
483
+ # What a running workflow sends along, taken once per delivery_id: add_transaction's
484
+ # "records" (what each pass settled, linked as it comes, before the ending), a sync's pages.
343
485
  def notification(event)
486
+ link_references(event) { |path, entry| linked_record(path, entry) } if event.name == "records"
344
487
  log_event(event)
345
488
  end
346
489
 
@@ -362,6 +505,15 @@ A start can fail two ways, and they're handled differently:
362
505
 
363
506
  - **Refused** (QuBe Sync answered 4xx: bad input, a workflow that isn't published) or an input that
364
507
  raised: nothing was started. The row is marked `failed` and the error raised; start again.
508
+ - **Not realtime**: workflows run on realtime connections (and simulated ones). On a row whose
509
+ `connection_type` is `standard`, `start` raises `QubeRails::RealtimeRequired` before writing a
510
+ run or calling QuBe Sync. When QuBe Sync refuses the start for it anyway (a `422` whose
511
+ `errors.code` is `realtime_required`: the connection was downgraded in the dashboard), the row
512
+ is kept as `realtime_required`, not `failed`, with `error` `{"code", "detail"}`, and
513
+ `RealtimeRequired` is raised with the detail. QuBe Sync stores nothing for that refusal, the
514
+ `Idempotency-Key` included, so once the customer upgrades the connection from its page in the
515
+ QuBe Sync dashboard, `run.retry_start!` (or `start` again, which returns that run) starts it with
516
+ the same reference.
365
517
  - **No answer** (a timeout, a 5xx, a dropped connection): the run may have started. The row stays
366
518
  `starting`, with its reference and input, and the error is raised. Send it again with
367
519
  `run.retry_start!` (or `QuickbooksDesktop::CreateInvoice.retry_start(run)`), never with a new
@@ -381,7 +533,8 @@ the first call started, as it is now, plus `Idempotent-Replayed: true`, and star
381
533
  same key with a different call is a `422`; a refused call (`400`, `403`, `404`, `422`) stores no
382
534
  key, so retrying it runs the checks again. A key lives as long as its run: finished runs are
383
535
  purged 60 days after they end. `retry_start!` returns a run that already has its `qube_run_id`
384
- as it is, and refuses one that `failed`. (The gem's client also resends a start that got no
536
+ as it is, and refuses one that `failed`; one that's `realtime_required` it sends again, unless its
537
+ connection's row still says `standard` (it raises `RealtimeRequired` without calling QuBe Sync). (The gem's client also resends a start that got no
385
538
  answer twice itself, within 60 seconds, with the same key.)
386
539
 
387
540
  A `QubeRails::Run` keeps `operation`, `record`, `connection`, `reference`, `revision`, `state`,
@@ -421,7 +574,8 @@ module QuickbooksDesktop
421
574
  # error or discarded: show event.error["user_message"].
422
575
  def failed(event); end
423
576
 
424
- # QuBe Sync keeps trying (QuickBooks closed, a dialog open). Never resend. Default: logs.
577
+ # QuBe Sync keeps trying (QuickBooks closed, a dialog open, another company file open). Show
578
+ # event.error["user_message"]. Never resend. Default: logs.
425
579
  def retrying(event); end
426
580
 
427
581
  # The answer never came back: QuickBooks may have applied it. Default: failed(event). A query
@@ -499,21 +653,36 @@ QuBe Sync still checks every start: a field the operation doesn't take is a 422
499
653
  ## Run status
500
654
 
501
655
  The engine keeps every ending on the run row before your handler runs, under the same lock:
502
- `state`, `outcome`, a failure's `error` (as the event carried it: a sentence, or its code,
503
- message and detail), a cancel's `cancel_reason`, and `ended_at`. So a run's result is there
656
+ `state`, `outcome`, a failure's `error` (as the event carried it: `{code, type, message,
657
+ quickbooks_message, hint}`, where `code` is QuickBooks' status code and `type` a stable name to
658
+ branch on; a run from before QuBe Sync sent that object keeps its sentence, or its code, message and
659
+ detail), a cancel's `cancel_reason`, and `ended_at`. Every event's `headline`, one plain sentence
660
+ for a person ("Added the transaction to QuickBooks as TxnID 1F2-1."), is kept as `run.headline`:
661
+ show it, never parse it. Branch on `event`, `outcome`, `output` and `error`. So a run's result is there
504
662
  whether or not your `ended` and `failed` handlers write anything; those are for your own records.
505
663
  `run.ended?`, `run.failed?` and `run.cancelled?` say which (a run that completed on a
506
664
  `cancelled` outcome, where your app chose to stop, counts as cancelled), and `run.summary_text`
507
- says it in a sentence for your user: "Added to QuickBooks", "Done", "Couldn't sync",
665
+ says it in a sentence for your user: "Added to QuickBooks", "Done", "Done, but some didn't go
666
+ through" (an outcome such as `push_records`' `pushed_with_errors`: `run.with_errors?`), "Couldn't sync",
508
667
  "Cancelled", "Needs your answer", "Sending to QuickBooks", "Still waiting for QuickBooks"
509
668
  or "Syncing with QuickBooks" (the words are I18n's: see [Wording and translations](#wording-and-translations)). `run.reason_text` says why it failed or was cancelled, as a sentence (the error's message, or
510
- the reason your app gave), and nil otherwise.
669
+ the reason your app gave), and nil otherwise; `run.error_detail` is the error's `hint`, what
670
+ usually fixes it.
671
+
672
+ A run's links work only while they apply: `links.cancel` until it ends (the row's `cancel_url` is
673
+ cleared then), and `links.decisions` and `links.search` while it asks (the row's `links`, cleared
674
+ when it stops asking; `search` only when the question has a record field). Read them from the row,
675
+ and expect nil.
676
+
677
+ A start refused as `realtime_required` reads QuBe Sync's detail (how to upgrade the connection)
678
+ as its summary, has sync status `:failed`, and gets the same "Try sending again" button, for once
679
+ the connection is upgraded.
511
680
 
512
681
  A start QuBe Sync hasn't confirmed for a minute (`run.unconfirmed?`: still `starting`, after a
513
682
  start that got no answer) reads "Still waiting for QuickBooks", and the partial offers a "Try
514
683
  sending again" button. It posts to `POST qube/runs/:id/retry_start`, behind your sign-in and
515
684
  CSRF, which runs the same `authorize_question` policy as the questions (404 otherwise), answers
516
- 409 for a run that isn't `starting`, calls `run.retry_start!` (same reference, so a start that did
685
+ 409 for a run that isn't `starting` (or `realtime_required`), calls `run.retry_start!` (same reference, so a start that did
517
686
  land answers with its run) and redirects back with 303.
518
687
 
519
688
  Show the latest run's on the record's page:
@@ -523,8 +692,9 @@ Show the latest run's on the record's page:
523
692
  ```
524
693
 
525
694
  Its locals are `record` and `operation`. It shows the summary (`.qube-run-summary`, inside
526
- `.qube-run-status.qube-run-<state>`) and, for a failure, the error's detail
527
- (`.qube-run-error-detail`), and nothing for a record with no runs. Its pieces are
695
+ `.qube-run-status.qube-run-<state>`, plus `.qube-run-with-errors` for an ending with errors), for a
696
+ failure its message (`.qube-run-reason`) and hint (`.qube-run-error-detail`), for an ended run with
697
+ no reason its headline (`.qube-run-headline`), and nothing for a record with no runs. Its pieces are
528
698
  `qube_rails/run_status/*`: see [Styling](#styling) to restyle or replace any of them.
529
699
 
530
700
  ## Sync status
@@ -549,7 +719,8 @@ Per connection, since an invoice can be in one company file and not another.
549
719
  out on, for a page that doesn't say which.
550
720
 
551
721
  When the run and the link disagree, the newest word wins:
552
- 1. a latest run that hasn't ended: `:sending` (an unconfirmed start too) or `:needs_answer`;
722
+ 1. a latest run that hasn't ended: `:sending` (an unconfirmed start too) or `:needs_answer`; a
723
+ start refused as `realtime_required` is `:failed`;
553
724
  2. a latest run that failed or was cancelled after the link was made, or with no link:
554
725
  `:failed` or `:cancelled`;
555
726
  3. a link: `:in_quickbooks`, always with its `qb_id`;
@@ -593,9 +764,15 @@ cause is known. A question waiting on your user isn't affected. When the connect
593
764
  resumes, the engine tells the pages of the records with a run still going on it to refresh (by the
594
765
  runs' connection index, at most 200), so the status changes without a reload.
595
766
 
596
- An answer or a start retry that can't go through (the question changed, QuBe Sync refused the
597
- answer's data, the start was confirmed meanwhile) goes back to the page with the reason in
598
- `flash[:qube_rails_error]`, which the partials show once, so it shows under Turbo too.
767
+ An answer or a start retry that can't go through (the question changed, the start was confirmed
768
+ meanwhile) goes back to the page with the reason in `flash[:qube_rails_error]`, which the partials
769
+ show once, so it shows under Turbo too. When QuBe Sync says the question was answered or asked
770
+ again since (409, or a 400 such as `not_awaiting_input`), the question is forgotten and the run reads
771
+ as running ("Syncing with QuickBooks") until its next webhook. An answer QuBe Sync refuses (422)
772
+ goes back in `flash[:qube_rails_refusal]` (`token`, `choice`, `message`, `values`): the question
773
+ partial shows the message inside the question, refills that choice's text, number, select and
774
+ checkbox fields with what was typed (not a search's pick or a rows field; nothing when it's over
775
+ 1,000 characters, for a cookie session), and marks them `aria-invalid`, described by the message.
599
776
 
600
777
  ## Questions
601
778
 
@@ -619,7 +796,14 @@ column of up to three options, such as create or use, as a segmented control), t
619
796
  its answers so far call for (each column shown while its `when` holds), stacked in a grid, a search
620
797
  per record column (sent with the row). "Set all to:" sets that choice on every record, and "Use for
621
798
  all N" under a filled search or select copies it to the other records that ask it and are still
622
- empty. Its answer is `{"records": {row key => {column => value}}}`.
799
+ empty. A rows field needs the behaviour script: without it the field and its submit stay hidden and
800
+ a `<noscript>` line says answering needs JavaScript (`question.needs_script`); cancel still works.
801
+ With more than one record it asks one at a time, and the form's button row reads, from the right:
802
+ the submit (on the last record) or Next, Back, and the step count ("2 of 3"), with cancel at the
803
+ row's left. Next is never disabled: pressing it with something missing shows what. "Set all to:"
804
+ is hidden. The other records stay in the form, hidden, so it's still one answer. Its answer
805
+ is `{"records": {row key => {column => value}}}`: each row's `key`, the columns
806
+ that row asks (`rows[].columns`), a number column as a number and a boolean one as `true` or `false`.
623
807
 
624
808
  An answer QuBe Sync can't take (422) shows its reason; one it says has changed (409, or any 400)
625
809
  goes back to the page with a message; the run's next webhook says what came of it.
@@ -641,9 +825,21 @@ your CSP nonce when you have one) and, with `stylesheet: true`, the opt-in style
641
825
  (`qube_rails.css`). Your asset pipeline serves both: Propshaft as it is, Sprockets through the
642
826
  engine's precompile list. Without `stylesheet: true` nothing of ours styles your page.
643
827
 
644
- Every rule in `qube_rails.css` is inside `:where()`, so it has no specificity and any rule of
645
- yours wins. It has no reset and no global styles. Theme it with CSS variables on `:root` or any
646
- element around the screens:
828
+ Every rule in `qube_rails.css` is inside `:where()`, so it has no specificity, and inside the
829
+ `components` cascade layer. The file starts by declaring `@layer theme, base, components,
830
+ utilities;` (Tailwind's own order), so wherever it loads: any unlayered CSS of yours wins, utility
831
+ classes (`@layer utilities`) win, and a reset in `@layer base` doesn't strip it. It has no reset and
832
+ no global styles.
833
+
834
+ - **Tailwind v4** (preflight in `@layer base`): works as it is, in any load order; your
835
+ `ui_classes` utilities override the engine's look.
836
+ - **Tailwind v3** (unlayered preflight) isn't supported with the engine's stylesheet: preflight's `*`, `button`, `input` and `[type=submit]`
837
+ rules beat a layered stylesheet, so the engine's borders, button backgrounds and paddings are
838
+ reset. Give every button and input piece classes (the example below does the main ones; add
839
+ `pick`, `button_ghost`, `search_result` and `segment`), or move to v4.
840
+ - Bootstrap and other unlayered CSS: its element rules and classes win, as before.
841
+
842
+ Theme it with CSS variables on `:root` or any element around the screens:
647
843
 
648
844
  ```css
649
845
  :root {
@@ -672,7 +868,9 @@ so `prefers-color-scheme` carries through. An app whose dark mode is a class sho
672
868
  Motion is short and only where it says something: a button gives way on press (`scale(0.97)`),
673
869
  the search box's matches drop in from the input (150ms; they close at once, and moving through them
674
870
  with the keyboard is instant), a rows field's field fades in as it starts to apply, what "Set all to"
675
- or "Use for all" fills flashes a tint, and a one-shot error fades in. All of it is transform and
871
+ or "Use for the other records too" fills flashes a tint (a record in a later step flashes as it comes
872
+ on show), a rows field's next record comes in from the side it's
873
+ stepped from (180ms, a few px), and a one-shot error fades in. All of it is transform and
676
874
  opacity, on `cubic-bezier(0.23, 1, 0.32, 1)`; with `prefers-reduced-motion: reduce` the fades stay
677
875
  and the movement goes. Hover effects apply only on devices with a fine pointer.
678
876
 
@@ -681,31 +879,40 @@ and the movement goes. Hover effects apply only on devices with a fine pointer.
681
879
  `config.ui_classes` adds your CSS framework's classes beside the `qube-` ones, by piece:
682
880
 
683
881
  ```ruby
684
- # Bootstrap
882
+ # Tailwind
883
+ config.ui_classes = {
884
+ button: "rounded-md bg-indigo-600 px-3 py-2 text-sm font-semibold text-white hover:bg-indigo-500",
885
+ button_secondary: "rounded-md bg-white px-3 py-2 text-sm font-semibold text-gray-900 ring-1 ring-inset ring-gray-300 hover:bg-gray-50",
886
+ input: "rounded-md border border-gray-300 px-3 py-2 text-sm focus:border-indigo-600 focus:outline-none",
887
+ select: "rounded-md border border-gray-300 px-3 py-2 text-sm",
888
+ label: "text-sm font-medium text-gray-900",
889
+ error: "rounded-md bg-red-50 px-3 py-2 text-sm text-red-700"
890
+ }
891
+ # Bootstrap (its form-check-input carries a top margin meant for .form-check; mt-0 lines it up)
685
892
  config.ui_classes = {
686
893
  button: "btn btn-primary", button_secondary: "btn btn-outline-secondary", input: "form-control",
687
- select: "form-select", checkbox: "form-check-input", label: "form-label",
688
- error: "alert alert-danger", status: "alert alert-light", search_result: "list-group-item list-group-item-action"
894
+ select: "form-select", checkbox: "form-check-input mt-0", label: "form-label", error: "alert alert-danger"
689
895
  }
690
- # Tailwind
691
- config.ui_classes = { button: "rounded bg-indigo-600 px-3 py-1.5 text-white", input: "rounded border-gray-300" }
692
896
  ```
693
897
 
898
+ Set `--qube-accent` to your primary colour too (Tailwind's indigo-600 is `#4f46e5`): the engine
899
+ uses it for what has no piece, such as a pick's "Use this one" link and the focus ring.
900
+
694
901
  | Piece | Where |
695
902
  | --- | --- |
696
903
  | `question` | the question's `<section>` |
697
904
  | `message`, `details` | its sentence, its label/value table |
698
905
  | `choice` | each choice's `<form>` |
699
- | `button`, `button_secondary`, `button_ghost` | the one primary button (a form choice's submit, or a plain question's first choice; the retry button), the secondary ones (other exits, later forms, redeliver, Apply), and cancel (`button_ghost`, else `button_secondary`) |
700
- | `picks`, `pick`, `pick_detail`, `pick_action` | the picks' list, each pick's option-row button (never `button`), its detail, its "Use this one" |
701
- | `choice_footer`, `choice_divider` | the exits' row; the "or" between picks and a form |
906
+ | `button`, `button_secondary`, `button_ghost` | the one primary button (the first offered record's "Use this one", a search's once a match is picked, else a form choice's submit, or a plain question's first choice; the retry button; a rows field's Next, made by the script), the secondary ones (the other offered records' "Use this one", a decline beside them, other exits, later forms, redeliver, Apply, a rows field's Back), and the ghosts: cancel (`button_ghost`; with none, no class of yours, so it keeps the engine's quiet look) |
907
+ | `picks`, `pick`, `pick_detail`, `pick_action` | the picks' list, each pick's option row (a button, never `button`; an offered record's row is a `div` whose only target is its "Use this one"), its detail, its "Use this one" (an offered record's is the submit button and also takes the `button` or `button_secondary` piece) |
908
+ | `choice_footer`, `choice_actions`, `choice_divider` | the exits' own row (with picks, or an exit with a description); a form choice's button row (cancel at its start, its submit at its end, with the exits when it's the question's one form); the "or" between picks and a form |
702
909
  | `choice_detail`, `choice_description` | a choice's detail (in its button) and description |
703
910
  | `field`, `label` | a field's wrapper and its label (and the rows field's) |
704
911
  | `input`, `select`, `checkbox` | text, number and search inputs; selects; checkboxes |
705
912
  | `search`, `search_results`, `search_result` | a search box's wrapper, its matches' container, each match (made by the script) |
706
913
  | `rows`, `row`, `row_header`, `row_fields` | a rows field's list of records, each record, its name, its fields' grid |
707
914
  | `segmented`, `segment` | a record's choice as a segmented control, each option |
708
- | `use_for_all` | the "Use for all N" button under a field |
915
+ | `use_for_all` | the "Use for the other N records too" button under a field |
709
916
  | `status`, `summary`, `detail` | the run status, its sentence, a failure's detail |
710
917
  | `stall` | why it waits on a stalled connection |
711
918
  | `error` | a one-shot error |
@@ -722,8 +929,10 @@ operation:` and `render "qube_rails/run_status", record:, operation:` don't chan
722
929
  | --- | --- | --- |
723
930
  | `qube_rails/question/_question` | `question` | the section: error, message, details, choices |
724
931
  | `qube_rails/question/_message`, `_details` | `question` | the sentence; the label/value rows |
725
- | `qube_rails/question/_picks`, `_pick` | `question`; `question`, `choice` | the picks' list; one pick, a form posting `choice` |
932
+ | `qube_rails/question/_picks`, `_pick` | `question`; `question`, `choice` | the picks' list; one pick, a form posting `choice` (a record's title, lines and facts, or a search's picked match) |
726
933
  | `qube_rails/question/_choice` | `question`, `choice` | a form or exit choice: a form posting `choice` and `data[...]` with your CSRF token |
934
+ | `qube_rails/question/_inline_search` | `question`, `choice` | a search's box under the offered records, with no submit |
935
+ | `qube_rails/question/_disclosure` | `question`, `choice` | a form behind "or <its label>…" (a name clash's rename) |
727
936
  | `qube_rails/question/_footer` | `question` | the exits' row |
728
937
  | `qube_rails/question/_field` | `field`, `control` | a field's wrapper and label around its control (HTML) |
729
938
  | `qube_rails/question/fields/_text`, `_number`, `_boolean`, `_select`, `_search`, `_rows` | `field` | one field, by `field.type` |
@@ -732,22 +941,38 @@ operation:` and `render "qube_rails/run_status", record:, operation:` don't chan
732
941
  | `qube_rails/question/rows/_segmented` | `field` | a short enum as a segmented control (radios posted as `field.input_name`) |
733
942
  | `qube_rails/run_status/_status` | `run_status` | the error, then the status: summary, detail, buttons |
734
943
  | `qube_rails/run_status/_summary`, `_detail`, `_stall`, `_retry`, `_redeliver` | `run_status` | each part (`_stall` while its connection is stalled) |
735
- | `qube_rails/_error` | `message` (optional) | a one-shot error; without `message:`, `flash[:qube_rails_error]` |
944
+ | `qube_rails/_manage_connection` | `connection` | a set-up connection's "Set up QuickBooks again" and "Use a different company file" buttons |
945
+ | `qube_rails/_error` | `message`, `id` (optional) | a one-shot error; without `message:`, `flash[:qube_rails_error]` |
736
946
 
737
947
  The locals are view-models, plain Ruby objects. Their fields are the contract, kept stable across
738
948
  versions:
739
949
 
740
- - `QubeRails::QuestionView`: `picks`, `forms`, `exits`, `plain?` (see "Choices" below), `message`, `details` (each `label`, `value`), `choices`, `token`,
950
+ - `QubeRails::QuestionView`: `picks` (the offered records, a `PickedView` slot per search box, then
951
+ the other rows), `searches` (search boxes under offered records), `alongside` (a decline with no
952
+ row of its own, just under them), `forms`, `disclosed` (forms behind "or <its label>…"), `exits`
953
+ (cancel last), `plain?`, `roles?` (the prompt says each choice's role), `matches?` (picks are
954
+ offered records), `joined_form` (the one form whose button row holds the exits), `offered_count`,
955
+ `divided?(choice, n)` (an "or" before form `n`), `mid_sentence(label)` (a label after "or"),
956
+ `ui_text(key, **options)`
957
+ (the engine's own word `question.<key>`, the one place the question's partials look new words up) (see "Choices" below), `message`, `details` (each `label`, `value`), `choices`, `token`,
741
958
  `action_url`, `search_url`, `error` (QuBe Sync's refusal, or nil), `prompt` (as QuBe Sync sent it).
742
- - `QubeRails::ChoiceView`: `id`, `label`, `detail`, `description`, `fields`, `index`, `action_url`,
743
- `secondary?` (cancel), `kind` (`:pick`, `:form` or `:exit`), `style` (its button's: `:primary`,
744
- `:secondary`, `:ghost`, or nil for a pick) and `button_piece` (its `ui_classes` piece).
959
+ - `QubeRails::ChoiceView`: `id`, `label`, `title`, `action`, `detail`, `lines`, `facts` (each a
960
+ `FactView`: `label`, `value`), `row?` (it has any of those four), `detail_parts(text = detail)`,
961
+ `description`, `fields`, `index`, `action_url`, `data` (hidden `data[...]` inputs its pick posts),
962
+ `slot?` (a `PickedView`: the row a search box's picked match fills, hidden until then),
963
+ `role` (QuBe Sync's: `pick`, `search`, `decline`, `cancel` or `answer`, one it doesn't know read as
964
+ `answer`; nil when the prompt has none), `cancel?` (and `secondary?`, the same), `kind` (`:pick`,
965
+ `:form` or `:exit`), `style` (its button's: `:primary`, `:secondary`, `:ghost`; for a pick nil, or
966
+ an offered record's "Use this one"), `button_piece` (its `ui_classes` piece) and `waits_for_pick?`
967
+ (a search's: its submit is hidden until a match is picked).
745
968
  - `QubeRails::FieldView`: `name`, `input_name` (post your value under it), `dom_id`, `type` (`text`,
746
969
  `number`, `boolean`, `select`, `search` or `rows`), `label`, `required`, `options` (a select's,
747
970
  each `value` and `label`), `kind` (a search's record kind), `search_url`, `search_field`, `row_key`,
748
- `when`, `rows` (a `RowsView`), `disabled`, `partial`, and `labelled?`, `cell?` (a rows field's) and
971
+ `when`, `rows` (a `RowsView`), `disabled`, `value` (what it starts at: a column's `default`, else
972
+ nil), `partial`, `placeholder`, and `labelled?`, `inline?` (a search box under offered records:
973
+ not required, "Search QuickBooks…"), `cell?` (a rows field's) and
749
974
  `segmented?` (a cell's enum of up to three options).
750
- - `QubeRails::RowsView`: `name`, `label`, `input_name`, `search_url`, `columns` (FieldViews), `rows`,
975
+ - `QubeRails::RowsView`: `name`, `label` (blank: no heading), `input_name`, `search_url`, `columns` (FieldViews), `rows`,
751
976
  `set_all` (the column "Set all to:" sets, or nil).
752
977
  `QubeRails::RowView`: `key`, `label`, `detail`, `values`, `values_json`, `index`, `cells` (the
753
978
  columns it asks or already has a value for), `segmented_cells`, `field_cells`.
@@ -763,14 +988,43 @@ versions:
763
988
  `data-qube-stall="<reason>"`). `RunStatusView.from_sync(sync, urls, error:, connection:)` takes the
764
989
  connection the page is about (the partial's `connection:` local), else the latest run's.
765
990
 
766
- Choices show by kind. A pick (an item of a `choose` list: an id ending `:<n>`, no fields) is a quiet
767
- option row; with no picks, a plain choice before the first form is one too (a name clash's "Use the
768
- existing record"). Each form choice (one with fields) is its own section, "or" between it and what
769
- comes before (`question.or`), its field's label leading and its submit the one filled button (only
770
- the first form's; later ones are secondary). The exits (none of these, cancel) sit in a row under a
771
- hairline, cancel as a ghost. A question with neither picks nor forms keeps its choices in one row,
772
- the first primary. So a screen never has more than one filled button. The form gets
773
- `data-qube-choice-kind`, the button `data-qube-button` (its style).
991
+ Choices show by the `role` QuBe Sync gives each (`prompt.choices[].role`). The records it offers
992
+ (`pick`) are option rows, with no heading (the question's message says what they are), each ending in a
993
+ "Use this one" button: the first is the screen's one filled button, the rest secondary. A choice
994
+ about one record can say what it is as a row: `title` in place of its label, `action` as its
995
+ button, and `lines` and `facts` (label and value side by side) in place of `detail`.
996
+
997
+ Offered records, a decline and a search show at once. Beside a `decline` the records weigh the same
998
+ as it: every record's button and the decline are secondary. A decline that says what it is as a row
999
+ (a near match's "Riverbend · new customer in QuickBooks · Add as new") is a row among the records;
1000
+ any other ("None of these") is a button just under them (`question.alongside`). A `search` is its
1001
+ box alone under them (`question.searches`), "Search QuickBooks…" (its label is for screen readers),
1002
+ not required. Picking a match there answers nothing: the match shows as a row like the offered
1003
+ ones, after them and before a decline's row, its "Use this one" focused, and the box empties for
1004
+ another search; a second pick replaces the row. The page renders that row hidden and empty (a
1005
+ `PickedView` in `question.picks`, posting the search's choice and the match as its field), and the
1006
+ script fills it. `cancel` sits alone in the footer row below, as a ghost. Without the script the
1007
+ search can't work, so the page shows the offered records, the decline and cancel, as forms that
1008
+ post.
1009
+
1010
+ With nothing offered, the search is a section of its own, as a form, the exits in its button row.
1011
+ Its submit ("Use this one") is hidden until a match is picked, then shows as the primary button.
1012
+ After a search that finds nothing (two characters or more, no error, no match picked), the decline
1013
+ is the primary button until a pick or a search that finds matches. Elsewhere `decline` ("It's not
1014
+ in QuickBooks") sits in the footer row below the choices. An `answer` shows by its shape: one with
1015
+ fields is its own section, its submit the one filled button when no record is offered (only the
1016
+ first form's; later ones are secondary). With no picks, a plain choice before the first form is an
1017
+ option row (a name clash's "Use the existing record") and the main action, and the forms after it
1018
+ wait behind "or <its label>…" (`question.disclosed`, a `<details>`): opened, its submit is the main
1019
+ action, the row's button steps back, and the focus goes to its first field; a refusal of its answer
1020
+ opens it. A question with neither picks nor forms keeps its choices in one row, the first primary.
1021
+ A role the engine doesn't know is an `answer`.
1022
+
1023
+ From a QuBe Sync that sends no roles, choices show by their shape instead: an item of a `choose` list
1024
+ (an id ending `:<n>`, no fields) is a quiet option row without a heading, the first form's submit is
1025
+ the one filled button, and the rest are exits, cancel a ghost. So a screen never has more than one
1026
+ filled button. The form gets `data-qube-choice-kind` and, with roles, `data-qube-choice-role`; the
1027
+ button `data-qube-button` (its style).
774
1028
 
775
1029
  A field override posts its value as `field.input_name`, so the controller reads it as it reads
776
1030
  ours: a checkbox `"true"`, a number as typed, a rows cell `data[<field>][<row key>][<column>]`.
@@ -784,26 +1038,76 @@ no CSP nonce (it's a file, not an inline script), and loads once however often i
784
1038
  - A search: an element with `data-qube-search="<search URL>"`, `data-qube-field="<field>"` and, in a
785
1039
  rows table, `data-qube-row="<row key>"`, holding a text input `data-qube-search-input`, a hidden
786
1040
  input `data-qube-search-value` (the one with the name, which gets the picked `value`) and a
787
- container `data-qube-search-results`. Typing two characters or more asks the search URL; each
1041
+ container `data-qube-search-results`. Focusing it empty asks the search URL with `q` empty (the
1042
+ list's first active records by name), and so does clearing it; typing two characters or more asks
1043
+ it with what's typed; each
788
1044
  match is a button (classes from `data-qube-result-class`, `role="option"`); picking one (a click,
789
1045
  or the arrow keys and Enter) fills the hidden input and fires `change` on it and `qube:picked` on
790
1046
  the box. Escape, a click outside or leaving the box closes the matches. The box gets
791
1047
  `data-qube-open` while they show, and the input `aria-expanded` and `aria-activedescendant`. Until a
792
1048
  match is picked, the text input is invalid, so the form isn't sent. Its words come from the box's
793
- `data-qube-text-no-matches`, `-searching`, `-search-failed` and `-pick-a-match` (English without).
1049
+ `data-qube-text-no-matches`, `-searching`, `-search-failed`, `-search-changed` (the search
1050
+ answered 409: the question changed) and `-pick-a-match` (English without). A match's detail is
1051
+ split into `.qube-detail-part` spans at " · ", so a line breaks between parts. A picked box gets
1052
+ `data-qube-picked` and an inline `padding-inline-start` for its check, so your input class's
1053
+ padding can't put the check over the text.
794
1054
  - A rows field: `data-qube-rows` around it; each record `data-qube-row` with `data-qube-values` (JSON);
795
1055
  each field `data-qube-col="<column>"` with `data-qube-when` (JSON) and, for a required column,
796
1056
  `data-qube-required`; each input `data-qube-rows-input` (a radio counts when checked). A field
797
1057
  whose `when` doesn't hold is `hidden` (and `data-qube-hidden`), its inputs disabled and not
798
- required, so it's neither sent nor asked for; the script toggles all three as answers change. Optional:
1058
+ required, so it's neither sent nor asked for; the script toggles all three as answers change. A
1059
+ column's `default` starts checked (or selected) and counts for `when`. The field and the form's
1060
+ submit carry `data-qube-needs-script` and `hidden` until the script shows them. Optional:
799
1061
  `data-qube-rows-set-all="<column>"` holding buttons `data-qube-set-all="<value>"` (sets that column on
800
1062
  every record offering the value), and a button `data-qube-use-for-all` in a field (shown, with the
801
- table's `data-qube-text-use-for-all`, "Use for all %{count}", while the field has a value other
802
- records' shown fields lack; copies it to them). What either fills gets `data-qube-filled` for the
803
- stylesheet's tint.
804
- - A form choice (`data-qube-choice-kind="form"`) whose required fields are all searches: its submit
805
- is disabled until each has a pick, and again if the text is edited after (by the script only, so it
806
- still posts without it).
1063
+ field's `data-qube-text-use-for-all-one` / `-other`, "Use for the other record too" / "Use for the
1064
+ other %{count} records too", while the field has a value other records' shown fields lack; copies
1065
+ it to them, then shows `<div class="qube-used-for-all" data-qube-used-for-all role="status">` with
1066
+ `data-qube-text-used-for-all-one` / `-other` in its place until the value changes). What either
1067
+ fills gets `data-qube-filled` for the stylesheet's tint; a record not on show gets it as it's
1068
+ shown.
1069
+ - Steps: a rows field with two records or more shows one at a time. The script marks the field
1070
+ `data-qube-stepped` and `data-qube-step="<n>"` (from 0), the record on show
1071
+ `data-qube-step-current`, and hides the others (`hidden` and `display: none`, never removed, so the
1072
+ form still posts every record). It marks the end of the form's button row
1073
+ (`[data-qube-actions-end]`, see below) `data-qube-step-nav` and adds there, before the submit: the
1074
+ step count `<span class="qube-rows-step" data-qube-step-line aria-live="polite">` (the field's
1075
+ `data-qube-text-step`, "%{position} of %{count}"; a `%{name}` in your own wording is the record's
1076
+ detail, else its name, from the header its `aria-labelledby` names), Back (`data-qube-step-back`,
1077
+ `data-qube-button="secondary"`, classes from `data-qube-button-secondary-class`; hidden on the
1078
+ first record) and Next (`data-qube-step-next`, `data-qube-button="primary"`, classes from
1079
+ `data-qube-button-class`; hidden on the last record, never disabled: pressed with the record
1080
+ incomplete it focuses what's missing and the browser says why). A form without that row gets one
1081
+ after the records. The form's submit shows on the last record only, and
1082
+ `data-qube-rows-set-all` is hidden. Next and Back move the focus to the record's
1083
+ first control. A refused submit (a field invalid in a hidden record) and Enter before the last
1084
+ record show the first record with a problem; a page whose one-shot error (`role="alert"`) names a
1085
+ record opens on it. Words from `data-qube-text-back` and `-next` (English without). These classes are all styled
1086
+ by `qube_rails.css` as it was before steps, so an app's copy of it still fits.
1087
+ - No submit is ever disabled: a required field left empty, or a search with text but no pick, is
1088
+ the browser's own validation on submit (the search input carries `required` and the "Pick one of
1089
+ the matches." message), which focuses it and says what's missing.
1090
+ - A form choice's button row: `.qube-choice-actions[data-qube-actions]`, holding
1091
+ `.qube-choice-actions-start` (cancel) and
1092
+ `.qube-choice-actions-end[data-qube-actions-end]` (other exits, then the submit). When a question
1093
+ has one form and no picks, its exits' buttons sit in that row and submit their own (hidden,
1094
+ empty) forms through the `form` attribute, so it works without the script.
1095
+ - A search box under offered records: its search's choice has a hidden pick form among the
1096
+ question's rows (`form[data-qube-choice-kind=pick][data-qube-choice-role=search]` with the same
1097
+ `data-qube-choice`). A picked match fills that form's `data[...]` input, its first text span (the
1098
+ name) and second (the detail), shows it and focuses its button; the box empties. The box's own
1099
+ form never submits, and its input never says "Pick one of the matches.".
1100
+ - A form behind "or <its label>…" (`details[data-qube-disclosure]`): opening it focuses its first
1101
+ field.
1102
+ - A search's list opens only for the box being focused or typed in: a box closes as the focus
1103
+ leaves it, open or not yet, and an answer that arrives for a box no longer focused is dropped.
1104
+ - A search choice's form (`form[data-qube-choice-role=search]`, not in a rows field): its own submit
1105
+ shows once a match is picked and hides again when the text changes. A search of two characters or
1106
+ more that finds nothing (with no match picked under offered records) makes the question's
1107
+ decline buttons (`button[data-qube-choice-role=decline]`, a decline form's submit, or a decline
1108
+ row's `[data-qube-offered]` action) primary, their classes swapped between the question's
1109
+ `data-qube-button-class` and `data-qube-button-secondary-class`; a pick or a search that finds
1110
+ matches swaps them back.
807
1111
  - The storyboard: a button `data-qube-copy="<text>"` copies its text.
808
1112
 
809
1113
  #### A custom combobox
@@ -837,7 +1141,7 @@ layout, so your CSS and `ui_classes` apply: the run status (not sent, starting,
837
1141
  with its retry button, running, waiting on a stalled connection (QuickBooks not checking in, or
838
1142
  closed), waiting for an answer, looking stuck with its redeliver button, in
839
1143
  QuickBooks, done, failed with its detail, cancelled), the one-shot error, and a question of each
840
- kind (a near match, a record search, a pick from a list, a fixed list, number and yes/no fields, a
1144
+ kind (a near match, a missing account, more than one match, a fixed list, number and yes/no fields, a
841
1145
  name clash, a lost answer, a missing customer, records not in QuickBooks yet, and a refused answer). Each screen is a section with
842
1146
  the screen on a flat canvas, with a note and its "Override files" (the partials to override for it, each with a
843
1147
  Copy button); the canvas can be shown as your page is, light or dark. The list of screens links to
@@ -845,8 +1149,8 @@ each one. `GET /qube/storyboard/<screen>` shows one.
845
1149
 
846
1150
  It's on while `config.storyboard` is true (by default, in development), behind your sign-in. It
847
1151
  calls nothing: its searches answer from the samples (`lib/qube_rails/storyboard/*.json`, prompts
848
- shaped as QuBe Sync sends them), its forms post to a no-op that comes back with "Storyboard:
849
- nothing was sent.", and no row is written.
1152
+ shaped as QuBe Sync sends them; in a rows field only the row's kind), its forms post to a no-op that
1153
+ comes back with "Storyboard: nothing was sent." under the question, and no row is written.
850
1154
 
851
1155
  ## Wording and translations
852
1156
 
@@ -870,7 +1174,9 @@ en:
870
1174
  | `status.in_quickbooks` | In QuickBooks | the status, linked |
871
1175
  | `status.added` | Added to QuickBooks | the status, an add that completed |
872
1176
  | `status.done`, `status.done_with` | Done; Done: %{outcome} | the status, completed |
1177
+ | `status.done_with_errors` | Done, but some didn't go through | the status, completed on an outcome with errors (`pushed_with_errors`) |
873
1178
  | `status.failed` | Couldn't sync | the status, failed (why is `reason_text`, below it) |
1179
+ | `status.realtime_required` | This company file's connection needs an upgrade to realtime before this can sync. | the status, a start refused as `realtime_required` that carried no detail |
874
1180
  | `status.not_started` | it couldn't be sent | a failure's message for a start that never went out |
875
1181
  | `status.cancelled` | Cancelled | the status, cancelled (the reason, if any, below it) |
876
1182
  | `status.cancel_reason` | it was stopped before it finished | `Run#cancel_reason_text` with no reason |
@@ -878,6 +1184,7 @@ en:
878
1184
  | `status.starting` | Sending to QuickBooks | the status, just started |
879
1185
  | `status.unconfirmed` | Still waiting for QuickBooks | the status, a start unconfirmed for a minute |
880
1186
  | `status.running` | Syncing with QuickBooks | the status, running |
1187
+ | `status.cancelling` | Cancelling… | the status after your user's cancel is posted, until the run's next event (state `cancelling`, the engine's own) |
881
1188
  | `status.quiet` | No update from QuickBooks for a while. | above the redeliver button |
882
1189
  | `status.check_for_updates` | Check for updates | the redeliver button |
883
1190
  | `status.try_again` | Try sending again | the retry button |
@@ -893,13 +1200,25 @@ en:
893
1200
  | `errors.disconnect_unreachable` | Couldn't reach QuickBooks' sync service just now. Try disconnecting again in a minute. | a disconnect QuBe Sync didn't answer |
894
1201
  | `errors.still_syncing` | Something is still syncing with this company file. Let it finish, or answer its question, then disconnect. | a disconnect while work is going |
895
1202
  | `errors.question_changed` | This question changed after the page loaded, so your answer wasn't sent. The page now shows the latest. | an answer to a changed question |
1203
+ | `errors.question_moved_on` | This question was already answered or has changed, so your answer wasn't sent. If QuickBooks needs anything else, it will ask here. | an answer QuBe Sync says came too late (409, or a 400 such as `not_awaiting_input`) |
896
1204
  | `errors.answer_refused`, `errors.answer_refused_with` | That answer couldn't be used. Check it and try again.; That answer couldn't be used: %{detail} | an answer QuBe Sync refused (422) |
1205
+ | `connection.set_up_again` | Set up QuickBooks again | `qube_rails/manage_connection`'s button to its setup |
1206
+ | `connection.use_different_company_file` | Use a different company file | `qube_rails/manage_connection`'s button to switch its company file |
897
1207
  | `question.set_all` | Set all to: | before a rows field's buttons that set every record's choice (each an option's own label) |
898
- | `question.use_for_all` | Use for all %{count} | under a filled field other records ask too |
1208
+ | `question.use_for_all` | one: Use for the other record too; other: Use for the other %{count} records too | under a filled field other records ask too (a plain string works too) |
1209
+ | `question.used_for_all` | one: Also filled in on the other record.; other: Also filled in on the other %{count} records. | where that button was, once pressed |
1210
+ | `question.choose` | Choose… | a select's first, empty option |
1211
+ | `question.step` | %{position} of %{count} | a rows field's step count, in the button row before Back (`%{name}`, the record's kind or name, may be added) |
1212
+ | `question.back`, `question.next` | Back; Next | a rows field's step buttons |
899
1213
  | `question.or` | or | between picks and a form choice |
900
1214
  | `question.use_pick` | Use this one | at the end of each pick's row: what clicking it does |
1215
+ | `question.disclose_choice` | or %{label}… | a form after a promoted row, closed (`%{label}`: its label, first letter lowercased) |
1216
+ | `question.search_quickbooks` | Search QuickBooks… | a search box under offered records |
1217
+ | `question.optional` | (optional) | after the label of a field that may be left empty |
1218
+ | `question.needs_script` | Answering this needs JavaScript. Turn it on for this page, or answer from a browser that has it. | in place of a rows field without the script (`<noscript>`) |
901
1219
  | `question.pick_a_match` | Pick one of the matches. | a search box with text but no pick, on submit |
902
1220
  | `question.no_matches`, `question.searching`, `question.search_failed` | No matches; Searching…; Search isn't available right now. Try again in a moment. | the search box's matches |
1221
+ | `question.search_changed` | This question has changed. Reload the page to see the latest. | the search box's matches, when the search answers 409 |
903
1222
 
904
1223
  `QubeRails.t(key, **options)` looks one up as the engine does. A question's own words (its message,
905
1224
  details, choices and field labels) are QuBe Sync's prompt, in English. The route constants
@@ -944,6 +1263,17 @@ gain `run` and `connection`), move `account_id`, `authorize_question!` and
944
1263
  `qube_connections` (its owner, `qube_id` and status) and drop the `qube_*` columns from your
945
1264
  tables once nothing reads them.
946
1265
 
1266
+ From qube_rails 0.2.1: `bundle update qube_rails`, then `bin/rails qube_rails:install:migrations`
1267
+ and `bin/rails db:migrate` before the new version serves any traffic or runs any job. The
1268
+ migration adds `qube_connections.company_file_changed_at` and `company_file_revision`, and
1269
+ `qube_quickbooks_records.stale_since`, `missing_since`, `review_since` and `review_name`. Every link read (`qb_id_for`, `find_linked`, `in_quickbooks`, `sync_status`...)
1270
+ now filters on those columns, so without the migration every sync fails, not only
1271
+ `connection.company_file_changed`.
1272
+
1273
+ From qube_rails 0.2.0: `bundle update qube_rails`, then `bin/rails qube_rails:install:migrations`
1274
+ and `bin/rails db:migrate` for `qube_connections.connection_type` and `qube_runs.headline`.
1275
+ Existing connection rows read `realtime` until their next event says their type.
1276
+
947
1277
  From qube_rails 0.1.0 (v1): 0.2.0 shares nothing with it. Its models and tables are yours to keep
948
1278
  or drop.
949
1279