qube_rails 0.2.1 → 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 (45) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +105 -0
  3. data/README.md +213 -56
  4. data/app/assets/javascripts/qube_rails/question.js +80 -41
  5. data/app/assets/stylesheets/qube_rails.css +143 -0
  6. data/app/controllers/qube_rails/connections_controller.rb +19 -3
  7. data/app/controllers/qube_rails/storyboard_controller.rb +1 -1
  8. data/app/models/qube_rails/connection.rb +110 -8
  9. data/app/models/qube_rails/quickbooks_record.rb +22 -0
  10. data/app/views/qube_rails/_manage_connection.html.erb +19 -0
  11. data/app/views/qube_rails/question/_choice.html.erb +2 -4
  12. data/app/views/qube_rails/question/_disclosure.html.erb +7 -0
  13. data/app/views/qube_rails/question/_footer.html.erb +2 -8
  14. data/app/views/qube_rails/question/_inline_search.html.erb +12 -0
  15. data/app/views/qube_rails/question/_pick.html.erb +25 -7
  16. data/app/views/qube_rails/question/_picks.html.erb +2 -3
  17. data/app/views/qube_rails/question/_question.html.erb +22 -13
  18. data/app/views/qube_rails/question/fields/_search.html.erb +3 -2
  19. data/app/views/qube_rails/storyboard/show.html.erb +4 -3
  20. data/config/locales/en.yml +7 -0
  21. data/config/routes.rb +2 -0
  22. data/db/migrate/20261124000000_add_qube_company_file_change.rb +17 -0
  23. data/lib/generators/qube_rails/templates/connection_events.rb.tt +17 -1
  24. data/lib/qube_rails/configuration.rb +2 -0
  25. data/lib/qube_rails/connection_events.rb +67 -7
  26. data/lib/qube_rails/engine.rb +1 -0
  27. data/lib/qube_rails/link_check.rb +274 -0
  28. data/lib/qube_rails/operation.rb +1 -0
  29. data/lib/qube_rails/question_view.rb +170 -118
  30. data/lib/qube_rails/request.rb +2 -0
  31. data/lib/qube_rails/storyboard/ask_about_add.json +1 -1
  32. data/lib/qube_rails/storyboard/choose.json +2 -2
  33. data/lib/qube_rails/storyboard/enum_select.json +1 -1
  34. data/lib/qube_rails/storyboard/missing_record.json +1 -1
  35. data/lib/qube_rails/storyboard/name_clash.json +41 -3
  36. data/lib/qube_rails/storyboard/near_match.json +8 -3
  37. data/lib/qube_rails/storyboard/number_boolean.json +1 -1
  38. data/lib/qube_rails/storyboard/record_search.json +2 -2
  39. data/lib/qube_rails/storyboard/refusal.json +7 -2
  40. data/lib/qube_rails/storyboard/rows.json +35 -18
  41. data/lib/qube_rails/storyboard.rb +21 -5
  42. data/lib/qube_rails/sync_status.rb +12 -1
  43. data/lib/qube_rails/version.rb +1 -1
  44. data/lib/qube_rails.rb +9 -0
  45. metadata +6 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6e7280e11681c6f111e93886324700bde6134f5063e67644184d672014b4bce1
4
- data.tar.gz: bfb8f73cde8dc4d6d2a9afe5a0023cbec88036542c6146c7722102b0c907e848
3
+ metadata.gz: 8fd72dc90871b00a99363ab1df95c2716dfdee0b9e34547ee41ee159a3e0e144
4
+ data.tar.gz: c33ff8c2f1f9a35f4c0d35883879f329c0f837399c43dcc14e4da06ab5e5e27a
5
5
  SHA512:
