qube_sync 0.4.0 → 0.6.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 (99) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +94 -3
  3. data/README.md +106 -7
  4. data/exe/qube_sync +11 -0
  5. data/lib/qube_sync/client.rb +58 -7
  6. data/lib/qube_sync/operations/account.rb +21 -20
  7. data/lib/qube_sync/operations/ar_refund_credit_card.rb +17 -14
  8. data/lib/qube_sync/operations/bill.rb +148 -104
  9. data/lib/qube_sync/operations/bill_payment_check.rb +29 -22
  10. data/lib/qube_sync/operations/bill_payment_credit_card.rb +21 -16
  11. data/lib/qube_sync/operations/bill_to_pay.rb +7 -6
  12. data/lib/qube_sync/operations/billing_rate.rb +10 -9
  13. data/lib/qube_sync/operations/build_assembly.rb +13 -12
  14. data/lib/qube_sync/operations/charge.rb +36 -34
  15. data/lib/qube_sync/operations/check.rb +144 -100
  16. data/lib/qube_sync/operations/class.rb +11 -11
  17. data/lib/qube_sync/operations/credit_card_charge.rb +144 -100
  18. data/lib/qube_sync/operations/credit_card_credit.rb +144 -100
  19. data/lib/qube_sync/operations/credit_memo.rb +142 -108
  20. data/lib/qube_sync/operations/currency.rb +7 -7
  21. data/lib/qube_sync/operations/customer.rb +54 -53
  22. data/lib/qube_sync/operations/customer_msg.rb +5 -5
  23. data/lib/qube_sync/operations/customer_type.rb +7 -7
  24. data/lib/qube_sync/operations/data_ext.rb +7 -6
  25. data/lib/qube_sync/operations/date_driven_terms.rb +5 -5
  26. data/lib/qube_sync/operations/deposit.rb +53 -38
  27. data/lib/qube_sync/operations/employee.rb +27 -23
  28. data/lib/qube_sync/operations/entity.rb +5 -5
  29. data/lib/qube_sync/operations/estimate.rb +119 -90
  30. data/lib/qube_sync/operations/fields.rb +4058 -0
  31. data/lib/qube_sync/operations/form1099_category_account_mapping.rb +3 -2
  32. data/lib/qube_sync/operations/inventory_adjustment.rb +43 -34
  33. data/lib/qube_sync/operations/inventory_site.rb +11 -11
  34. data/lib/qube_sync/operations/invoice.rb +142 -108
  35. data/lib/qube_sync/operations/item.rb +5 -5
  36. data/lib/qube_sync/operations/item_assemblies_can_build.rb +2 -2
  37. data/lib/qube_sync/operations/item_discount.rb +25 -24
  38. data/lib/qube_sync/operations/item_fixed_asset.rb +17 -16
  39. data/lib/qube_sync/operations/item_group.rb +17 -15
  40. data/lib/qube_sync/operations/item_inventory.rb +45 -44
  41. data/lib/qube_sync/operations/item_inventory_assembly.rb +51 -48
  42. data/lib/qube_sync/operations/item_non_inventory.rb +55 -44
  43. data/lib/qube_sync/operations/item_other_charge.rb +51 -40
  44. data/lib/qube_sync/operations/item_payment.rb +21 -20
  45. data/lib/qube_sync/operations/item_receipt.rb +144 -100
  46. data/lib/qube_sync/operations/item_sales_tax.rb +21 -20
  47. data/lib/qube_sync/operations/item_sales_tax_group.rb +11 -11
  48. data/lib/qube_sync/operations/item_service.rb +55 -44
  49. data/lib/qube_sync/operations/item_sites.rb +10 -8
  50. data/lib/qube_sync/operations/item_subtotal.rb +7 -7
  51. data/lib/qube_sync/operations/job_type.rb +7 -7
  52. data/lib/qube_sync/operations/journal_entry.rb +49 -34
  53. data/lib/qube_sync/operations/lead.rb +7 -7
  54. data/lib/qube_sync/operations/list.rb +2 -2
  55. data/lib/qube_sync/operations/list_display.rb +2 -2
  56. data/lib/qube_sync/operations/list_merge.rb +6 -4
  57. data/lib/qube_sync/operations/other_name.rb +7 -7
  58. data/lib/qube_sync/operations/payment_method.rb +6 -5
  59. data/lib/qube_sync/operations/payroll_item_non_wage.rb +5 -5
  60. data/lib/qube_sync/operations/payroll_item_wage.rb +7 -7
  61. data/lib/qube_sync/operations/price_level.rb +23 -19
  62. data/lib/qube_sync/operations/purchase_order.rb +113 -86
  63. data/lib/qube_sync/operations/receive_payment.rb +37 -30
  64. data/lib/qube_sync/operations/sales_order.rb +117 -90
  65. data/lib/qube_sync/operations/sales_receipt.rb +142 -108
  66. data/lib/qube_sync/operations/sales_rep.rb +11 -11
  67. data/lib/qube_sync/operations/sales_tax_code.rb +15 -15
  68. data/lib/qube_sync/operations/sales_tax_payment_check.rb +18 -14
  69. data/lib/qube_sync/operations/sales_tax_return_line.rb +2 -2
  70. data/lib/qube_sync/operations/ship_method.rb +5 -5
  71. data/lib/qube_sync/operations/special_account.rb +2 -2
  72. data/lib/qube_sync/operations/standard_terms.rb +5 -5
  73. data/lib/qube_sync/operations/terms.rb +5 -5
  74. data/lib/qube_sync/operations/time_tracking.rb +23 -22
  75. data/lib/qube_sync/operations/to_do.rb +23 -23
  76. data/lib/qube_sync/operations/transaction.rb +15 -10
  77. data/lib/qube_sync/operations/transfer.rb +12 -12
  78. data/lib/qube_sync/operations/transfer_inventory.rb +35 -26
  79. data/lib/qube_sync/operations/txn_display.rb +2 -2
  80. data/lib/qube_sync/operations/unit_of_measure_set.rb +5 -5
  81. data/lib/qube_sync/operations/vehicle.rb +7 -7
  82. data/lib/qube_sync/operations/vehicle_mileage.rb +8 -8
  83. data/lib/qube_sync/operations/vendor.rb +54 -52
  84. data/lib/qube_sync/operations/vendor_credit.rb +144 -100
  85. data/lib/qube_sync/operations/vendor_type.rb +7 -7
  86. data/lib/qube_sync/operations/workers_comp_code.rb +8 -8
  87. data/lib/qube_sync/operations.rb +267 -262
  88. data/lib/qube_sync/version.rb +1 -1
  89. data/lib/qube_sync/webhooks/event.rb +80 -6
  90. data/lib/qube_sync/workflow_types/cli.rb +120 -0
  91. data/lib/qube_sync/workflow_types/rbs_renderer.rb +290 -0
  92. data/lib/qube_sync/workflow_types/ruby_renderer.rb +391 -0
  93. data/lib/qube_sync/workflow_types/workflow.rb +153 -0
  94. data/lib/qube_sync/workflow_types.rb +219 -0
  95. data/sig/qube_sync/client.rbs +6 -2
  96. data/sig/qube_sync/operations.rbs +2 -1
  97. data/sig/qube_sync/webhooks.rbs +148 -0
  98. data/sig/qube_sync/workflow_types.rbs +59 -0
  99. metadata +13 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1eac592828778d486630d76ff7d8b43072a5006682c1b8182f1c5e13f48097f2
