qube_sync 0.3.0 → 0.5.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 (268) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +84 -0
  3. data/README.md +291 -75
  4. data/Rakefile +12 -0
  5. data/exe/qube_sync +11 -0
  6. data/lib/qube_sync/client.rb +614 -0
  7. data/lib/qube_sync/operations/account.rb +338 -0
  8. data/lib/qube_sync/operations/account_tax_line_info.rb +30 -0
  9. data/lib/qube_sync/operations/aging_report.rb +160 -0
  10. data/lib/qube_sync/operations/alert.rb +91 -0
  11. data/lib/qube_sync/operations/ar_refund_credit_card.rb +402 -0
  12. data/lib/qube_sync/operations/bar_code.rb +37 -0
  13. data/lib/qube_sync/operations/bill.rb +1117 -0
  14. data/lib/qube_sync/operations/bill_payment_check.rb +420 -0
  15. data/lib/qube_sync/operations/bill_payment_credit_card.rb +320 -0
  16. data/lib/qube_sync/operations/bill_to_pay.rb +67 -0
  17. data/lib/qube_sync/operations/billing_rate.rb +173 -0
  18. data/lib/qube_sync/operations/budget_summary_report.rb +80 -0
  19. data/lib/qube_sync/operations/build_assembly.rb +319 -0
  20. data/lib/qube_sync/operations/charge.rb +454 -0
  21. data/lib/qube_sync/operations/check.rb +1099 -0
  22. data/lib/qube_sync/operations/class.rb +176 -0
  23. data/lib/qube_sync/operations/cleared_status.rb +39 -0
  24. data/lib/qube_sync/operations/company.rb +39 -0
  25. data/lib/qube_sync/operations/company_activity.rb +31 -0
  26. data/lib/qube_sync/operations/credit_card_charge.rb +1044 -0
  27. data/lib/qube_sync/operations/credit_card_credit.rb +1044 -0
  28. data/lib/qube_sync/operations/credit_memo.rb +1277 -0
  29. data/lib/qube_sync/operations/currency.rb +195 -0
  30. data/lib/qube_sync/operations/custom_detail_report.rb +176 -0
  31. data/lib/qube_sync/operations/custom_summary_report.rb +180 -0
  32. data/lib/qube_sync/operations/customer.rb +745 -0
  33. data/lib/qube_sync/operations/customer_msg.rb +117 -0
  34. data/lib/qube_sync/operations/customer_type.rb +133 -0
  35. data/lib/qube_sync/operations/data_event_recovery_info.rb +54 -0
  36. data/lib/qube_sync/operations/data_ext.rb +202 -0
  37. data/lib/qube_sync/operations/data_ext_def.rb +179 -0
  38. data/lib/qube_sync/operations/date_driven_terms.rb +131 -0
  39. data/lib/qube_sync/operations/deposit.rb +570 -0
  40. data/lib/qube_sync/operations/employee.rb +581 -0
  41. data/lib/qube_sync/operations/employee_default.rb +100 -0
  42. data/lib/qube_sync/operations/entity.rb +118 -0
  43. data/lib/qube_sync/operations/estimate.rb +1084 -0
  44. data/lib/qube_sync/operations/fields.rb +4058 -0
  45. data/lib/qube_sync/operations/form1099_category_account_mapping.rb +91 -0
  46. data/lib/qube_sync/operations/general_detail_report.rb +185 -0
  47. data/lib/qube_sync/operations/general_summary_report.rb +180 -0
  48. data/lib/qube_sync/operations/host.rb +36 -0
  49. data/lib/qube_sync/operations/inventory_adjustment.rb +491 -0
  50. data/lib/qube_sync/operations/inventory_site.rb +214 -0
  51. data/lib/qube_sync/operations/invoice.rb +1242 -0
  52. data/lib/qube_sync/operations/item.rb +115 -0
  53. data/lib/qube_sync/operations/item_assemblies_can_build.rb +44 -0
  54. data/lib/qube_sync/operations/item_discount.rb +320 -0
  55. data/lib/qube_sync/operations/item_fixed_asset.rb +318 -0
  56. data/lib/qube_sync/operations/item_group.rb +255 -0
  57. data/lib/qube_sync/operations/item_inventory.rb +447 -0
  58. data/lib/qube_sync/operations/item_inventory_assembly.rb +486 -0
  59. data/lib/qube_sync/operations/item_non_inventory.rb +472 -0
  60. data/lib/qube_sync/operations/item_other_charge.rb +445 -0
  61. data/lib/qube_sync/operations/item_payment.rb +269 -0
  62. data/lib/qube_sync/operations/item_receipt.rb +1055 -0
  63. data/lib/qube_sync/operations/item_sales_tax.rb +271 -0
  64. data/lib/qube_sync/operations/item_sales_tax_group.rb +200 -0
  65. data/lib/qube_sync/operations/item_service.rb +466 -0
  66. data/lib/qube_sync/operations/item_sites.rb +98 -0
  67. data/lib/qube_sync/operations/item_subtotal.rb +182 -0
  68. data/lib/qube_sync/operations/job_report.rb +156 -0
  69. data/lib/qube_sync/operations/job_type.rb +131 -0
  70. data/lib/qube_sync/operations/journal_entry.rb +533 -0
  71. data/lib/qube_sync/operations/lead.rb +216 -0
  72. data/lib/qube_sync/operations/list.rb +42 -0
  73. data/lib/qube_sync/operations/list_deleted.rb +57 -0
  74. data/lib/qube_sync/operations/list_display.rb +59 -0
  75. data/lib/qube_sync/operations/list_merge.rb +57 -0
  76. data/lib/qube_sync/operations/other_name.rb +245 -0
  77. data/lib/qube_sync/operations/paycheck.rb +139 -0
  78. data/lib/qube_sync/operations/payment_method.rb +129 -0
  79. data/lib/qube_sync/operations/payroll_detail_report.rb +161 -0
  80. data/lib/qube_sync/operations/payroll_item.rb +75 -0
  81. data/lib/qube_sync/operations/payroll_item_addition.rb +98 -0
  82. data/lib/qube_sync/operations/payroll_item_company_contribution.rb +134 -0
  83. data/lib/qube_sync/operations/payroll_item_deduction.rb +124 -0
  84. data/lib/qube_sync/operations/payroll_item_direct_deposit.rb +70 -0
  85. data/lib/qube_sync/operations/payroll_item_non_wage.rb +93 -0
  86. data/lib/qube_sync/operations/payroll_item_tax.rb +123 -0
  87. data/lib/qube_sync/operations/payroll_item_wage.rb +168 -0
  88. data/lib/qube_sync/operations/payroll_item_workers_compensation.rb +108 -0
  89. data/lib/qube_sync/operations/payroll_last_period.rb +30 -0
  90. data/lib/qube_sync/operations/payroll_liability_adjustment.rb +204 -0
  91. data/lib/qube_sync/operations/payroll_liability_check.rb +137 -0
  92. data/lib/qube_sync/operations/payroll_prior_payment.rb +178 -0
  93. data/lib/qube_sync/operations/payroll_summary_report.rb +157 -0
  94. data/lib/qube_sync/operations/payroll_year_to_date_adjustment.rb +211 -0
  95. data/lib/qube_sync/operations/preferences.rb +61 -0
  96. data/lib/qube_sync/operations/price_level.rb +309 -0
  97. data/lib/qube_sync/operations/purchase_order.rb +1065 -0
  98. data/lib/qube_sync/operations/qb_command_exec.rb +37 -0
  99. data/lib/qube_sync/operations/receive_payment.rb +634 -0
  100. data/lib/qube_sync/operations/receive_payment_to_deposit.rb +38 -0
  101. data/lib/qube_sync/operations/sales_order.rb +1072 -0
  102. data/lib/qube_sync/operations/sales_receipt.rb +1371 -0
  103. data/lib/qube_sync/operations/sales_rep.rb +172 -0
  104. data/lib/qube_sync/operations/sales_tax_code.rb +205 -0
  105. data/lib/qube_sync/operations/sales_tax_payable.rb +37 -0
  106. data/lib/qube_sync/operations/sales_tax_payment_check.rb +379 -0
  107. data/lib/qube_sync/operations/sales_tax_return.rb +35 -0
  108. data/lib/qube_sync/operations/sales_tax_return_line.rb +43 -0
  109. data/lib/qube_sync/operations/ship_method.rb +116 -0
  110. data/lib/qube_sync/operations/special_account.rb +55 -0
  111. data/lib/qube_sync/operations/special_item.rb +44 -0
  112. data/lib/qube_sync/operations/standard_terms.rb +125 -0
  113. data/lib/qube_sync/operations/template.rb +36 -0
  114. data/lib/qube_sync/operations/terms.rb +91 -0
  115. data/lib/qube_sync/operations/time_report.rb +127 -0
  116. data/lib/qube_sync/operations/time_tracking.rb +304 -0
  117. data/lib/qube_sync/operations/to_do.rb +260 -0
  118. data/lib/qube_sync/operations/transaction.rb +361 -0
  119. data/lib/qube_sync/operations/transfer.rb +213 -0
  120. data/lib/qube_sync/operations/transfer_inventory.rb +393 -0
  121. data/lib/qube_sync/operations/txn.rb +38 -0
  122. data/lib/qube_sync/operations/txn_deleted.rb +54 -0
  123. data/lib/qube_sync/operations/txn_display.rb +76 -0
  124. data/lib/qube_sync/operations/txn_void.rb +36 -0
  125. data/lib/qube_sync/operations/unit_of_measure_set.rb +149 -0
  126. data/lib/qube_sync/operations/vehicle.rb +152 -0
  127. data/lib/qube_sync/operations/vehicle_mileage.rb +191 -0
  128. data/lib/qube_sync/operations/vendor.rb +663 -0
  129. data/lib/qube_sync/operations/vendor_credit.rb +1052 -0
  130. data/lib/qube_sync/operations/vendor_type.rb +131 -0
  131. data/lib/qube_sync/operations/workers_comp_code.rb +184 -0
  132. data/lib/qube_sync/operations.rb +1169 -0
  133. data/lib/qube_sync/version.rb +1 -1
  134. data/lib/qube_sync/workflow_types/cli.rb +120 -0
  135. data/lib/qube_sync/workflow_types/rbs_renderer.rb +290 -0
  136. data/lib/qube_sync/workflow_types/ruby_renderer.rb +391 -0
  137. data/lib/qube_sync/workflow_types/workflow.rb +153 -0
  138. data/lib/qube_sync/workflow_types.rb +219 -0
  139. data/lib/qube_sync.rb +1 -0
  140. data/sig/qube_sync/client.rbs +85 -0
  141. data/sig/qube_sync/operations/account.rbs +65 -0
  142. data/sig/qube_sync/operations/account_tax_line_info.rbs +13 -0
  143. data/sig/qube_sync/operations/aging_report.rbs +29 -0
  144. data/sig/qube_sync/operations/alert.rbs +53 -0
  145. data/sig/qube_sync/operations/ar_refund_credit_card.rbs +53 -0
  146. data/sig/qube_sync/operations/bar_code.rbs +16 -0
  147. data/sig/qube_sync/operations/bill.rbs +78 -0
  148. data/sig/qube_sync/operations/bill_payment_check.rbs +62 -0
  149. data/sig/qube_sync/operations/bill_payment_credit_card.rbs +45 -0
  150. data/sig/qube_sync/operations/bill_to_pay.rbs +19 -0
  151. data/sig/qube_sync/operations/billing_rate.rbs +40 -0
  152. data/sig/qube_sync/operations/budget_summary_report.rbs +22 -0
  153. data/sig/qube_sync/operations/build_assembly.rbs +64 -0
  154. data/sig/qube_sync/operations/charge.rbs +80 -0
  155. data/sig/qube_sync/operations/check.rbs +81 -0
  156. data/sig/qube_sync/operations/class.rbs +43 -0
  157. data/sig/qube_sync/operations/cleared_status.rbs +16 -0
  158. data/sig/qube_sync/operations/company.rbs +15 -0
  159. data/sig/qube_sync/operations/company_activity.rbs +14 -0
  160. data/sig/qube_sync/operations/credit_card_charge.rbs +69 -0
  161. data/sig/qube_sync/operations/credit_card_credit.rbs +69 -0
  162. data/sig/qube_sync/operations/credit_memo.rbs +162 -0
  163. data/sig/qube_sync/operations/currency.rbs +52 -0
  164. data/sig/qube_sync/operations/custom_detail_report.rbs +31 -0
  165. data/sig/qube_sync/operations/custom_summary_report.rbs +33 -0
  166. data/sig/qube_sync/operations/customer.rbs +174 -0
  167. data/sig/qube_sync/operations/customer_msg.rbs +31 -0
  168. data/sig/qube_sync/operations/customer_type.rbs +32 -0
  169. data/sig/qube_sync/operations/data_event_recovery_info.rbs +20 -0
  170. data/sig/qube_sync/operations/data_ext.rbs +53 -0
  171. data/sig/qube_sync/operations/data_ext_def.rbs +51 -0
  172. data/sig/qube_sync/operations/date_driven_terms.rbs +35 -0
  173. data/sig/qube_sync/operations/deposit.rbs +100 -0
  174. data/sig/qube_sync/operations/employee.rbs +173 -0
  175. data/sig/qube_sync/operations/employee_default.rbs +68 -0
  176. data/sig/qube_sync/operations/entity.rbs +24 -0
  177. data/sig/qube_sync/operations/estimate.rbs +148 -0
  178. data/sig/qube_sync/operations/form1099_category_account_mapping.rbs +33 -0
  179. data/sig/qube_sync/operations/general_detail_report.rbs +31 -0
  180. data/sig/qube_sync/operations/general_summary_report.rbs +32 -0
  181. data/sig/qube_sync/operations/host.rbs +19 -0
  182. data/sig/qube_sync/operations/inventory_adjustment.rbs +105 -0
  183. data/sig/qube_sync/operations/inventory_site.rbs +66 -0
  184. data/sig/qube_sync/operations/invoice.rbs +144 -0
  185. data/sig/qube_sync/operations/item.rbs +25 -0
  186. data/sig/qube_sync/operations/item_assemblies_can_build.rbs +15 -0
  187. data/sig/qube_sync/operations/item_discount.rbs +62 -0
  188. data/sig/qube_sync/operations/item_fixed_asset.rbs +97 -0
  189. data/sig/qube_sync/operations/item_group.rbs +62 -0
  190. data/sig/qube_sync/operations/item_inventory.rbs +87 -0
  191. data/sig/qube_sync/operations/item_inventory_assembly.rbs +94 -0
  192. data/sig/qube_sync/operations/item_non_inventory.rbs +64 -0
  193. data/sig/qube_sync/operations/item_other_charge.rbs +59 -0
  194. data/sig/qube_sync/operations/item_payment.rbs +55 -0
  195. data/sig/qube_sync/operations/item_receipt.rbs +71 -0
  196. data/sig/qube_sync/operations/item_sales_tax.rbs +57 -0
  197. data/sig/qube_sync/operations/item_sales_tax_group.rbs +50 -0
  198. data/sig/qube_sync/operations/item_service.rbs +62 -0
  199. data/sig/qube_sync/operations/item_sites.rbs +26 -0
  200. data/sig/qube_sync/operations/item_subtotal.rbs +48 -0
  201. data/sig/qube_sync/operations/job_report.rbs +28 -0
  202. data/sig/qube_sync/operations/job_type.rbs +32 -0
  203. data/sig/qube_sync/operations/journal_entry.rbs +88 -0
  204. data/sig/qube_sync/operations/lead.rbs +91 -0
  205. data/sig/qube_sync/operations/list.rbs +15 -0
  206. data/sig/qube_sync/operations/list_deleted.rbs +17 -0
  207. data/sig/qube_sync/operations/list_display.rbs +21 -0
  208. data/sig/qube_sync/operations/list_merge.rbs +22 -0
  209. data/sig/qube_sync/operations/other_name.rbs +71 -0
  210. data/sig/qube_sync/operations/paycheck.rbs +27 -0
  211. data/sig/qube_sync/operations/payment_method.rbs +33 -0
  212. data/sig/qube_sync/operations/payroll_detail_report.rbs +29 -0
  213. data/sig/qube_sync/operations/payroll_item.rbs +23 -0
  214. data/sig/qube_sync/operations/payroll_item_addition.rbs +48 -0
  215. data/sig/qube_sync/operations/payroll_item_company_contribution.rbs +58 -0
  216. data/sig/qube_sync/operations/payroll_item_deduction.rbs +54 -0
  217. data/sig/qube_sync/operations/payroll_item_direct_deposit.rbs +30 -0
  218. data/sig/qube_sync/operations/payroll_item_non_wage.rbs +23 -0
  219. data/sig/qube_sync/operations/payroll_item_tax.rbs +58 -0
  220. data/sig/qube_sync/operations/payroll_item_wage.rbs +48 -0
  221. data/sig/qube_sync/operations/payroll_item_workers_compensation.rbs +42 -0
  222. data/sig/qube_sync/operations/payroll_last_period.rbs +13 -0
  223. data/sig/qube_sync/operations/payroll_liability_adjustment.rbs +59 -0
  224. data/sig/qube_sync/operations/payroll_liability_check.rbs +27 -0
  225. data/sig/qube_sync/operations/payroll_prior_payment.rbs +48 -0
  226. data/sig/qube_sync/operations/payroll_summary_report.rbs +30 -0
  227. data/sig/qube_sync/operations/payroll_year_to_date_adjustment.rbs +66 -0
  228. data/sig/qube_sync/operations/preferences.rbs +26 -0
  229. data/sig/qube_sync/operations/price_level.rbs +57 -0
  230. data/sig/qube_sync/operations/purchase_order.rbs +159 -0
  231. data/sig/qube_sync/operations/qb_command_exec.rbs +22 -0
  232. data/sig/qube_sync/operations/receive_payment.rbs +102 -0
  233. data/sig/qube_sync/operations/receive_payment_to_deposit.rbs +15 -0
  234. data/sig/qube_sync/operations/sales_order.rbs +153 -0
  235. data/sig/qube_sync/operations/sales_receipt.rbs +139 -0
  236. data/sig/qube_sync/operations/sales_rep.rbs +43 -0
  237. data/sig/qube_sync/operations/sales_tax_code.rbs +49 -0
  238. data/sig/qube_sync/operations/sales_tax_payable.rbs +16 -0
  239. data/sig/qube_sync/operations/sales_tax_payment_check.rbs +64 -0
  240. data/sig/qube_sync/operations/sales_tax_return.rbs +14 -0
  241. data/sig/qube_sync/operations/sales_tax_return_line.rbs +15 -0
  242. data/sig/qube_sync/operations/ship_method.rbs +31 -0
  243. data/sig/qube_sync/operations/special_account.rbs +16 -0
  244. data/sig/qube_sync/operations/special_item.rbs +17 -0
  245. data/sig/qube_sync/operations/standard_terms.rbs +34 -0
  246. data/sig/qube_sync/operations/template.rbs +15 -0
  247. data/sig/qube_sync/operations/terms.rbs +23 -0
  248. data/sig/qube_sync/operations/time_report.rbs +26 -0
  249. data/sig/qube_sync/operations/time_tracking.rbs +57 -0
  250. data/sig/qube_sync/operations/to_do.rbs +59 -0
  251. data/sig/qube_sync/operations/transaction.rbs +39 -0
  252. data/sig/qube_sync/operations/transfer.rbs +47 -0
  253. data/sig/qube_sync/operations/transfer_inventory.rbs +76 -0
  254. data/sig/qube_sync/operations/txn.rbs +15 -0
  255. data/sig/qube_sync/operations/txn_deleted.rbs +17 -0
  256. data/sig/qube_sync/operations/txn_display.rbs +22 -0
  257. data/sig/qube_sync/operations/txn_void.rbs +15 -0
  258. data/sig/qube_sync/operations/types.rbs +434 -0
  259. data/sig/qube_sync/operations/unit_of_measure_set.rbs +51 -0
  260. data/sig/qube_sync/operations/vehicle.rbs +43 -0
  261. data/sig/qube_sync/operations/vehicle_mileage.rbs +38 -0
  262. data/sig/qube_sync/operations/vendor.rbs +142 -0
  263. data/sig/qube_sync/operations/vendor_credit.rbs +70 -0
  264. data/sig/qube_sync/operations/vendor_type.rbs +32 -0
  265. data/sig/qube_sync/operations/workers_comp_code.rbs +52 -0
  266. data/sig/qube_sync/operations.rbs +148 -0
  267. data/sig/qube_sync/workflow_types.rbs +59 -0
  268. metadata +265 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6d91d913272b0ecdd7f2b2bf91b584e2ab2291841a3badf4641d67d385841b51
