|
1 | 1 | # qbwc-common |
2 | | -QBWC logic shared between tap and target |
| 2 | + |
| 3 | +Shared Python library for QuickBooks Desktop Web Connector (QBWC) used by [`tap-qbwc`](https://github.com/hotgluexyz/tap-qbwc) and [`target-qbwc`](https://github.com/hotgluexyz/target-qbwc). |
| 4 | + |
| 5 | +Repository: [github.com/hotgluexyz/qbwc-common](https://github.com/hotgluexyz/qbwc-common) |
| 6 | + |
| 7 | +It centralises transport to the QBWC SOAP service, the bundled Intuit qbXML 13.0 XSD set, and the encode/decode helpers both connectors build on. |
| 8 | + |
| 9 | +## What's included |
| 10 | + |
| 11 | +| Module | Responsibility | |
| 12 | +|---|---| |
| 13 | +| `client.py` | `QBWCClient`: authenticate, enqueue qbXML, long-poll for responses | |
| 14 | +| `qbxml.py` | Encode requests and decode responses against the XSD; `merge_request_elements`, `normalize_rs_list`, `parse_rs_element` | |
| 15 | +| `mod_merge.py` | XSD-driven filtering for `*Mod` payloads (`get_mod_element_names`, `filter_dict_for_mod`, `get_ret_only_field_names`) | |
| 16 | +| `qbxml_encode_errors.py` | User-facing messages for XSD encode validation failures (`format_encode_validation_error`) | |
| 17 | +| `config.py` | Shared config contract, defaults, and sandbox/production base URLs | |
| 18 | +| `exceptions.py` | `QBWC*` transport errors and `QBXML*` encode/decode errors | |
| 19 | +| `qbd_xml_schemas/` | Bundled `qbxmlops130.xsd` and dependencies (qbXML 13.0) | |
| 20 | + |
| 21 | +Public exports live in `qbwc_common.__init__`. Import from `qbwc_common` in connector code. |
| 22 | + |
| 23 | +## Installation |
| 24 | + |
| 25 | +```bash |
| 26 | +git clone https://github.com/hotgluexyz/qbwc-common.git |
| 27 | +cd qbwc-common |
| 28 | +python -m venv .venv |
| 29 | +source .venv/bin/activate |
| 30 | +pip install -e ".[dev]" |
| 31 | +``` |
| 32 | + |
| 33 | +Connectors declare a dependency on this package. For local work on both repos, clone `qbwc-common` as a sibling directory and install it before the tap or target. |
| 34 | + |
| 35 | +## Configuration |
| 36 | + |
| 37 | +Shared keys consumed by `QBWCClient` (connectors may add their own settings on top): |
| 38 | + |
| 39 | +| Key | Required | Default | Description | |
| 40 | +|---|---|---|---| |
| 41 | +| `token` | yes | | Base64 connector token for the QBWC SOAP service | |
| 42 | +| `request_timeout` | no | `1200` | Seconds a QBWC request may take before timeout | |
| 43 | +| `is_sandbox` | no | `false` | Use `qbwc-qa.hotglue.xyz` instead of `qbwc.hotglue.com` | |
| 44 | +| `qbwc_is_alive_timeout` | no | `3600` | Timeout for the optional `HostQueryRq` liveness check | |
| 45 | + |
| 46 | +Example: |
| 47 | + |
| 48 | +```json |
| 49 | +{ |
| 50 | + "token": "your_base64_connector_token", |
| 51 | + "is_sandbox": true, |
| 52 | + "request_timeout": 1200 |
| 53 | +} |
| 54 | +``` |
| 55 | + |
| 56 | +## Usage |
| 57 | + |
| 58 | +### Client and qbXML round-trip |
| 59 | + |
| 60 | +```python |
| 61 | +from qbwc_common import QBWCClient, load_qbd_xml_schemas |
| 62 | + |
| 63 | +schemas = load_qbd_xml_schemas() |
| 64 | +client = QBWCClient(config, schemas, logger=my_logger) |
| 65 | +client.create_session() |
| 66 | +client.check_qbwc_is_alive() # optional HostQueryRq ping |
| 67 | +response = client.make_request({"HostQueryRq": {}}) |
| 68 | +``` |
| 69 | + |
| 70 | +`make_request` encodes dict-shaped request elements, sends them through QBWC, and returns the decoded `QBXMLMsgsRs` body. Use `send_qbxml` when you already have a qbXML string. |
| 71 | + |
| 72 | +### Batched writes |
| 73 | + |
| 74 | +Pass a list of single-key request dicts. Set `on_error="continueOnError"` so one failed record does not abort the batch. Give each record a `@requestID` attribute; QuickBooks echoes it on the matching `*Rs`. |
| 75 | + |
| 76 | +For write responses with partial `*Ret` payloads, pass `decode_validation="skip"` (the tap defaults to strict decode on reads). |
| 77 | + |
| 78 | +```python |
| 79 | +from qbwc_common import ON_ERROR_CONTINUE |
| 80 | + |
| 81 | +requests = [ |
| 82 | + { |
| 83 | + "CustomerAddRq": { |
| 84 | + "@requestID": "0", |
| 85 | + "CustomerAdd": {"Name": "Customer A", "CompanyName": "A Co"}, |
| 86 | + } |
| 87 | + }, |
| 88 | + { |
| 89 | + "CustomerAddRq": { |
| 90 | + "@requestID": "1", |
| 91 | + "CustomerAdd": {"Name": "Customer B", "CompanyName": "B Co"}, |
| 92 | + } |
| 93 | + }, |
| 94 | +] |
| 95 | +response = client.make_request( |
| 96 | + requests, |
| 97 | + on_error=ON_ERROR_CONTINUE, |
| 98 | + decode_validation="skip", |
| 99 | +) |
| 100 | +``` |
| 101 | + |
| 102 | +### Mod payload merge |
| 103 | + |
| 104 | +After a query returns a `*Ret` record, strip read-only fields before overlaying incoming changes onto a `*Mod` payload: |
| 105 | + |
| 106 | +```python |
| 107 | +from qbwc_common import filter_dict_for_mod, get_mod_element_names |
| 108 | + |
| 109 | +allowed = get_mod_element_names(schemas, "CustomerMod") |
| 110 | +incoming = filter_dict_for_mod(payload, allowed) |
| 111 | +merged = {**filter_dict_for_mod(existing_ret, allowed), **incoming} |
| 112 | +merged["ListID"] = existing_ret["ListID"] |
| 113 | +merged["EditSequence"] = existing_ret["EditSequence"] |
| 114 | +``` |
| 115 | + |
| 116 | +`get_ret_only_field_names` returns `*Ret` fields that are not valid on the matching `*Mod` element. |
| 117 | + |
| 118 | +### Response parsing |
| 119 | + |
| 120 | +```python |
| 121 | +from qbwc_common import normalize_rs_list, parse_rs_element |
| 122 | + |
| 123 | +for rs in normalize_rs_list(response, "CustomerAddRs"): |
| 124 | + parsed = parse_rs_element(rs) |
| 125 | + # parsed: request_id, status_code, status_message, entity_key, entity |
| 126 | +``` |
| 127 | + |
| 128 | +## Development |
| 129 | + |
| 130 | +```bash |
| 131 | +tox |
| 132 | +``` |
| 133 | + |
| 134 | +Or run tools directly: |
| 135 | + |
| 136 | +```bash |
| 137 | +.venv/bin/ruff check . |
| 138 | +.venv/bin/pytest tests/ |
| 139 | +``` |
| 140 | + |
| 141 | +Related repos: |
| 142 | + |
| 143 | +- [`tap-qbwc`](https://github.com/hotgluexyz/tap-qbwc): Singer tap for reading from QuickBooks Desktop via QBWC |
| 144 | +- [`target-qbwc`](https://github.com/hotgluexyz/target-qbwc): Singer target for writing QuickBooks-shaped records via QBWC |
0 commit comments