4
- data.tar.gz: 04de6f5cc7db7be2569186733e1961f291348d96e8a23dcf832ab4f40a96d722
3
+ metadata.gz: 972bcd21ec06cbecb11ecef26e26c4a2931ccff827a698b25fec8d05b1f758ed
4
+ data.tar.gz: 7c65b456a289bd8aad18103bb3bc6e80ea9289a4405ef4628e5af355f055ce0c
5
5
  SHA512:
6
- metadata.gz: 1011b04d773e99fb8fa441608c11f2d37a173ded5a98a41c07b3237eaa0cc67a3ea460a5fda24b9b39e39441c4dcc2a12cbe0a8c69b2d9994f89d765117a18d5
7
- data.tar.gz: 5f681be6ee755144dfae40d73d2a8d3d9eb0a43ceeea9a9c712c89e09719f9a86f52bd6e3dfd056f5a00d660d1ef518f3a22eb0a6a06bccbcd54d54c465ac9a0
6
+ metadata.gz: '085fc85b02ab96e5009f5031eb9d27d525f40ea7c4fb7aeb2bf12c5afe1a2d1a1b04f36ca7b7e87844c1e9c1f13950d9d9ce957d621fb1ed3daf7e5be868c1c3'
7
+ data.tar.gz: c490c19e4a8a5c44bf52f1706a87564508f0e2905b9f3590e3f6aeb833847981c43e77eea66542f748671b1d0df9b29ea4e7d589f8b747a95d3da94f4e28da98
data/CHANGELOG.md CHANGED
@@ -1,7 +1,98 @@
1
- ## [Unreleased]
1
+ ## [0.6.0] - 2026-11-27
2
2
 