4
- data.tar.gz: 00d4062eead7a747ddc51ee0eaf44f5e25799532028b3ed30343ec25f7e7843e
3
+ metadata.gz: dc09f26aabd06f4a7ac423990cc7ae51742aa1ae7731d9e5e7b09a64335b4093
4
+ data.tar.gz: e696f0278123e6546adff8d65ade1547075946038a90f4780b86104e73d09a58
5
5
  SHA512:
6
- metadata.gz: b244afce7cc38609ca0b100fb4f85102c13ca194d7d5cfd61d792950c37402cf84dd28e868830be11060bf5948482607ef206749c9b6c5b7f302da9df2883db6
7
- data.tar.gz: 923cf67564f27f9be8a715ec059bdb4dfa70befc478eaeba7188bfe3a02c203b21b63d68e4db827c3d55727c4070c4c3d7f2c229f603dc75e109a7e6d9e7db8f
6
+ metadata.gz: 25778ea6b1ed553c3fcfa69a402903a2e306f8b1b708ed73a59588258911ad30913d0bf23748fea913fe17823f305ecb684aace696e5696ce1df6ec81c9aff75
7
+ data.tar.gz: 8020665667de1b9d698f11dc73a1bcbda52eb74bfe84558bb08221386ce2f8fc39af1d9e345fae2d5d138f81aa901a18951f42ae2109500e19ffbea6b8e8b13e
data/CHANGELOG.md CHANGED
@@ -1,5 +1,89 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.5.0] - 2026-10-27
4
+
5
+ Typed workflow starts, simulated connections, resending a run's latest event, and per-row search. Nothing
6
+ existing changes: every 0.4.0 call works as it did.
7
+
8
+ ### New
9
+
10
+ - **Typed workflow starts.** `bundle exec qube_sync workflows` (with `QUBE_API_KEY` set) fetches
11
+ your app's workflow input types from QuBe Sync and writes `lib/qube_workflows.rb` and its RBS
12
+ (`sig/qube_workflows.rbs`): a start method and an `*_input` builder for each branch of each
13
+ workflow's input, with every operation body typed as that operation's params
14
+ (`QubeSync::Operations::<Entity>::<action>_params`) and linked to its YARD reference. Fields a
15
+ workflow sets itself (`set_by_workflow`) are optional in its bodies. Options: `--drafts`,
16
+ `--output`, `--sig`, and `--check`, which exits 1 when your file no longer matches what QuBe
17
+ Sync serves (naming the workflows that changed) or on a 401, and warns but exits 0 when QuBe
18
+ Sync can't be reached. The same input always gives byte-identical files, and the generated
19
+ file loads on Ruby 2.7 too. `QubeSync::WorkflowTypes.render` and `.check` do the same from
20
+ code; qube_rails' generator uses them.
21
+ - `Client#workflow_types(include_drafts: false, etag: nil)`: `GET /workflows/types`, returning
22
+ `:not_modified` on a 304.
23
+ - `Client#create_connection(webhook_url:, name: nil, type: nil)`: `type: "simulated"` makes a
24
+ connection to a simulated QuickBooks company file, connected as soon as it's made, for trying
25
+ an integration without QuickBooks Desktop.
26
+ - `Client#redeliver_run(connection_id, run_id)`: `POST .../workflow-runs/{id}/redeliver` has
27
+ QuBe Sync send the run's latest event to your webhook again, for when your endpoint was down
28
+ longer than QuBe Sync's retries.
29
+ - `search(search_url, field:, q:, row: nil)`: `row` names the row of a question's rows field,
30
+ for a search whose kind depends on that row (the missing-records question's per-record search).
31
+ - `QubeSync::Operations::DIGEST`: the sha256 of the QuickBooks operations manifest this version
32
+ was generated from. `qube_sync workflows` warns when QuBe Sync's operations differ from it,
33
+ since operations this version doesn't know are typed as a plain Hash.
34
+
35
+ ### Changed
36
+
37
+ - The per-operation docs now say a QuickBooks `list_id` is unique within a list family, not
38
+ across the company file: customers, vendors, employees and other names share one sequence,
39
+ every item type shares another, and each other list has its own. Key stored ids by
40
+ connection and record kind, never by `list_id` alone.
41
+
42
+ ## [0.4.0] - 2026-10-25
43
+
44
+ Adds `QubeSync::Client`, a client for the v2 API. Nothing existing changes: the v1 module
45
+ functions still call `/api/v1` and read `QUBE_API_KEY` and `QUBE_URL`, and are now documented as
46
+ legacy (no runtime warning). New code should use the client.
47
+
48
+ - `QubeSync::Client.new(api_key:, base_url: "https://qubesync.com", open_timeout: 5,
49
+ read_timeout: 30, max_retries: 2, total_timeout: 60, on_retry: nil)`. It takes the key as an argument and never reads the
50
+ environment, sends it as Basic auth, and never shows it in `inspect`. `require
51
+ "qube_sync/client"` loads it alone, on the standard library (Net::HTTP), without Faraday.
52
+ - Connections: `create_connection`, `get_connection`, `list_connections`, `update_connection`,
53
+ `delete_connection`, `regenerate_onboarding`, `set_password`, `get_qwc`.
54
+ - Runs and questions: `start_run` (its `reference` is the Idempotency-Key), `get_run`,
55
+ `list_runs`, `cancel_run`, `run_events`, `answer`, `search`. Methods that take a link refuse
56
+ one on another scheme, host or port with `ArgumentError`, before any request.
57
+ - QuickBooks operations: one method per operation on its entity, `client.customer.create`,
58
+ `client.invoice.query`, `client.txn_void.execute`... (261 operations on 124 entities;
59
+ QuickBooks' `class` is `client.class_`), each `(connection_id, params = {}, webhook_url:,
60
+ idempotency_key: nil)`. They're generated from the QuickBooks operations manifest
61
+ (`spec/fixtures/operations.json`, served at https://qubesync.com/libraries/operations.json)
62
+ by `bin/generate-operations` (`rake operations:generate`), with YARD docs listing every field
63
+ and RBS records for the params in `sig/qube_sync/operations/`. An entity's file loads on first
64
+ use. CI fails when the generated files or the vendored manifest drift.
65
+ - `queue(operation_id, connection_id, params = {}, webhook_url:, idempotency_key: nil, method:
66
+ nil, path: nil)` queues an operation by its id; `method:` and `path:` send one this version
67
+ doesn't know. A query string repeats an array's key and brackets nested Hashes.
68
+ - Requests: `queue_qbxml`, `get_request`, `request_pages`, `list_requests`, `each_request`
69
+ (every page), `discard_request`; and `request` for anything else. Operations and
70
+ `queue_qbxml` make an Idempotency-Key per call when none is given, and reuse it on that call's
71
+ retries.
72
+ - Signatures for the whole client in `sig/` (`rbs -I sig validate` runs in CI).
73
+ - Retries: a GET, PUT, DELETE or a request with an Idempotency-Key is retried twice (0.5 s, then
74
+ 1 s) on a failed connection, a timeout, or a 429, 502, 503 or 504, honouring `Retry-After` up
75
+ to 30 s. `answer` is retried too when its link has a `prompt_token`. Anything else outside 2xx
76
+ raises `QubeSync::APIError` (a `QubeSync::Error`) with `status`, `errors`, `code`, `message`,
77
+ `body` and `request_id`.
78
+ - A call returns or raises within `total_timeout` (60 s), retries and their waits included: each
79
+ attempt's timeouts are cut to the time left, and no retry is made unless a second is left after
80
+ its wait.
81
+ - `on_retry:` is called before each retry's wait with a frozen Hash (`attempt`, `max_retries`,
82
+ `delay`, `elapsed`, `method`, `url` without its query, `status`, `error`); an exception it
83
+ raises stops the call.
84
+ - A retried DELETE that gets a 404 after an earlier attempt's answer was lost (a read timeout, a
85
+ reset or closed connection, a 502 or 504) returns nil, as a 204 would.
86
+
3
87
  ## [0.3.0] - 2026-10-23
4
88
 
5
89
  Adds `QubeSync::Webhooks`, which verifies a delivery and parses it into a typed event. Nothing
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # QUBESync
2
2
 
3
- A simple wrapper around the QUBE Sync API.
3
+ The Ruby library for the [QuBe Sync](https://qubesync.com) API: a client for the v2 API, and
4
+ webhook verification. The API's docs are at https://docs.qubesync.com.
4
5
 
5
6
  ## Installation
6
7
 
@@ -14,14 +15,301 @@ If bundler is not being used to manage dependencies, install the gem by executin
14
15
 
15
16
  $ gem install qube_sync
16
17
 
17
- ## Configuration
18
+ ## The v2 client
19
+
20
+ `QubeSync::Client` calls the v2 API. Make one from your app's configuration: it never reads the
21
+ environment itself, so one app can hold a sandbox and a production client at once.
22
+
23
+ ```ruby
24
+ require "qube_sync" # or require "qube_sync/client" alone: it uses only the standard library
25
+
26
+ QUBE = QubeSync::Client.new(api_key: ENV.fetch("QUBE_API_KEY"))
27
+ ```
28
+
29
+ `base_url:` (default `"https://qubesync.com"`), `open_timeout:` (5 s), `read_timeout:` (30 s),
30
+ `max_retries:` (2), `total_timeout:` (60 s) and `on_retry:` are options (see Retries below). Every method returns the response's `data`, a plain Hash or Array
31
+ with String keys, and nil for an empty answer.
32
+
33
+ ### Onboarding a customer
34
+
35
+ ```ruby
36
+ connection = QUBE.create_connection(webhook_url: "https://myapp.example/qube/connections", name: "Acme Ltd")
37
+ customer.update!(qube_connection_id: connection["id"])
38
+
39
+ redirect_to connection["links"]["onboarding"], allow_other_host: true
40
+ ```
41
+
42
+ QuBe Sync sends `connection.connected` to the connection's `webhook_url` once the customer's Web
43
+ Connector first checks in. `regenerate_onboarding(id)` makes a fresh onboarding link, and
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`,
47
+ `list_connections`, `delete_connection`, `set_password(id, password: nil)` and `get_qwc(id)` (the
48
+ QWC file's XML) are there for setup without hosted onboarding.
49
+
50
+ ### Starting a run and answering its question
51
+
52
+ ```ruby
53
+ run = QUBE.start_run(
54
+ connection_id, "sync_customer", {"customer" => {"name" => "Acme Ltd"}},
55
+ reference: "customer-#{customer.id}", # also sent as the Idempotency-Key
56
+ webhook_url: "https://myapp.example/qube/runs"
57
+ )
58
+
59
+ # Later, a workflow_run webhook says the run is awaiting input. Its links are the run's own:
60
+ event = QubeSync::Webhooks.verify(raw_body, header, secrets: ENV.fetch("QUBE_WEBHOOK_SECRET"))
61
+ if event.awaiting_input?
62
+ matches = QUBE.search(event.links["search"], field: "customer", q: "Acme") # a record field's choices
63
+ QUBE.answer(event.links["decisions"], choice: "rename", data: {"name" => "Acme Ltd (2)"})
64
+ end
65
+ ```
66
+
67
+ `get_run(run_url)` or `get_run(connection_id, run_id)` reads a run, `list_runs(connection_id,
68
+ reference:, state:, outcome:)` finds runs, `cancel_run(cancel_url, reason: nil)` cancels one,
69
+ `redeliver_run(connection_id, run_id)` has QuBe Sync send its latest event again (after an
70
+ outage longer than the webhook retries), and
71
+ `run_events(connection_id, run_id, after:, limit:)` returns a page of its event log whole
72
+ (`{"data" => [...], "next_after" => ...}`). A method that takes a link takes it from a webhook's
73
+ or a run's `links`, or a path under `/api/v2`. A link on any other scheme, host or port raises
74
+ `ArgumentError` before a request is made, so the API key only ever goes to QuBe Sync.
75
+
76
+ ### Typed workflow starts
77
+
78
+ `qube_sync workflows` fetches your app's workflow input types (`GET /api/v2/workflows/types`) and
79
+ writes them as Ruby and RBS you check in: a start method per workflow, and per branch of its
80
+ input, whose operation bodies have the same types and field docs as the operation methods below.
81
+
82
+ ```sh
83
+ QUBE_API_KEY=... bundle exec qube_sync workflows # lib/qube_workflows.rb, sig/qube_workflows.rbs
84
+ QUBE_API_KEY=... bundle exec qube_sync workflows --check # in CI: exits 1 when the files are out of date
85
+ ```
86
+
87
+ ```ruby
88
+ require_relative "qube_workflows"
89
+ QubeWorkflows.client = QUBE # once, at boot
90
+
91
+ QubeWorkflows.add_transaction.invoice(connection_id, {
92
+ customer_ref: {list_id: "80000001-1700000000"},
93
+ invoice_line_add: [{item_ref: {full_name: "Consulting"}, amount: "100.00"}]
94
+ }, adds: [{kind: "customer", add: {name: "Acme Ltd"}}],
95
+ reference: "invoice-#{invoice.id}", webhook_url: "https://myapp.example/qube/runs")
96
+
97
+ # The input alone, for start or a QubeRails::Operation's input:
98
+ QubeWorkflows.add_transaction.invoice_input(params, adds: adds)
99
+ ```
100
+
101
+ - A workflow whose input has branches (add_transaction's `operation`, upsert's `kind`) gets one
102
+ method per branch, named by the branch: the discriminator is filled in and the inputs are
103
+ keywords (required ones without defaults), except a workflow's one operation body (add_transaction's
104
+ `params`), which every branch takes positionally; a workflow with two (upsert's `add` and
105
+ `update`) takes both as keywords. `start(connection_id, input, ...)` takes any branch's input. A workflow without
106
+ branches gets `start(connection_id, <inputs as keywords>, reference:, webhook_url:)` and
107
+ `input(...)`. Each `*_input` leaves out nil values. `connection_id` may be anything with a
108
+ `qube_id` (a QubeRails::Connection).
109
+ - Each start takes `reference:`, `webhook_url:`, `version: nil` and `client:` (QubeWorkflows.client
110
+ unless given), and returns the run as `start_run` does.
111
+ - The RBS gives each input a type alias (`QubeWorkflows::AddTransaction::invoice_input`), each
112
+ operation body that operation's params record (`::QubeSync::Operations::Invoice::create_params`)
113
+ and a nested entry with branches (an `adds` item) a union of a record per branch. An operation
114
+ newer than your qube_sync is a plain Hash, with a warning when the served operations aren't the
115
+ gem's. A field the workflow sets itself (QuBe Sync lists them as `set_by_workflow`: upsert's
116
+ `list_id` and `edit_sequence`) is optional in that body, which then gets a record of its own
117
+ (`payment_body`, `customer_update_body`), and its docs say a value given for it is overwritten.
118
+ - QuBe Sync still checks every start: a field the operation doesn't take is a 422 at the call, its
119
+ error's `path` the body (`input.params`) and its `message` naming the field (`unknown parameter:
120
+ "customer_rf"`).
121
+ - `--drafts` types each workflow's draft where it has one, so you can build against a workflow
122
+ before publishing it. The header records the digest and the flag, and `--check` fetches with the
123
+ same flag. When QuBe Sync can't be reached or answers 5xx, `--check` warns and exits 0; a 401
124
+ exits 1.
125
+ - `--output PATH` and `--sig PATH` choose the files; `QUBE_BASE_URL` another host.
126
+ - In Rails, `bin/rails g qube_rails:workflows` (qube_rails) writes the same file into `app/qube/`.
127
+
128
+ ### Queueing an operation
129
+
130
+ Every QuickBooks operation is a method on its entity: `client.<entity>.<action>`, where the
131
+ action is `create`, `update`, `query`, `delete` or `execute`.
132
+
133
+ ```ruby
134
+ hook = "https://myapp.example/qube/requests"
135
+
136
+ request = QUBE.customer.create(connection_id, {
137
+ name: "Acme Ltd",
138
+ bill_address: {addr1: "1 Main St", city: "Austin", state: "TX"}
139
+ }, webhook_url: hook)
140
+
141
+ # A query sends its filters as the query string; nested filters are fine.
142
+ QUBE.invoice.query(connection_id, {
143
+ modified_date_range_filter: {from_modified_date: "2026-10-01T00:00:00"},
144
+ include_line_items: true,
145
+ iterator: true, max_returned: 50 # pages of 50, each its own webhook
146
+ }, webhook_url: hook)
147
+
148
+ QUBE.txn_void.execute(connection_id, {txn_void_type: "Invoice", txn_id: "1A2-1700000000"}, webhook_url: hook)
149
+
150
+ # qbXML as written.
151
+ QUBE.queue_qbxml(connection_id, request_xml, webhook_url: hook)
152
+ ```
153
+
154
+ - Each method is `(connection_id, params = {}, webhook_url:, idempotency_key: nil)` and returns
155
+ the queued request. Its documentation (YARD, in `lib/qube_sync/operations/<entity>.rb`) lists
156
+ every field, nested ones included, says whether QuickBooks answers in pages, and links the API
157
+ reference. The params' types are RBS records in `sig/qube_sync/operations/`, for Steep or an
158
+ editor that reads RBS.
159
+ - An entity's file loads the first time you use it, so `require "qube_sync/client"` stays quick.
160
+ - QuickBooks' `class` entity is `client.class_` (`client.class` is Ruby's).
161
+ - `queue(operation_id, connection_id, params = {}, webhook_url:, idempotency_key: nil)` queues one
162
+ by its id: `QUBE.queue("customer.create", connection_id, {name: "Acme Ltd"}, webhook_url: hook)`
163
+ sends the same request as `QUBE.customer.create`. For an operation newer than your version of
164
+ the gem, pass `method:` and `path:` (relative to the connection):
165
+ `QUBE.queue("widget.create", connection_id, params, webhook_url: hook, method: :post, path: "widgets")`.
166
+ - A query string repeats an array's key (`list_id=1&list_id=2`) and brackets nested Hashes
167
+ (`name_range_filter[from_name]=A`, `currency_filter[list_id][]=1`), as the API reads them.
168
+
169
+ The answer comes to `webhook_url` (see Webhooks below). `get_request(connection_id, id)`,
170
+ `request_pages(connection_id, id)` and `discard_request(connection_id, id)` act on one request.
171
+ `list_requests(connection_id, page:, page_size:, state:, ...)` returns a page whole (`{"data" =>
172
+ [...], "meta" => {"page" => 1, "total_pages" => 3}}`), and `each_request(connection_id, **filters)`
173
+ yields every request on every page (an Enumerator without a block).
174
+
175
+ `request(method, path_or_url, body = nil, query: {}, headers: {})` calls anything else and returns
176
+ the whole parsed body.
177
+
178
+ ### Retries, idempotency and errors
179
+
180
+ - A GET, PUT or DELETE, or any request with an `Idempotency-Key`, is retried up to `max_retries`
181
+ times (after 0.5 s, then 1 s) when the connection fails or times out, or QuBe Sync answers 429,
182
+ 502, 503 or 504. A `Retry-After` on a 429 or 503 is honoured, up to 30 s. Other requests
183
+ (`create_connection`, `cancel_run`...) are sent once.
184
+ - A call returns or raises within `total_timeout` (60 s), retries and their waits included: each
185
+ attempt's timeouts are cut to the time left, and a retry is made only when at least a second
186
+ would be left after its wait (a `Retry-After` that doesn't fit isn't waited, nor shortened; the
187
+ call raises what the last attempt got). Pass `max_retries: 0` for calls made while a user waits
188
+ on a page, if 60 s is too long.
189
+ - `answer` is retried when its link has a `prompt_token`, as a run's `links.decisions` always
190
+ does while it asks. A retry after a lost answer may raise a 409 with code `prompt_changed`:
191
+ the question has been answered, by the first attempt or by someone else. Without a
192
+ `prompt_token` it's sent once, since an answer sent again could be taken for the run's next
193
+ question.
194
+ - A retried DELETE (`delete_connection`, or `request(:delete, ...)`) that gets a 404 returns nil,
195
+ as a 204 would, when an earlier attempt's answer was lost after the request could have reached
196
+ QuBe Sync (a read timeout, a connection reset or closed, a 502 or 504): that attempt deleted it.
197
+ Any other 404 raises, including a retry's after a refused connection, a connect timeout, a 429
198
+ or a 503.
199
+ - `on_retry:` takes a callable, called before each retry's wait with a frozen Hash: `attempt`
200
+ (1, 2...), `max_retries`, `delay` and `elapsed` (seconds), `method`, `url` (without its query
201
+ string), `status` (for a status retry) and `error` (for a network failure), and never the key,
202
+ headers or body. It isn't called when no retry is made. An exception it raises stops the call
203
+ and reaches the caller.
204
+
205
+ ```ruby
206
+ QubeSync::Client.new(api_key: ENV.fetch("QUBE_API_KEY"),
207
+ on_retry: ->(r) { Rails.logger.warn("QuBe Sync retry #{r[:attempt]}/#{r[:max_retries]} #{r[:method]} #{r[:url]} #{r[:status] || r[:error].class}") })
208
+ ```
209
+ - `start_run` sends `reference` as the Idempotency-Key. `queue` and `queue_qbxml` take
210
+ `idempotency_key:`; without one the client makes a UUID per call and sends it again on that
211
+ call's retries, so a retry never queues a request twice.
212
+ - Any other answer outside 2xx raises `QubeSync::APIError` (a `QubeSync::Error`): `status`,
213
+ `errors` (the body's `errors` as parsed), `code` (`errors["code"]`, such as `prompt_changed`, or
214
+ nil), `message` (one line, safe to log), `body` and `request_id` (the `x-request-id` header, for
215
+ support). A connection that still fails after the retries raises Ruby's own error
216
+ (`Net::OpenTimeout`, `Net::ReadTimeout`, `Errno::ECONNREFUSED`...).
217
+ - The API key never appears in an error or in `inspect`.
218
+
219
+ ```ruby
220
+ begin
221
+ QUBE.answer(decisions_url, choice: "rename")
222
+ rescue QubeSync::APIError => e
223
+ raise unless e.code == "prompt_changed" # the question changed: show the new one
224
+ refresh_question(run)
225
+ end
226
+ ```
227
+
228
+ ## Webhooks
229
+
230
+ `QubeSync::Webhooks` verifies a delivery's `X-QUBE-Signature` header and parses the body into a
231
+ typed event. It doesn't need Rails or Rack, and never reads the environment: pass it the raw body,
232
+ the header and your webhook secret.
233
+
234
+ ```ruby
235
+ require "qube_sync"
236
+
237
+ # raw_body: the request body exactly as received, before anything parses it.
238
+ # header: the X-QUBE-Signature header (nil when it's absent).
239
+ def handle_qube_webhook(raw_body, header)
240
+ event = QubeSync::Webhooks.verify(raw_body, header, secrets: ENV.fetch("QUBE_WEBHOOK_SECRET"))
241
+
242
+ case event.type
243
+ when "request"
244
+ # A queued request's answer. Deduplicate on event.dedupe_key ("<page_request_id>:<state>").
245
+ # event.response_json, event.error, event.page, event.iteration_state
246
+ when "workflow_run"
247
+ # A run is waiting for an answer, or has ended. Skip it unless event.newer_than?(stored)
248
+ # for the revision stored with event.reference: deliveries can arrive out of order.
249
+ # event.awaiting_input? / completed? / failed? / cancelled?, event.prompt, event.output
250
+ when "notification"
251
+ # Data a running workflow sent. Deduplicate on event.dedupe_key (the delivery_id), and
252
+ # never skip one by revision. event.name, event.data
253
+ when "connection"
254
+ # Connected, setup cancelled, stalled or resumed. Deduplicate on event.dedupe_key, and skip
255
+ # it unless event.newer_than?(the revision stored for event.connection_id).
256
+ when "name_index"
257
+ # event.connection_id, event.name_index
258
+ else
259
+ # An event this version doesn't know yet: acknowledge it.
260
+ end
261
+
262
+ 200
263
+ rescue QubeSync::Webhooks::SignatureError => e
264
+ # e.reason is :missing, :malformed, :stale or :mismatch. The message is safe to log.
265
+ warn "QuBe Sync webhook refused: #{e.message}"
266
+ 401
267
+ end
268
+ ```
269
+
270
+ - `secrets:` takes one secret or a list. While a secret rotates, a delivery carries one `v1`
271
+ signature per active secret, and either secret verifies it.
272
+ - The timestamp must be within 300 seconds of now, either way. `tolerance:` (seconds) sets
273
+ another window, and `now:` (unix seconds or a `Time`) sets the clock, for tests.
274
+ - Every event has `type`, `event`, `timestamp`, `app_id`, `sandbox`, `dedupe_key` and `to_h`
275
+ (the whole body). A missing key reads as `nil`, and `event["any_key"]` reads any other key.
276
+ - `QubeSync::Webhooks.parse(raw_body)` builds the event without verifying it, for tests or for
277
+ code that verified the delivery elsewhere.
278
+
279
+ In Rails, read the raw body with `request.raw_post`:
280
+
281
+ ```ruby
282
+ class QubeWebhooksController < ActionController::API
283
+ def create
284
+ event = QubeSync::Webhooks.verify(
285
+ request.raw_post,
286
+ request.headers[QubeSync::Webhooks::HEADER],
287
+ secrets: Rails.application.credentials.qube_webhook_secret
288
+ )
289
+ QubeWebhookJob.perform_later(event.to_h) # route by type in the job, as above
290
+ head :ok
291
+ rescue QubeSync::Webhooks::SignatureError => e
292
+ Rails.logger.warn("QuBe Sync webhook refused: #{e.message}")
293
+ head :unauthorized
294
+ end
295
+ end
296
+ ```
297
+
298
+ `QubeSync.verify_and_build_webhook!` (0.2.4) still works, and still returns the parsed Hash.
299
+
300
+ ## v1 (legacy)
301
+
302
+ The v1 module functions below call `/api/v1` and still work, but the v2 client above is the one to
303
+ use for new code.
304
+
305
+ ### Configuration
18
306
 
19
307
  You'll need to set two evironment variables in your application to use this gem:
20
308
 
21
309
  `QUBE_API_KEY` - This is your API key, which you can find in your QUBE Sync application's settings.
22
310
  `QUBE_WEBHOOK_SECRET` - This is the secret key used to sign the webhook payloads. You can find this in your QUBE Sync application's settings.
23
311
 
24
- ## Usage
312
+ ### Usage
25
313
 
26
314
  ```ruby