6
- metadata.gz: f10897c069a8b2dae2cf7ee4eace60fcc5e090db00db39721d0510e4e12dffb7335d35c8e841248ce49cb1835ebd1413bd0bd30aff51f529a2ac3255a169d063
7
- data.tar.gz: 40338c434f448682fb17b758290b530d17b83035c8c559611e1a7dc4a69140b8b910f35914fb2dd5cf7def7246dfa19469c737cbc0c1a88bf4c29ef440228084
6
+ metadata.gz: 1a8bb20571fe87eb59bf027d8fa002f684a4d4f35e649a8bba45f656317ddded477fcc8b747103927d696f30c9c7b71448bcb922207a30144c1e238632bd9d1d
7
+ data.tar.gz: ebe8730554ea3ca5b4e62b679e78919cad243eb409a5bdeb7d4a633431078829b921fa0dfa04aaaf0c55c3bea181b644c3da986690a8c038e59562ace8bfae89
data/CHANGELOG.md CHANGED
@@ -1,5 +1,110 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.3.0 (2026-11-27)
4
+
5
+ Run `bin/rails qube_rails:install:migrations` and `bin/rails db:migrate` before this version
6
+ serves any traffic: it adds `qube_connections.company_file_changed_at` and
7
+ `company_file_revision`, and `qube_quickbooks_records.stale_since`, `missing_since`,
8
+ `review_since` and `review_name`, and every link read filters on them, so without
9
+ the migration every sync fails.
10
+
11
+ ### New
12
+
13
+ **A connection switched to another company file**
14
+ - `connection.company_file_changed` (the customer chose "Use a different company file" on the
15
+ connection's setup page) sets the connection back to `pending`, clears `stall_reason`, marks
16
+ its `qube_quickbooks_records` rows stale (`stale_since`, ids kept), deletes its sync marks, and
17
+ sets `company_file_changed_at` and `company_file_revision`, under the row's lock with the
18
+ revision check. One that comes after a later event (a retry landing after `connected`) still
19
+ forgets the file when it's newer than `company_file_revision` and runs the hook, leaving
20
+ `status` and `revision` alone; a redelivery does nothing. Then the new
21
+ `ConnectionEvents#company_file_changed(event)` hook runs (it logs by default; the install
22
+ generator's template has it). Pages with a run going on the connection refresh, as for a stall.
23
+ - A stale link is never used: `qb_id_for`, `find_linked`, `quickbooks_record`, `in_quickbooks`,
24
+ `not_in_quickbooks` and `SyncStatus` read current links only (`QuickbooksRecord.current`,
25
+ `.stale`, `.missing`, `.under_review`, `#stale?`, `#missing?`, `#under_review?`;
26
+ `Connection#stale_links`, `#missing_links`). `link` makes the row it writes current.
27
+ - `QubeRails::LinkCheck`: on the next `connection.connected` it queues a plain request per kind
28
+ with stale links (`<kind>.query` by up to 50 ListIDs or TxnIDs, as the gem's
29
+ `Operations::INDEX` `id_param` says, else the engine's `TXN_KINDS` / `LIST_KINDS`; a kind with
30
+ neither is kept as missing when the check starts, and reported). An id found with the same name (case and spacing ignored), or kept
31
+ without a name, is current again with the answer's EditSequence. One found under another name is
32
+ held for review (`review_since`, `review_name`, unused): ids carry their record's creation time,
33
+ so a shared id means a copied file, and a rename may be a repurposed record.
34
+ `Connection#confirm_link(link)` makes it current with QuickBooks' name, `#reject_link(link)`
35
+ makes it missing; `#review_links`, `#link_under_review?`. One not found is kept as missing
36
+ (`missing_since`, unused). The next company file change makes all of them stale again. An id the answer
37
+ leaves out is missing (QuickBooks' 500 warning still returns every id it has); an answer with rows it didn't ask for
38
+ or an odd shape, or to a check queued before the last company file change, settles nothing.
39
+ After each batch the new
40
+ `ConnectionEvents#links_checked(kind:, found:, relinked:, review:, missing:, stale_left:)` runs
41
+ (it logs by default). `Connection#check_stale_links` starts the checks again by hand.
42
+ - `Operation.start` and `Request.queue` raise `QubeRails::LinkBeingChecked` for a record whose link
43
+ is still stale on the connection (`Connection#checking_link?`), first queuing its kind's check
44
+ again when the last one ended (or never got an answer) over `LinkCheck::RETRY_AFTER` (5 minutes)
45
+ ago, and `QubeRails::LinkNeedsReview`
46
+ for one under review (both `NotReady`), so nothing is sent for it until its link is settled.
47
+ - `SyncStatus` ignores a run made before `company_file_changed_at`: a record sent to the old file
48
+ reads `:not_sent` until its link is checked.
49
+ - `POST quickbooks/connections/:id/company_file` (`connection_company_file_path`): renews the
50
+ connection's links and redirects to its `links.company_file`. 404 for a simulated connection.
51
+ - `render "qube_rails/manage_connection", connection:`: "Set up QuickBooks again" and, unless
52
+ it's simulated, "Use a different company file", while the connection is connected or stalled.
53
+ New keys `connection.set_up_again` and `connection.use_different_company_file`;
54
+ `Connection#set_up?`, `#simulated?` and `#company_file_switchable?`.
55
+ - The vendored webhook test vectors have `connection.company_file_changed`.
56
+
57
+ ### Changed
58
+
59
+ **Offered records, a decline and a search at once** (in place of 0.2.1's branch at a time)
60
+ - Offered records, a decline and a search show at once. Beside a decline, every record's button
61
+ and the decline are secondary. A decline that says what it is as a row (title, action, lines:
62
+ resolve's "Riverbend · new customer in QuickBooks · Add as new") is a row among the records;
63
+ any other ("None of these") is a button just under them (`QuestionView#alongside`,
64
+ `.qube-choice-alongside`), not in the footer. Without a decline the first record is still the
65
+ main action. Cancel is alone in the footer.
66
+ - A search beside offered records is its box alone under them (`QuestionView#searches`, new
67
+ partial `question/_inline_search`, `.qube-search-inline`, new key `question.search_quickbooks`,
68
+ `FieldView#placeholder`, `FieldView#inline?`). Picking a match answers nothing: the match shows
69
+ as a row like the offered ones, focused, and the box empties for another search; a second pick
70
+ replaces it. That row is a slot the page renders hidden and empty (`PickedView`,
71
+ `ChoiceView#slot?` and `#data`), posting the search's choice with the match. A search that finds
72
+ nothing makes the decline the main action, unless a match was picked.
73
+ - A search's list opens only for the box being focused or typed in, and a box under offered
74
+ records never shows the error edge: its pick is a row of its own.
75
+ - The branch pattern is gone: `QuestionView#chain?`, `#branch`, `#branch_part`, `#shown_part?` and
76
+ `#joined_exits`, `data-qube-branch*` and "← Back to the possible match". An override of
77
+ `_question`, `_footer` or `_choice` copied from 0.2.1 that calls them needs updating, and an
78
+ override of `_pick` must render `choice.data` and hide `choice.slot?`. `question.none_of_these`
79
+ and `question.back_to_offered` are unused.
80
+ - An offered record's button is described by the record's name (`aria-describedby`,
81
+ `ChoiceView#label_id`), so a screen reader says which record "Use this one" picks. The search box
82
+ under offered records is hidden until the script runs, since it can't search without it.
83
+
84
+ **A name clash leads with the existing record**
85
+ - A choice about one record can carry `title`, `action`, `lines` (each split on " · ") and
86
+ `facts` (`{label, value}`), in place of `detail`: `ChoiceView#title`, `#action`, `#lines`,
87
+ `#facts` (`FactView`), `#row?`; `.qube-pick-line`, `.qube-pick-facts`, `.qube-pick-fact`,
88
+ `.qube-pick-fact-label`.
89
+ - `ensure`'s ask_use shows the existing record's row (QuickBooks' stored name, its lines, and
90
+ Company, Balance, Added) with "Use existing" as the main action. Adding it under another name
91
+ waits behind "or add it under another name…" (new key `question.disclose_choice`,
92
+ `QuestionView#disclosed` and `#mid_sentence`, new partial `question/_disclosure`, a `<details>`
93
+ with `.qube-choice-disclosure` and `data-qube-disclosure`); opened, its submit is the main
94
+ action and the focus goes to its first field. A refusal of its answer opens it.
95
+
96
+ **An offered record's button is its only target**
97
+ - An offered record's row (`.qube-pick`) is now a `div`, and its "Use this one"
98
+ (`.qube-pick-action`) is the submit button: a click on the record's name or details does
99
+ nothing. A row without its own button (a plain option) is still a button whole. Styles keyed
100
+ on `button.qube-pick` for an offered record need `.qube-pick`.
101
+
102
+ **Smaller**
103
+ - Option rows sit on a quiet fill rather than a border, so they aren't boxes inside the card.
104
+ - The storyboard's search in a rows field returns only records of the row's kind, as QuBe Sync's
105
+ search scopes by `row`. Its notes say in plain words what brings each screen up and what your
106
+ user can do.
107
+
3
108
  ## 0.2.1 (2026-11-17)
4
109
 
5
110
  Connections keep their type, so workflows aren't started on standard ones, and run webhooks are
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 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. |
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. |
@@ -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:
@@ -209,8 +225,9 @@ dropped ...") and returns.
209
225
 
210
226
  A `QubeRails::Connection` is one company file: `owner` (your account), `qube_id` (QuBe Sync's
211
227
  id, nil until it answers), `name`, `status` (`pending`, `connected`, `setup_cancelled`,
212
- `stalled`), `stall_reason`, `revision` and `connection_type` (`realtime`, `standard` or
213
- `simulated`). `QubeRails::Connection.owned_by(account)` lists an 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.
214
231
 
215
232
  A connection's type can't be changed through the API: the customer upgrades a standard one to
216
233
  realtime from its page in the QuBe Sync dashboard. Its next event carries the new type, and
@@ -236,6 +253,109 @@ So a row id used again (MySQL 5.7 after a restart, a restored database) never ta
236
253
  connection. The unpaged listing is acceptable because it only runs for a row without an id,
237
254
  which is rare: a lost create, or an event that beat the save.
238
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
+
239
359
  ```ruby
240
360
  module QuickbooksDesktop
241
361
  class ConnectionEvents < QubeRails::ConnectionEvents
@@ -258,6 +378,17 @@ module QuickbooksDesktop
258
378
  def resumed(event)
259
379
  log_event(event)
260
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
261
392
  end
262
393
  end
263
394
  ```
@@ -269,7 +400,9 @@ QuickBooks gives out ListIDs from one counter per family, so an id is unique onl
269
400
  family of one company file (verified on QuickBooks Enterprise 24.0): customers, vendors,
270
401
  employees and other names share one, every item type shares another, each other list (accounts,
271
402
  classes, terms...) has its own, and the same counter value turns up in several families.
272
- 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.
273
406
 
274
407
  ```ruby
275
408
  connection.link(customer, kind: "customer", qb_id: list_id, edit_sequence: "171", name: "Riverbend Electric")
@@ -441,7 +574,8 @@ module QuickbooksDesktop
441
574
  # error or discarded: show event.error["user_message"].
442
575
  def failed(event); end
443
576
 
444
- # 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.
445
579
  def retrying(event); end
446
580
 
447
581
  # The answer never came back: QuickBooks may have applied it. Default: failed(event). A query
@@ -769,8 +903,8 @@ uses it for what has no piece, such as a pick's "Use this one" link and the focu
769
903
  | `question` | the question's `<section>` |
770
904
  | `message`, `details` | its sentence, its label/value table |
771
905
  | `choice` | each choice's `<form>` |
772
- | `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", "Not this one", other exits, later forms, redeliver, Apply, a rows field's Back), and the ghosts: cancel, "← Back to the possible match" (`button_ghost`; with none, no class of yours, so they keep the engine's quiet look) |
773
- | `picks`, `pick`, `pick_detail`, `pick_action` | the picks' list, each pick's option-row button (never `button`), its detail, its "Use this one" (an offered record's also takes the `button` or `button_secondary` piece) |
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) |
774
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 |
775
909
  | `choice_detail`, `choice_description` | a choice's detail (in its button) and description |
776
910
  | `field`, `label` | a field's wrapper and its label (and the rows field's) |
@@ -795,9 +929,11 @@ operation:` and `render "qube_rails/run_status", record:, operation:` don't chan
795
929
  | --- | --- | --- |
796
930
  | `qube_rails/question/_question` | `question` | the section: error, message, details, choices |
797
931
  | `qube_rails/question/_message`, `_details` | `question` | the sentence; the label/value rows |
798
- | `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) |
799
933
  | `qube_rails/question/_choice` | `question`, `choice` | a form or exit choice: a form posting `choice` and `data[...]` with your CSRF token |
800
- | `qube_rails/question/_footer` | `question` | the exits' row (in a chain, ending in "Not this one" / "None of these") |
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) |
936
+ | `qube_rails/question/_footer` | `question` | the exits' row |
801
937
  | `qube_rails/question/_field` | `field`, `control` | a field's wrapper and label around its control (HTML) |
802
938
  | `qube_rails/question/fields/_text`, `_number`, `_boolean`, `_select`, `_search`, `_rows` | `field` | one field, by `field.type` |
803
939
  | `qube_rails/question/rows/_row` | `rows`, `row` | one record: its name, its choice, its fields |
@@ -805,21 +941,25 @@ operation:` and `render "qube_rails/run_status", record:, operation:` don't chan
805
941
  | `qube_rails/question/rows/_segmented` | `field` | a short enum as a segmented control (radios posted as `field.input_name`) |
806
942
  | `qube_rails/run_status/_status` | `run_status` | the error, then the status: summary, detail, buttons |
807
943
  | `qube_rails/run_status/_summary`, `_detail`, `_stall`, `_retry`, `_redeliver` | `run_status` | each part (`_stall` while its connection is stalled) |
944
+ | `qube_rails/_manage_connection` | `connection` | a set-up connection's "Set up QuickBooks again" and "Use a different company file" buttons |
808
945
  | `qube_rails/_error` | `message`, `id` (optional) | a one-shot error; without `message:`, `flash[:qube_rails_error]` |
809
946
 
810
947
  The locals are view-models, plain Ruby objects. Their fields are the contract, kept stable across
811
948
  versions:
812
949
 
813
- - `QubeRails::QuestionView`: `picks`, `forms`, `exits` (cancel last), `plain?`, `roles?` (the prompt
814
- says each choice's role), `matches?` (picks are offered records: "Possible matches"), `joined_form` and
815
- `joined_exits` (the one form whose button row holds the exits, and those exits), `chain?` (offered
816
- records with a search, shown a branch at a time), `branch` (`:offered` or `:search` as the page
817
- loads; nil when it isn't a chain), `branch_part(piece)` (a form's, or `:picks`' or `:footer`'s,
818
- `"offered"` or `"search"`), `shown_part?(part)`, `offered_count`, `divided?(choice, n)` (an "or"
819
- before form `n`), `ui_text(key, **options)`
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)`
820
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`,
821
958
  `action_url`, `search_url`, `error` (QuBe Sync's refusal, or nil), `prompt` (as QuBe Sync sent it).
822
- - `QubeRails::ChoiceView`: `id`, `label`, `detail`, `description`, `fields`, `index`, `action_url`,
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),
823
963
  `role` (QuBe Sync's: `pick`, `search`, `decline`, `cancel` or `answer`, one it doesn't know read as
824
964
  `answer`; nil when the prompt has none), `cancel?` (and `secondary?`, the same), `kind` (`:pick`,
825
965
  `:form` or `:exit`), `style` (its button's: `:primary`, `:secondary`, `:ghost`; for a pick nil, or
@@ -829,7 +969,8 @@ versions:
829
969
  `number`, `boolean`, `select`, `search` or `rows`), `label`, `required`, `options` (a select's,
830
970
  each `value` and `label`), `kind` (a search's record kind), `search_url`, `search_field`, `row_key`,
831
971
  `when`, `rows` (a `RowsView`), `disabled`, `value` (what it starts at: a column's `default`, else
832
- nil), `partial`, and `labelled?`, `cell?` (a rows field's) and
972
+ nil), `partial`, `placeholder`, and `labelled?`, `inline?` (a search box under offered records:
973
+ not required, "Search QuickBooks…"), `cell?` (a rows field's) and
833
974
  `segmented?` (a cell's enum of up to three options).
834
975
  - `QubeRails::RowsView`: `name`, `label` (blank: no heading), `input_name`, `search_url`, `columns` (FieldViews), `rows`,
835
976
  `set_all` (the column "Set all to:" sets, or nil).
@@ -849,31 +990,35 @@ versions:
849
990
 
850
991
  Choices show by the `role` QuBe Sync gives each (`prompt.choices[].role`). The records it offers
851
992
  (`pick`) are option rows, with no heading (the question's message says what they are), each ending in a
852
- "Use this one" button: the first is the screen's one filled button, the rest secondary.
853
-
854
- Offered records with a `search` are a chain, shown a branch at a time (`question.chain?`). The
855
- offered records come first, with the footer row below them: `cancel` at its start and "Not this
856
- one" (one record) or "None of these" (several) at its end (`question.none_of_these`). That swaps
857
- them for the search: "← Back to the possible match" (`question.back_to_offered`) above it, then the
858
- search's form, its field's label leading ("Not listed? Search QuickBooks"), with cancel at the
859
- start of its button row and `decline` ("It's not in QuickBooks") and its submit at the end. Moving
860
- to the search focuses its box (which lists the first records); Back focuses the first record; what
861
- was typed or picked stays. A page showing QuBe Sync's refusal of the search's answer starts on the
862
- search. Each part carries `data-qube-branch-part` (`offered` or `search`) and the one not on show
863
- is `hidden`. Without the script the search can't work, so a chain shows the offered records and a
864
- footer of cancel and the decline, as forms that post; "Not this one" and the search wait for the
865
- script (which then hides the footer's decline: it belongs to the search).
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.
866
1009
 
867
1010
  With nothing offered, the search is a section of its own, as a form, the exits in its button row.
868
- Any search's submit ("Use this one") is hidden until a match is picked, then shows as the primary
869
- button; after a search that finds nothing (two characters or more, no error), the decline is the
870
- primary button until a pick or a search that finds matches. Elsewhere `decline` ("It's not in
871
- QuickBooks") sits in the footer row below the choices, and `cancel` ("Don't add the invoice") at
872
- the start of that row, as a ghost. An `answer` shows by its shape: one with fields is its own section, its submit the one filled
873
- button when no record is offered (only the first form's; later ones are secondary); with no picks, a
874
- plain choice before the first form is an option row (a name clash's "Use the existing record"). A
875
- question with neither picks nor forms keeps its choices in one row, the first primary. A role the
876
- engine doesn't know is an `answer`.
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`.
877
1022
 
878
1023
  From a QuBe Sync that sends no roles, choices show by their shape instead: an item of a `choose` list
879
1024
  (an id ending `:<n>`, no fields) is a quiet option row without a heading, the first form's submit is
@@ -947,17 +1092,20 @@ no CSP nonce (it's a file, not an inline script), and loads once however often i
947
1092
  `.qube-choice-actions-end[data-qube-actions-end]` (other exits, then the submit). When a question
948
1093
  has one form and no picks, its exits' buttons sit in that row and submit their own (hidden,
949
1094
  empty) forms through the `form` attribute, so it works without the script.
950
- - A chain (see "Choices"): in a `[data-qube-question]`, a `[data-qube-branch="search"]` or
951
- `[data-qube-branch="offered"]` button shows that branch: each `[data-qube-branch-part]` not of it
952
- is hidden (`hidden` and `display: none`), "Not this one" (the `data-qube-branch="search"` button
953
- without a part of its own) shows on the offered branch, and a `form[data-qube-choice-role=decline]`
954
- on the search's only. The focus goes to the search's `[data-qube-search-input]`, or to the first
955
- offered record's button. As the page loads, the branch on show is the search when an `offered`
956
- part is `hidden`.
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.
957
1104
  - A search choice's form (`form[data-qube-choice-role=search]`, not in a rows field): its own submit
958
1105
  shows once a match is picked and hides again when the text changes. A search of two characters or
959
- more that finds nothing makes the question's decline buttons (`button[data-qube-choice-role=decline]`,
960
- or a decline form's submit) primary, their classes swapped between the question's
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
961
1109
  `data-qube-button-class` and `data-qube-button-secondary-class`; a pick or a search that finds
962
1110
  matches swaps them back.
963
1111
  - The storyboard: a button `data-qube-copy="<text>"` copies its text.
@@ -993,7 +1141,7 @@ layout, so your CSS and `ui_classes` apply: the run status (not sent, starting,
993
1141
  with its retry button, running, waiting on a stalled connection (QuickBooks not checking in, or
994
1142
  closed), waiting for an answer, looking stuck with its redeliver button, in
995
1143
  QuickBooks, done, failed with its detail, cancelled), the one-shot error, and a question of each
996
- 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
997
1145
  name clash, a lost answer, a missing customer, records not in QuickBooks yet, and a refused answer). Each screen is a section with
998
1146
  the screen on a flat canvas, with a note and its "Override files" (the partials to override for it, each with a
999
1147
  Copy button); the canvas can be shown as your page is, light or dark. The list of screens links to
@@ -1001,8 +1149,8 @@ each one. `GET /qube/storyboard/<screen>` shows one.
1001
1149
 
1002
1150
  It's on while `config.storyboard` is true (by default, in development), behind your sign-in. It
1003
1151
  calls nothing: its searches answer from the samples (`lib/qube_rails/storyboard/*.json`, prompts
1004
- shaped as QuBe Sync sends them), its forms post to a no-op that comes back with "Storyboard:
1005
- 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.
1006
1154
 
1007
1155
  ## Wording and translations
1008
1156
 
@@ -1054,6 +1202,8 @@ en:
1054
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 |
1055
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`) |
1056
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 |
1057
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) |
1058
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) |
1059
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 |
@@ -1062,8 +1212,8 @@ en:
1062
1212
  | `question.back`, `question.next` | Back; Next | a rows field's step buttons |
1063
1213
  | `question.or` | or | between picks and a form choice |
1064
1214
  | `question.use_pick` | Use this one | at the end of each pick's row: what clicking it does |
1065
- | `question.none_of_these` | one: Not this one; other: None of these | at the end of a chain's footer row: shows the search in place of the offered records |
1066
- | `question.back_to_offered` | one: ← Back to the possible match; other: ← Back to the %{count} possible matches | above a chain's search: shows the offered records again |
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 |
1067
1217
  | `question.optional` | (optional) | after the label of a field that may be left empty |
1068
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>`) |
1069
1219
  | `question.pick_a_match` | Pick one of the matches. | a search box with text but no pick, on submit |
@@ -1113,6 +1263,13 @@ gain `run` and `connection`), move `account_id`, `authorize_question!` and
1113
1263
  `qube_connections` (its owner, `qube_id` and status) and drop the `qube_*` columns from your
1114
1264
  tables once nothing reads them.
1115
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
+
1116
1273
  From qube_rails 0.2.0: `bundle update qube_rails`, then `bin/rails qube_rails:install:migrations`
1117
1274
  and `bin/rails db:migrate` for `qube_connections.connection_type` and `qube_runs.headline`.
1118
1275
  Existing connection rows read `realtime` until their next event says their type.