3
- - Releases publish through RubyGems trusted publishing, from `release.yml`'s OIDC token; no
4
- API key is stored.
3
+ For QuBe Sync's new workflow webhook shape. One read changes: `WorkflowRunEvent#error` returns
4
+ a `WorkflowRunError` instead of the body's raw value. It's a minor version because, before 1.0,
5
+ a change to what a reader returns goes in the minor number; code that called String methods on
6
+ it (`event.error.upcase`) needs `event.error.message`.
7
+
8
+ ### Changed
9
+
10
+ - `WorkflowRunEvent#error` returns a `QubeSync::Webhooks::WorkflowRunError` (`code`, `type`,
11
+ `message`, `quickbooks_message`, `hint`), nil when there's none. QuBe Sync now sends `error` as
12
+ an object; a String from an older server reads as one with only `message`, without raising.
13
+ `error["message"]` and `error.to_s` still work, and `event["error"]` returns the raw value.
14
+ It serializes to JSON with every field (`to_json`, `as_json`), so it can be stored as it is.
15
+ What stops working is treating it as a String: `event.error == "text"`, `"..." + event.error`,
16
+ `include?` and the like; use `event.error.message`.
17
+
18
+ ### New
19
+
20
+ - `ConnectionEvent#company_file_changed?` for QuBe Sync's `connection.company_file_changed`
21
+ event: the customer switched the connection to another company file. Every ListID and TxnID
22
+ stored for the connection belongs to the old file: set them aside, check them on the new file
23
+ once it's connected (a renamed or copied file keeps most), keep those found under the same
24
+ name and ask your customer about those found under another; the
25
+ connection isn't connected until `connection.connected` arrives again. A v2
26
+ connection's `links["company_file"]` is the page to switch from (nil for a simulated
27
+ connection); `regenerate_onboarding` renews it with `links["onboarding"]`. The vendored test
28
+ vectors have the new event, and the workflow vectors' bodies as QuBe Sync now sends them
29
+ (each prompt choice has a `role`).
30
+ - `QubeSync::Operations::INDEX` entries carry `id_param`: the id list a query looks records up
31
+ by (`"list_id"` or `"txn_id"`), nil for a query with neither (company, preferences, reports)
32
+ and for every other action. Generated by `bin/generate-operations` from each query's params.
33
+ - `WorkflowRunEvent#headline` and `NotificationEvent#headline`: one plain sentence saying what
34
+ happened, for a person. Never parse it.
35
+ - `WorkflowRunEvent#workflow_id`.
36
+ - The vendored webhook test vectors are QuBe Sync's new ones: `error` an object, `headline` on
37
+ every workflow event, `summary.changes` in place of `summary.side_effects`, `links` only while
38
+ they work, and no `prompt.options`. The library passes `output`, `summary` and `prompt` through
39
+ as they come, so `push_records`' `pushed` / `pushed_with_errors` outcomes and their `items` and
40
+ `counts` need no change here; `output.outcome` is gone, so read `event.outcome`.
41
+ - RBS for `QubeSync::Webhooks` and its event classes (`sig/qube_sync/webhooks.rbs`).
42
+
43
+ - `RequestEvent#perhaps_applied?`: true for a `timed_out` request and for an `error` with
44
+ `error_type` `outcome_unknown` (QuBe Sync's new type for a write the Web Connector reported an
45
+ error on mid-request) or `response_too_large` (QuickBooks ran it, but its answer was too big
46
+ to keep). QuickBooks may have applied any of them, so look before sending a write again. A
47
+ query is safe to resend; page a `response_too_large` one (`iterator`, a smaller
48
+ `max_returned`) or narrow it.
49
+ `RequestEvent#error_type` reads `error.error_type`.
50
+ - A request webhook whose body would be over 1 MB now comes with `response_xml` nil,
51
+ `response_xml_omitted: true` and `links.self`. `RequestEvent#response_xml`,
52
+ `#response_xml_omitted?`, `#links` and `#self_link` read them, and
53
+ `Client#response_xml_for(event)` returns the event's `response_xml`, fetching it from
54
+ `links.self` when it was omitted.
55
+ - `Client#get_request(link)` takes a request's URL (such as `links.self`), as `get_run` does.
56
+ `get_request(connection_id, id)` works as before.
57
+
58
+ ## [0.5.0] - 2026-10-27
59
+
60
+ Typed workflow starts, simulated connections, resending a run's latest event, and per-row search. Nothing
61
+ existing changes: every 0.4.0 call works as it did.
62
+
63
+ ### New
64
+
65
+ - **Typed workflow starts.** `bundle exec qube_sync workflows` (with `QUBE_API_KEY` set) fetches
66
+ your app's workflow input types from QuBe Sync and writes `lib/qube_workflows.rb` and its RBS
67
+ (`sig/qube_workflows.rbs`): a start method and an `*_input` builder for each branch of each
68
+ workflow's input, with every operation body typed as that operation's params
69
+ (`QubeSync::Operations::<Entity>::<action>_params`) and linked to its YARD reference. Fields a
70
+ workflow sets itself (`set_by_workflow`) are optional in its bodies. Options: `--drafts`,
71
+ `--output`, `--sig`, and `--check`, which exits 1 when your file no longer matches what QuBe
72
+ Sync serves (naming the workflows that changed) or on a 401, and warns but exits 0 when QuBe
73
+ Sync can't be reached. The same input always gives byte-identical files, and the generated
74
+ file loads on Ruby 2.7 too. `QubeSync::WorkflowTypes.render` and `.check` do the same from
75
+ code; qube_rails' generator uses them.
76
+ - `Client#workflow_types(include_drafts: false, etag: nil)`: `GET /workflows/types`, returning
77
+ `:not_modified` on a 304.
78
+ - `Client#create_connection(webhook_url:, name: nil, type: nil)`: `type: "simulated"` makes a
79
+ connection to a simulated QuickBooks company file, connected as soon as it's made, for trying
80
+ an integration without QuickBooks Desktop.
81
+ - `Client#redeliver_run(connection_id, run_id)`: `POST .../workflow-runs/{id}/redeliver` has
82
+ QuBe Sync send the run's latest event to your webhook again, for when your endpoint was down
83
+ longer than QuBe Sync's retries.
84
+ - `search(search_url, field:, q:, row: nil)`: `row` names the row of a question's rows field,
85
+ for a search whose kind depends on that row (the missing-records question's per-record search).
86
+ - `QubeSync::Operations::DIGEST`: the sha256 of the QuickBooks operations manifest this version
87
+ was generated from. `qube_sync workflows` warns when QuBe Sync's operations differ from it,
88
+ since operations this version doesn't know are typed as a plain Hash.
89
+
90
+ ### Changed
91
+
92
+ - The per-operation docs now say a QuickBooks `list_id` is unique within a list family, not
93
+ across the company file: customers, vendors, employees and other names share one sequence,
94
+ every item type shares another, and each other list has its own. Key stored ids by
95
+ connection and record kind, never by `list_id` alone.
5
96
 
6
97
  ## [0.4.0] - 2026-10-25
7
98
 
data/README.md CHANGED
@@ -41,10 +41,22 @@ redirect_to connection["links"]["onboarding"], allow_other_host: true
41
41
 
42
42
  QuBe Sync sends `connection.connected` to the connection's `webhook_url` once the customer's Web
43
43
  Connector first checks in. `regenerate_onboarding(id)` makes a fresh onboarding link, and
44
- `update_connection(id, webhook_url:, name:)` changes either. `get_connection`,
44
+ `update_connection(id, webhook_url:, name:)` changes either. `create_connection(webhook_url:,
45
+ type: "simulated")` makes a connection to a simulated QuickBooks company file instead, connected
46
+ as it's made, for testing without a Windows computer. `get_connection`,
45
47
  `list_connections`, `delete_connection`, `set_password(id, password: nil)` and `get_qwc(id)` (the
46
48
  QWC file's XML) are there for setup without hosted onboarding.
47
49
 
50
+ A connection's `links["company_file"]` is a page where the customer switches the connection to
51
+ another company file (nil for a simulated connection). Offer it as "Use a different company
52
+ file" beside your set-up-again link. It expires with
53
+ `links["onboarding"]`, and `regenerate_onboarding(id)` renews both. After a switch QuBe Sync
54
+ sends `connection.company_file_changed`: stop using every ListID and TxnID you stored for that
55
+ connection (they belong to the old file) and treat it as not connected until
56
+ `connection.connected` arrives again. Then query the new file by those ids: keep each found under
57
+ the same name (a renamed, moved or copied file keeps most of them), ask your customer about each
58
+ found under another name, and treat the rest as not in QuickBooks.
59
+
48
60
  ### Starting a run and answering its question
49
61
 
50
62
  ```ruby
@@ -63,12 +75,66 @@ end
63
75
  ```
64
76
 
65
77
  `get_run(run_url)` or `get_run(connection_id, run_id)` reads a run, `list_runs(connection_id,
66
- reference:, state:, outcome:)` finds runs, `cancel_run(cancel_url, reason: nil)` cancels one, and
78
+ reference:, state:, outcome:)` finds runs, `cancel_run(cancel_url, reason: nil)` cancels one,
79
+ `redeliver_run(connection_id, run_id)` has QuBe Sync send its latest event again (after an
80
+ outage longer than the webhook retries), and
67
81
  `run_events(connection_id, run_id, after:, limit:)` returns a page of its event log whole
68
82
  (`{"data" => [...], "next_after" => ...}`). A method that takes a link takes it from a webhook's
69
83
  or a run's `links`, or a path under `/api/v2`. A link on any other scheme, host or port raises
70
84
  `ArgumentError` before a request is made, so the API key only ever goes to QuBe Sync.
71
85
 
86
+ ### Typed workflow starts
87
+
88
+ `qube_sync workflows` fetches your app's workflow input types (`GET /api/v2/workflows/types`) and
89
+ writes them as Ruby and RBS you check in: a start method per workflow, and per branch of its
90
+ input, whose operation bodies have the same types and field docs as the operation methods below.
91
+
92
+ ```sh
93
+ QUBE_API_KEY=... bundle exec qube_sync workflows # lib/qube_workflows.rb, sig/qube_workflows.rbs
94
+ QUBE_API_KEY=... bundle exec qube_sync workflows --check # in CI: exits 1 when the files are out of date
95
+ ```
96
+
97
+ ```ruby
98
+ require_relative "qube_workflows"
99
+ QubeWorkflows.client = QUBE # once, at boot
100
+
101
+ QubeWorkflows.add_transaction.invoice(connection_id, {
102
+ customer_ref: {list_id: "80000001-1700000000"},
103
+ invoice_line_add: [{item_ref: {full_name: "Consulting"}, amount: "100.00"}]
104
+ }, adds: [{kind: "customer", add: {name: "Acme Ltd"}}],
105
+ reference: "invoice-#{invoice.id}", webhook_url: "https://myapp.example/qube/runs")
106
+
107
+ # The input alone, for start or a QubeRails::Operation's input:
108
+ QubeWorkflows.add_transaction.invoice_input(params, adds: adds)
109
+ ```
110
+
111
+ - A workflow whose input has branches (add_transaction's `operation`, upsert's `kind`) gets one
112
+ method per branch, named by the branch: the discriminator is filled in and the inputs are
113
+ keywords (required ones without defaults), except a workflow's one operation body (add_transaction's
114
+ `params`), which every branch takes positionally; a workflow with two (upsert's `add` and
115
+ `update`) takes both as keywords. `start(connection_id, input, ...)` takes any branch's input. A workflow without
116
+ branches gets `start(connection_id, <inputs as keywords>, reference:, webhook_url:)` and
117
+ `input(...)`. Each `*_input` leaves out nil values. `connection_id` may be anything with a
118
+ `qube_id` (a QubeRails::Connection).
119
+ - Each start takes `reference:`, `webhook_url:`, `version: nil` and `client:` (QubeWorkflows.client
120
+ unless given), and returns the run as `start_run` does.
121
+ - The RBS gives each input a type alias (`QubeWorkflows::AddTransaction::invoice_input`), each
122
+ operation body that operation's params record (`::QubeSync::Operations::Invoice::create_params`)
123
+ and a nested entry with branches (an `adds` item) a union of a record per branch. An operation
124
+ newer than your qube_sync is a plain Hash, with a warning when the served operations aren't the
125
+ gem's. A field the workflow sets itself (QuBe Sync lists them as `set_by_workflow`: upsert's
126
+ `list_id` and `edit_sequence`) is optional in that body, which then gets a record of its own
127
+ (`payment_body`, `customer_update_body`), and its docs say a value given for it is overwritten.
128
+ - QuBe Sync still checks every start: a field the operation doesn't take is a 422 at the call, its
129
+ error's `path` the body (`input.params`) and its `message` naming the field (`unknown parameter:
130
+ "customer_rf"`).
131
+ - `--drafts` types each workflow's draft where it has one, so you can build against a workflow
132
+ before publishing it. The header records the digest and the flag, and `--check` fetches with the
133
+ same flag. When QuBe Sync can't be reached or answers 5xx, `--check` warns and exits 0; a 401
134
+ exits 1.
135
+ - `--output PATH` and `--sig PATH` choose the files; `QUBE_BASE_URL` another host.
136
+ - In Rails, `bin/rails g qube_rails:workflows` (qube_rails) writes the same file into `app/qube/`.
137
+
72
138
  ### Queueing an operation
73
139
 
74
140
  Every QuickBooks operation is a method on its entity: `client.<entity>.<action>`, where the
@@ -110,7 +176,7 @@ QUBE.queue_qbxml(connection_id, request_xml, webhook_url: hook)
110
176
  - A query string repeats an array's key (`list_id=1&list_id=2`) and brackets nested Hashes
111
177
  (`name_range_filter[from_name]=A`, `currency_filter[list_id][]=1`), as the API reads them.
112
178
 
113
- The answer comes to `webhook_url` (see Webhooks below). `get_request(connection_id, id)`,
179
+ The answer comes to `webhook_url` (see Webhooks below). `get_request(connection_id, id)` (or `get_request(link)`),
114
180
  `request_pages(connection_id, id)` and `discard_request(connection_id, id)` act on one request.
115
181
  `list_requests(connection_id, page:, page_size:, state:, ...)` returns a page whole (`{"data" =>
116
182
  [...], "meta" => {"page" => 1, "total_pages" => 3}}`), and `each_request(connection_id, **filters)`
@@ -186,17 +252,26 @@ def handle_qube_webhook(raw_body, header)
186
252
  case event.type
187
253
  when "request"
188
254
  # A queued request's answer. Deduplicate on event.dedupe_key ("<page_request_id>:<state>").
189
- # event.response_json, event.error, event.page, event.iteration_state
255
+ # event.response_json, event.error, event.error_type, event.page, event.iteration_state
256
+ # event.perhaps_applied?: timed_out, outcome_unknown or response_too_large. QuickBooks may
257
+ # have applied it: query the record before sending a write again. A query is safe to resend;
258
+ # page a response_too_large one (iterator, smaller max_returned) or narrow it.
259
+ # event.response_xml_omitted?: the body was over 1 MB, so response_xml is nil;
260
+ # client.response_xml_for(event) fetches it from event.self_link.
190
261
  when "workflow_run"
191
262
  # A run is waiting for an answer, or has ended. Skip it unless event.newer_than?(stored)
192
263
  # for the revision stored with event.reference: deliveries can arrive out of order.
193
- # event.awaiting_input? / completed? / failed? / cancelled?, event.prompt, event.output
264
+ # event.awaiting_input? / completed? / failed? / cancelled?, event.headline, event.prompt,
265
+ # event.outcome, event.output, event.summary["changes"], and on failed? event.error.message
194
266
  when "notification"
195
267
  # Data a running workflow sent. Deduplicate on event.dedupe_key (the delivery_id), and
196
268
  # never skip one by revision. event.name, event.data
197
269
  when "connection"
198
- # Connected, setup cancelled, stalled or resumed. Deduplicate on event.dedupe_key, and skip
199
- # it unless event.newer_than?(the revision stored for event.connection_id).
270
+ # Connected, setup cancelled, stalled, resumed or company file changed. Deduplicate on
271
+ # event.dedupe_key, and skip it unless event.newer_than?(the revision stored for
272
+ # event.connection_id). event.connected? / setup_cancelled? / stalled? / resumed?
273
+ # event.company_file_changed?: set aside the connection's ListIDs/TxnIDs, check them on the
274
+ # new file once connected? arrives again: keep those found under the same name.
200
275
  when "name_index"
201
276
  # event.connection_id, event.name_index
202
277
  else
@@ -217,6 +292,30 @@ end
217
292
  another window, and `now:` (unix seconds or a `Time`) sets the clock, for tests.
218
293
  - Every event has `type`, `event`, `timestamp`, `app_id`, `sandbox`, `dedupe_key` and `to_h`
219
294
  (the whole body). A missing key reads as `nil`, and `event["any_key"]` reads any other key.
295
+ - A request event is `perhaps_applied?` when it `timed_out`, or ended in an `error` whose
296
+ `error_type` is `outcome_unknown` (the Web Connector reported an error mid-write) or
297
+ `response_too_large` (QuickBooks ran it, but its answer was too big to keep). QuickBooks may
298
+ have saved it, so look before you send a create or an update again. A query is safe to
299
+ resend; page a `response_too_large` one (`iterator` and a smaller `max_returned`), or narrow
300
+ it when QuickBooks doesn't page it. Other errors, such as `quickbooks_business_error`,
301
+ `xml_error` or a read's `unexpected_error`, are not, and neither is a `discarded` request.
302
+ - A request event whose body would be over 1 MB comes with `response_xml` nil,
303
+ `response_xml_omitted?` true and `self_link` (its `links.self`, a v1 or v2 URL as the request
304
+ was queued). `response_json` always comes. `client.response_xml_for(event)` returns the
305
+ event's `response_xml`, or fetches it from `self_link` when it was omitted;
306
+ `client.get_request(event.self_link)` returns the whole request.
307
+ - Workflow run and notification events have `headline`, one plain sentence for a person (a log
308
+ line, a status on your page). Never parse it: branch on `event`, `outcome`, `output` and `error`.
309
+ - A failed run's `error` is a `QubeSync::Webhooks::WorkflowRunError` with `code` (QuickBooks'
310
+ status code, such as 3100), `type` (a stable name to branch on, such as `name_in_use`),
311
+ `message` (safe to show), `quickbooks_message` and `hint`; all but `message` may be nil.
312
+ `error["message"]` and `error.to_s` read the message too. An error from an older server, a
313
+ String, reads as one with only `message`; `event["error"]` is the raw value.
314
+ - Each outcome has its own `output`, with only the keys that ending sets. `push_records` ends
315
+ `pushed` or `pushed_with_errors`, with `output["items"]` (one per record, a failed one with its
316
+ own `error` object) and `output["counts"]`. `summary["changes"]` lists what the run changed in
317
+ QuickBooks. `links` holds only the links that work: `decisions` and `search` only while the run
318
+ is `awaiting_input`, `cancel` until it ends.
220
319
  - `QubeSync::Webhooks.parse(raw_body)` builds the event without verifying it, for tests or for
221
320
  code that verified the delivery elsewhere.
222
321
 
data/exe/qube_sync ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ # qube_sync workflows [--drafts] [--check] [--output lib/qube_workflows.rb] [--sig sig/qube_workflows.rbs]
5
+ #
6
+ # Writes your app's typed workflow starts (QubeSync::WorkflowTypes::CLI). QUBE_API_KEY is your
7
+ # app's API key; QUBE_BASE_URL is https://qubesync.com unless set.
8
+
9
+ require "qube_sync/workflow_types"
10
+
11
+ exit QubeSync::WorkflowTypes::CLI.new.run(ARGV)
@@ -159,8 +159,10 @@ module QubeSync
159
159
 
160
160
  # -- Connections ------------------------------------------------------------------------
161
161
 
162
- def create_connection(webhook_url:, name: nil)
163
- call(:post, "/connections", compact(webhook_url: webhook_url, name: name))
162
+ # type: "simulated" makes a connection to a simulated QuickBooks company file, connected as
163
+ # it's made (connection.connected comes at once), for testing with no Windows computer.
164
+ def create_connection(webhook_url:, name: nil, type: nil)
165
+ call(:post, "/connections", compact(webhook_url: webhook_url, name: name, type: type))
164
166
  end
165
167
 
166
168
  def get_connection(id)
@@ -223,12 +225,39 @@ module QubeSync
223
225
  call(:post, cancel_url, compact(reason: reason))
224
226
  end
225
227
 
228
+ # Asks QuBe Sync to send the run's latest event again (its ending, or the question it's
229
+ # waiting on) to the run's webhook URL, signed, with the revision it carries, so a receiver
230
+ # that missed it, or was down for longer than the retries, catches up. Returns
231
+ # `{"run_id", "event", "revision", "webhook_url"}`. A run with nothing to send yet answers
232
+ # 409 (APIError), and one asked again too soon 429.
233
+ def redeliver_run(connection_id, run_id)
234
+ call(:post, "/connections/#{segment(connection_id)}/workflow-runs/#{segment(run_id)}/redeliver")
235
+ end
236
+
226
237
  # Returns the whole body: `{"data" => [...], "next_after" => ...}`.
227
238
  def run_events(connection_id, run_id, after: nil, limit: nil)
228
239
  request(:get, "/connections/#{segment(connection_id)}/workflow-runs/#{segment(run_id)}/events",
229
240
  query: {after: after, limit: limit})
230
241
  end
231
242
 
243
+ # -- Workflow types ---------------------------------------------------------------------
244
+
245
+ # The input types of the app's workflows, which `qube_sync workflows` renders into a typed
246
+ # file (QubeSync::WorkflowTypes). Returns the document (the response's data): `digest`,
247
+ # `operations_digest`, `include_drafts`, `workflows` (each published workflow at its
248
+ # published version) and, with `include_drafts: true`, `drafts` (each workflow whose working
249
+ # copy differs from it). With `etag:` (a document's `digest`, or the ETag it came with),
250
+ # returns :not_modified when the document is still that one.
251
+ def workflow_types(include_drafts: false, etag: nil)
252
+ headers = {}
253
+ headers["If-None-Match"] = entity_tag(etag) unless etag.nil? || etag.to_s.empty?
254
+ call(:get, "/workflows/types", query: {include: include_drafts ? "drafts" : nil}, headers: headers)
255
+ rescue APIError => e
256
+ raise unless e.status == 304
257
+
258
+ :not_modified
259
+ end
260
+
232
261
  # -- Questions --------------------------------------------------------------------------
233
262
 
234
263
  # `decisions_url` is the run's `links.decisions`. It's retried like a GET when the link
@@ -240,9 +269,10 @@ module QubeSync
240
269
  call(:post, decisions_url, compact(choice: choice, data: data), retry_safe: prompt_token?(decisions_url))
241
270
  end
242
271
 
243
- # `search_url` is the run's `links.search`. Returns the matches, an Array.
244
- def search(search_url, field:, q:)
245
- call(:get, search_url, query: {field: field, q: q})
272
+ # `search_url` is the run's `links.search`. Returns the matches, an Array. `row` names the
273
+ # row of a rows field whose column's kind depends on it (`field: "records.list_id"`).
274
+ def search(search_url, field:, q:, row: nil)
275
+ call(:get, search_url, query: compact(field: field, q: q, row: row))
246
276
  end
247
277
 
248
278
  # -- Queued requests --------------------------------------------------------------------
@@ -287,8 +317,24 @@ module QubeSync
287
317
  query: {webhook_url: webhook_url}, headers: {"Idempotency-Key" => key_for(idempotency_key)})
288
318
  end
289
319
 
290
- def get_request(connection_id, id)
291
- call(:get, "/connections/#{segment(connection_id)}/queued-requests/#{segment(id)}")
320
+ # `get_request(connection_id, id)`, or `get_request(link)` for a link such as a request
321
+ # webhook's `links.self` (`event.self_link`), sent when its `response_xml` was omitted.
322
+ def get_request(connection_id_or_link, id = nil)
323
+ if id.nil?
324
+ call(:get, connection_id_or_link)
325
+ else
326
+ call(:get, "/connections/#{segment(connection_id_or_link)}/queued-requests/#{segment(id)}")
327
+ end
328
+ end
329
+
330
+ # A request webhook's `response_xml`: the event's own, or, when it was omitted for size,
331
+ # the one fetched from its `links.self`. nil when the request has none.
332
+ def response_xml_for(event)
333
+ return event.response_xml unless event.response_xml_omitted?
334
+
335
+ link = event.self_link or raise ArgumentError, "response_xml was omitted but the event has no links.self"
336
+ request = get_request(link)
337
+ request.is_a?(Hash) ? request["response_xml"] : nil
292
338
  end
293
339
 
294
340
  def request_pages(connection_id, id)
@@ -563,6 +609,11 @@ module QubeSync
563
609
  parts.map { |part| segment(part) }.join("/")
564
610
  end
565
611
 
612
+ def entity_tag(value)
613
+ text = value.to_s
614
+ (text.start_with?("\"") || text.start_with?("W/")) ? text : "\"#{text}\""
615
+ end
616
+
566
617
  def key_for(idempotency_key)
567
618
  key = idempotency_key.nil? ? SecureRandom.uuid : idempotency_key.to_s
568
619
  raise ArgumentError, "idempotency_key can't be empty" if key.empty?
@@ -35,8 +35,8 @@ module QubeSync
35
35
  # Jones:Kitchen:Cabinets. `full_name` values aren’t case-sensitive.
36
36
  # - `list_id` (String): `list_id` and `full_name` both identify a list object. QuickBooks
37
37
  # assigns `list_id` when the object is created. `list_id` values are unique within a list
38
- # type, not globally across all lists. If both `full_name` and `list_id` are supplied in a
39
- # request, QuickBooks uses `list_id` and ignores `full_name`.
38
+ # family, not across the company file: customers, vendors, employees and other names share
39
+ # one sequence, every item type shares another, and each other list has its own.
40
40
  # - `desc` (String): A descriptive text field.
41
41
  # - `detail_account_type` (one of "AP", "AR", "AccumulatedAdjustment",
42
42
  # "AccumulatedAmortization", "AccumulatedAmortizationOfOtherAssets", "AccumulatedDepletion",
@@ -93,8 +93,8 @@ module QubeSync
93
93
  # Jones:Kitchen:Cabinets. `full_name` values aren’t case-sensitive.
94
94
  # - `list_id` (String): `list_id` and `full_name` both identify a list object. QuickBooks
95
95
  # assigns `list_id` when the object is created. `list_id` values are unique within a list
96
- # type, not globally across all lists. If both `full_name` and `list_id` are supplied in a
97
- # request, QuickBooks uses `list_id` and ignores `full_name`.
96
+ # family, not across the company file: customers, vendors, employees and other names share
97
+ # one sequence, every item type shares another, and each other list has its own.
98
98
  # - `request_id` (String): Your own label for the request, sent to QuickBooks as its qbXML
99
99
  # `requestID` and echoed in the raw answer (`response_xml`); optional, since the answer's
100
100
  # webhook already carries the request's `id`.
@@ -108,8 +108,8 @@ module QubeSync
108
108
  # Jones:Kitchen:Cabinets. `full_name` values aren’t case-sensitive.
109
109
  # - `list_id` (String): `list_id` and `full_name` both identify a list object. QuickBooks
110
110
  # assigns `list_id` when the object is created. `list_id` values are unique within a list
111
- # type, not globally across all lists. If both `full_name` and `list_id` are supplied in a
112
- # request, QuickBooks uses `list_id` and ignores `full_name`.
111
+ # family, not across the company file: customers, vendors, employees and other names share
112
+ # one sequence, every item type shares another, and each other list has its own.
113
113
  # - `tax_line_id` (Integer): An internal representation of the tax line associated with this
114
114
  # account.
115
115
  #
@@ -155,8 +155,9 @@ module QubeSync
155
155
  # example Jones:Kitchen:Cabinets. `full_name` values aren’t case-sensitive.
156
156
  # - `list_id` (Array<String>): `list_id` and `full_name` both identify a list object.
157
157
  # QuickBooks assigns `list_id` when the object is created. `list_id` values are unique
158
- # within a list type, not globally across all lists. If both `full_name` and `list_id` are
159
- # supplied in a request, QuickBooks uses `list_id` and ignores `full_name`.
158
+ # within a list family, not across the company file: customers, vendors, employees and
159
+ # other names share one sequence, every item type shares another, and each other list has
160
+ # its own.
160
161
  # - `from_modified_date` (String): Filters results to objects modified on or after this
161
162
  # timestamp. QuickBooks Desktop accepts 1970-01-01 through 2038-01-19T03:14:07. If only a
162
163
  # date is provided, time defaults to 00:00:00. Choose at most one of: `list_id`, or
@@ -177,10 +178,10 @@ module QubeSync
177
178
  # "Sublevel", "TaxLineInfoRet", "TimeCreated", "TimeModified", "TotalBalance">)
178
179
  # - `list_id` (Array<String>): `list_id` and `full_name` both identify a list object.
179
180
  # QuickBooks assigns `list_id` when the object is created. `list_id` values are unique
180
- # within a list type, not globally across all lists. If both `full_name` and `list_id` are
181
- # supplied in a request, QuickBooks uses `list_id` and ignores `full_name`. Choose at most
182
- # one of: `list_id`, or `full_name`, or the set (`account_type`, `active_status`,
183
- # `currency_filter`, `from_modified_date`, `max_returned`, `name_filter`,
181
+ # within a list family, not across the company file: customers, vendors, employees and other
182
+ # names share one sequence, every item type shares another, and each other list has its own.
183
+ # Choose at most one of: `list_id`, or `full_name`, or the set (`account_type`,
184
+ # `active_status`, `currency_filter`, `from_modified_date`, `max_returned`, `name_filter`,
184
185
  # `name_range_filter`, `to_modified_date`). Members of a set combine with each other, not
185
186
  # with the other choices.
186
187
  # - `max_returned` (Integer): Limits the number of objects that a query returns. (To get a
@@ -266,8 +267,8 @@ module QubeSync
266
267
  # Jones:Kitchen:Cabinets. `full_name` values aren’t case-sensitive.
267
268
  # - `list_id` (String): `list_id` and `full_name` both identify a list object. QuickBooks
268
269
  # assigns `list_id` when the object is created. `list_id` values are unique within a list
269
- # type, not globally across all lists. If both `full_name` and `list_id` are supplied in a
270
- # request, QuickBooks uses `list_id` and ignores `full_name`.
270
+ # family, not across the company file: customers, vendors, employees and other names share
271
+ # one sequence, every item type shares another, and each other list has its own.
271
272
  # - `desc` (String): A descriptive text field.
272
273
  # - `edit_sequence` (String, required): `edit_sequence` is a server-generated revision token.
273
274
  # It changes each time the object is updated. To modify an existing object, you must send
@@ -283,8 +284,8 @@ module QubeSync
283
284
  # QuickBooks. The default value is true.
284
285
  # - `list_id` (String, required): `list_id` and `full_name` both identify a list object.
285
286
  # QuickBooks assigns `list_id` when the object is created. `list_id` values are unique
286
- # within a list type, not globally across all lists. If both `full_name` and `list_id` are
287
- # supplied in a request, QuickBooks uses `list_id` and ignores `full_name`.
287
+ # within a list family, not across the company file: customers, vendors, employees and other
288
+ # names share one sequence, every item type shares another, and each other list has its own.
288
289
  # - `name` (String): Name is the case-insensitive short name of a list object (without
289
290
  # ancestors). It must be unique within its hierarchy scope. Hierarchical lists can reuse the
290
291
  # same Name in different branches because `full_name` remains distinct.
@@ -303,8 +304,8 @@ module QubeSync
303
304
  # Jones:Kitchen:Cabinets. `full_name` values aren’t case-sensitive.
304
305
  # - `list_id` (String): `list_id` and `full_name` both identify a list object. QuickBooks
305
306
  # assigns `list_id` when the object is created. `list_id` values are unique within a list
306
- # type, not globally across all lists. If both `full_name` and `list_id` are supplied in a
307
- # request, QuickBooks uses `list_id` and ignores `full_name`.
307
+ # family, not across the company file: customers, vendors, employees and other names share
308
+ # one sequence, every item type shares another, and each other list has its own.
308
309
  # - `request_id` (String): Your own label for the request, sent to QuickBooks as its qbXML
309
310
  # `requestID` and echoed in the raw answer (`response_xml`); optional, since the answer's
310
311
  # webhook already carries the request's `id`.
@@ -318,8 +319,8 @@ module QubeSync
318
319
  # Jones:Kitchen:Cabinets. `full_name` values aren’t case-sensitive.
319
320
  # - `list_id` (String): `list_id` and `full_name` both identify a list object. QuickBooks
320
321
  # assigns `list_id` when the object is created. `list_id` values are unique within a list
321
- # type, not globally across all lists. If both `full_name` and `list_id` are supplied in a
322
- # request, QuickBooks uses `list_id` and ignores `full_name`.
322
+ # family, not across the company file: customers, vendors, employees and other names share
323
+ # one sequence, every item type shares another, and each other list has its own.
323
324
  # - `tax_line_id` (Integer): An internal representation of the tax line associated with this
324
325
  # account.
325
326
  #
@@ -36,8 +36,8 @@ module QubeSync
36
36
  # Jones:Kitchen:Cabinets. `full_name` values aren’t case-sensitive.
37
37
  # - `list_id` (String): `list_id` and `full_name` both identify a list object. QuickBooks
38
38
  # assigns `list_id` when the object is created. `list_id` values are unique within a list
39
- # type, not globally across all lists. If both `full_name` and `list_id` are supplied in a
40
- # request, QuickBooks uses `list_id` and ignores `full_name`.
39
+ # family, not across the company file: customers, vendors, employees and other names share
40
+ # one sequence, every item type shares another, and each other list has its own.
41
41
  # - `credit_card_txn_info` (Hash): Contains data from the credit card transaction used in the
42
42
  # payment. This data originates from a previous qbmsXML credit card transaction. The data
43
43
  # following the element `credit_card_txn_input_info`” data is the data from the original
@@ -130,8 +130,8 @@ module QubeSync
130
130
  # Jones:Kitchen:Cabinets. `full_name` values aren’t case-sensitive.
131
131
  # - `list_id` (String): `list_id` and `full_name` both identify a list object. QuickBooks
132
132
  # assigns `list_id` when the object is created. `list_id` values are unique within a list
133
- # type, not globally across all lists. If both `full_name` and `list_id` are supplied in a
134
- # request, QuickBooks uses `list_id` and ignores `full_name`.
133
+ # family, not across the company file: customers, vendors, employees and other names share
134
+ # one sequence, every item type shares another, and each other list has its own.
135
135
  # - `def_macro` (String): `def_macro` lets you assign a reusable name to a returned `txn_id`
136
136
  # or TxnLineID so later requests can reference it with `useMacro`. This feature requires SDK
137
137
  # 2.0+.
@@ -156,8 +156,8 @@ module QubeSync
156
156
  # Jones:Kitchen:Cabinets. `full_name` values aren’t case-sensitive.
157
157
  # - `list_id` (String): `list_id` and `full_name` both identify a list object. QuickBooks
158
158
  # assigns `list_id` when the object is created. `list_id` values are unique within a list
159
- # type, not globally across all lists. If both `full_name` and `list_id` are supplied in a
160
- # request, QuickBooks uses `list_id` and ignores `full_name`.
159
+ # family, not across the company file: customers, vendors, employees and other names share
160
+ # one sequence, every item type shares another, and each other list has its own.
161
161
  # - `ref_number` (String): `ref_number` is a user-managed transaction reference (for example,
162
162
  # a check number). It can be edited and is not guaranteed to be globally unique. Some
163
163
  # transaction types auto-populate `ref_number` when omitted, based on QuickBooks preferences
@@ -179,8 +179,8 @@ module QubeSync
179
179
  # Jones:Kitchen:Cabinets. `full_name` values aren’t case-sensitive.
180
180
  # - `list_id` (String): `list_id` and `full_name` both identify a list object. QuickBooks
181
181
  # assigns `list_id` when the object is created. `list_id` values are unique within a list
182
- # type, not globally across all lists. If both `full_name` and `list_id` are supplied in a
183
- # request, QuickBooks uses `list_id` and ignores `full_name`.
182
+ # family, not across the company file: customers, vendors, employees and other names share
183
+ # one sequence, every item type shares another, and each other list has its own.
184
184
  # - `request_id` (String): Your own label for the request, sent to QuickBooks as its qbXML
185
185
  # `requestID` and echoed in the raw answer (`response_xml`); optional, since the answer's
186
186
  # webhook already carries the request's `id`.
@@ -224,8 +224,9 @@ module QubeSync
224
224
  # `full_name_with_children` is exactly the same as `full_name`.
225
225
  # - `list_id` (Array<String>): `list_id` and `full_name` both identify a list object.
226
226
  # QuickBooks assigns `list_id` when the object is created. `list_id` values are unique
227
- # within a list type, not globally across all lists. If both `full_name` and `list_id` are
228
- # supplied in a request, QuickBooks uses `list_id` and ignores `full_name`.
227
+ # within a list family, not across the company file: customers, vendors, employees and
228
+ # other names share one sequence, every item type shares another, and each other list has
229
+ # its own.
229
230
  # - `list_id_with_children` (String): Allows you to filter for data that relates to the
230
231
  # specified object and its descendants.
231
232
  # - `currency_filter` (Hash): Filters by the specified currency. Choose at most one of:
@@ -239,8 +240,9 @@ module QubeSync
239
240
  # example Jones:Kitchen:Cabinets. `full_name` values aren’t case-sensitive.
240
241
  # - `list_id` (Array<String>): `list_id` and `full_name` both identify a list object.
241
242
  # QuickBooks assigns `list_id` when the object is created. `list_id` values are unique
242
- # within a list type, not globally across all lists. If both `full_name` and `list_id` are
243
- # supplied in a request, QuickBooks uses `list_id` and ignores `full_name`.
243
+ # within a list family, not across the company file: customers, vendors, employees and
244
+ # other names share one sequence, every item type shares another, and each other list has
245
+ # its own.
244
246
  # - `entity_filter` (Hash): An entity refers to a person on the QuickBooks Customer list,
245
247
  # Vendor list, Employee list, or Other Names list. You can use an EntityQuery request to get
246
248
  # information about all the entities that are set up in the QuickBooks file. In an
@@ -259,8 +261,9 @@ module QubeSync
259
261
  # `full_name_with_children` is exactly the same as `full_name`.
260
262
  # - `list_id` (Array<String>): `list_id` and `full_name` both identify a list object.
261
263
  # QuickBooks assigns `list_id` when the object is created. `list_id` values are unique
262
- # within a list type, not globally across all lists. If both `full_name` and `list_id` are
263
- # supplied in a request, QuickBooks uses `list_id` and ignores `full_name`.
264
+ # within a list family, not across the company file: customers, vendors, employees and
265
+ # other names share one sequence, every item type shares another, and each other list has
266
+ # its own.
264
267
  # - `list_id_with_children` (String): Allows you to filter for data that relates to the
265
268
  # specified object and its descendants.
266
269
  # - `include_line_items` (Boolean): This filter allows you to omit line items from a query