27
315
  require 'qube_sync'
@@ -128,78 +416,6 @@ QubeSync.verify_and_build_webhook!(request.body.read, request.headers['X-Qube-Si
128
416
  QubeSync.verify_and_build_webhook!(request.body.read, request.headers['X-Qube-Signature'], max_age: 120)
129
417
  ```
130
418
 
131
- ## Webhooks
132
-
133
- `QubeSync::Webhooks` verifies a delivery's `X-QUBE-Signature` header and parses the body into a
134
- typed event. It doesn't need Rails or Rack, and never reads the environment: pass it the raw body,
135
- the header and your webhook secret.
136
-
137
- ```ruby
138
- require "qube_sync"
139
-
140
- # raw_body: the request body exactly as received, before anything parses it.
141
- # header: the X-QUBE-Signature header (nil when it's absent).
142
- def handle_qube_webhook(raw_body, header)
143
- event = QubeSync::Webhooks.verify(raw_body, header, secrets: ENV.fetch("QUBE_WEBHOOK_SECRET"))
144
-
145
- case event.type
146
- when "request"
147
- # A queued request's answer. Deduplicate on event.dedupe_key ("<page_request_id>:<state>").
148
- # event.response_json, event.error, event.page, event.iteration_state
149
- when "workflow_run"
150
- # A run is waiting for an answer, or has ended. Skip it unless event.newer_than?(stored)
151
- # for the revision stored with event.reference: deliveries can arrive out of order.
152
- # event.awaiting_input? / completed? / failed? / cancelled?, event.prompt, event.output
153
- when "notification"
154
- # Data a running workflow sent. Deduplicate on event.dedupe_key (the delivery_id), and
155
- # never skip one by revision. event.name, event.data
156
- when "connection"
157
- # Connected, setup cancelled, stalled or resumed. Deduplicate on event.dedupe_key, and skip
158
- # it unless event.newer_than?(the revision stored for event.connection_id).
159
- when "name_index"
160
- # event.connection_id, event.name_index
161
- else
162
- # An event this version doesn't know yet: acknowledge it.
163
- end
164
-
165
- 200
166
- rescue QubeSync::Webhooks::SignatureError => e
167
- # e.reason is :missing, :malformed, :stale or :mismatch. The message is safe to log.
168
- warn "QuBe Sync webhook refused: #{e.message}"
169
- 401
170
- end
171
- ```
172
-
173
- - `secrets:` takes one secret or a list. While a secret rotates, a delivery carries one `v1`
174
- signature per active secret, and either secret verifies it.
175
- - The timestamp must be within 300 seconds of now, either way. `tolerance:` (seconds) sets
176
- another window, and `now:` (unix seconds or a `Time`) sets the clock, for tests.
177
- - Every event has `type`, `event`, `timestamp`, `app_id`, `sandbox`, `dedupe_key` and `to_h`
178
- (the whole body). A missing key reads as `nil`, and `event["any_key"]` reads any other key.
179
- - `QubeSync::Webhooks.parse(raw_body)` builds the event without verifying it, for tests or for
180
- code that verified the delivery elsewhere.
181
-
182
- In Rails, read the raw body with `request.raw_post`:
183
-
184
- ```ruby
185
- class QubeWebhooksController < ActionController::API
186
- def create
187
- event = QubeSync::Webhooks.verify(
188
- request.raw_post,
189
- request.headers[QubeSync::Webhooks::HEADER],
190
- secrets: Rails.application.credentials.qube_webhook_secret
191
- )
192
- QubeWebhookJob.perform_later(event.to_h) # route by type in the job, as above
193
- head :ok
194
- rescue QubeSync::Webhooks::SignatureError => e
195
- Rails.logger.warn("QuBe Sync webhook refused: #{e.message}")
196
- head :unauthorized
197
- end
198
- end
199
- ```
200
-
201
- `QubeSync.verify_and_build_webhook!` (0.2.4) still works, and still returns the parsed Hash.
202
-
203
419
  ## Development
204
420
 
205
421
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
data/Rakefile CHANGED
@@ -6,3 +6,15 @@ require "rspec/core/rake_task"
6
6
  RSpec::Core::RakeTask.new(:spec)
7
7
 
8
8
  task default: :spec
9
+
10
+ namespace :operations do
11
+ desc "Write the per-operation methods and signatures from spec/fixtures/operations.json"
12
+ task :generate do
13
+ ruby "bin/generate-operations"
14
+ end
15
+
16
+ desc "Fail when the generated operations are stale, missing or orphaned"
17
+ task :check do
18
+ ruby "bin/generate-operations", "--check"
19
+ end
20
+ end
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)