Skip to content

Commit 6174ab6

Browse files
authored
feat(connections): shadow write policy and the shadow close receipt (#243)
## Summary Regenerated from the server after robosystems #1733 (shadow close) and #1738 (write-policy ladder). These fields reach the hosted API with the next server release after v1.16.5; until then the server rejects `shadow` and omits the new receipt fields. ## Changes - **`SetWritePolicyRequestWritePolicy`** — now `qb_authoritative` or `shadow`. `native` is removed: it is what disconnecting or severing a connection leaves, and the server refuses it for a live connection. - **`ClosePeriodResponse`** — `shadow`, `entries_shadowed`, `gate_findings`, and `gate_finding_counts` (new model `ClosePeriodResponseGateFindingCounts`). - **GraphQL schema** — the close receipt's shadow fields (receipt v2), and on the period-drafts read `shadow`, `shadowedCount`, and each draft's `closeDisposition`. - **Docstrings** — connection creation and the Mercury config describe the per-entity bank-feed rule; `LinkBankAccountResponse.changed`. ## Breaking Changes None in the stable tier. Removing `native` from `SetWritePolicyRequestWritePolicy` is a generated-tier change and rides a client minor; it belongs in the release notes. No facade, the integration template, or the three apps send it. ## Testing - `just test-all`: 667 passed, 17 skipped; ruff, format, and basedpyright clean. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
2 parents a05acbc + 4ec7c3c commit 6174ab6

11 files changed

Lines changed: 207 additions & 37 deletions

‎robosystems_client/api/connections/create_connection.py‎

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,9 @@ def sync_detailed(
113113
allowed per provider per graph, except 'external' which allows one per source_name and 'plaid' which
114114
allows one per bank login (a connection still waiting on Link is returned instead of a second).
115115
Plaid: returns a pending connection — `POST /oauth/init` returns a `link_token` for Plaid Link. A
116-
bank feed (Mercury, Plaid) is refused (409) beside a live QuickBooks connection or on a graph with
117-
no chart of accounts.
116+
bank feed (Mercury, Plaid) names the entity its accounts book to (`entity_id`, the group parent when
117+
omitted) and is refused (409) when that entity has no chart of accounts or is the one QuickBooks
118+
keeps; QuickBooks is refused (409) when the group parent's books are already native.
118119
119120
Args:
120121
graph_id (str):
@@ -154,8 +155,9 @@ def sync(
154155
allowed per provider per graph, except 'external' which allows one per source_name and 'plaid' which
155156
allows one per bank login (a connection still waiting on Link is returned instead of a second).
156157
Plaid: returns a pending connection — `POST /oauth/init` returns a `link_token` for Plaid Link. A
157-
bank feed (Mercury, Plaid) is refused (409) beside a live QuickBooks connection or on a graph with
158-
no chart of accounts.
158+
bank feed (Mercury, Plaid) names the entity its accounts book to (`entity_id`, the group parent when
159+
omitted) and is refused (409) when that entity has no chart of accounts or is the one QuickBooks
160+
keeps; QuickBooks is refused (409) when the group parent's books are already native.
159161
160162
Args:
161163
graph_id (str):
@@ -190,8 +192,9 @@ async def asyncio_detailed(
190192
allowed per provider per graph, except 'external' which allows one per source_name and 'plaid' which
191193
allows one per bank login (a connection still waiting on Link is returned instead of a second).
192194
Plaid: returns a pending connection — `POST /oauth/init` returns a `link_token` for Plaid Link. A
193-
bank feed (Mercury, Plaid) is refused (409) beside a live QuickBooks connection or on a graph with
194-
no chart of accounts.
195+
bank feed (Mercury, Plaid) names the entity its accounts book to (`entity_id`, the group parent when
196+
omitted) and is refused (409) when that entity has no chart of accounts or is the one QuickBooks
197+
keeps; QuickBooks is refused (409) when the group parent's books are already native.
195198
196199
Args:
197200
graph_id (str):
@@ -229,8 +232,9 @@ async def asyncio(
229232
allowed per provider per graph, except 'external' which allows one per source_name and 'plaid' which
230233
allows one per bank login (a connection still waiting on Link is returned instead of a second).
231234
Plaid: returns a pending connection — `POST /oauth/init` returns a `link_token` for Plaid Link. A
232-
bank feed (Mercury, Plaid) is refused (409) beside a live QuickBooks connection or on a graph with
233-
no chart of accounts.
235+
bank feed (Mercury, Plaid) names the entity its accounts book to (`entity_id`, the group parent when
236+
omitted) and is refused (409) when that entity has no chart of accounts or is the one QuickBooks
237+
keeps; QuickBooks is refused (409) when the group parent's books are already native.
234238
235239
Args:
236240
graph_id (str):

‎robosystems_client/api/connections/set_connection_write_policy.py‎

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,13 @@ def sync_detailed(
106106
) -> Response[ConnectionResponse | ErrorResponse | HTTPValidationError]:
107107
"""Set Connection Write Policy
108108
109-
Opt a connection into or out of outbound write-back. 'qb_authoritative' makes QuickBooks the source
110-
of truth — RoboSystems-originated entries (manual JEs, schedule drafts) publish to QuickBooks when
111-
executed or at close. 'native' keeps RoboSystems authoritative with no write-back. This is the
112-
explicit operator opt-in for writing to your books of record.
109+
Choose how a live connection and RoboSystems share the books. 'qb_authoritative', the default, makes
110+
QuickBooks the book of record: RoboSystems-originated entries (manual JEs, schedule drafts) publish
111+
to QuickBooks when executed or at close. 'shadow' keeps QuickBooks the book of record and writes
112+
nothing to it: the close posts nothing locally either, its drafts become shadowed expectations
113+
compared with what QuickBooks holds, and its gates are recorded as findings. 'native' is not a
114+
choice here: it is what disconnecting or severing leaves, books kept in RoboSystems with no
115+
connection to write to. This is the explicit operator opt-in for writing to your books of record.
113116
114117
Args:
115118
graph_id (str):
@@ -149,10 +152,13 @@ def sync(
149152
) -> ConnectionResponse | ErrorResponse | HTTPValidationError | None:
150153
"""Set Connection Write Policy
151154
152-
Opt a connection into or out of outbound write-back. 'qb_authoritative' makes QuickBooks the source
153-
of truth — RoboSystems-originated entries (manual JEs, schedule drafts) publish to QuickBooks when
154-
executed or at close. 'native' keeps RoboSystems authoritative with no write-back. This is the
155-
explicit operator opt-in for writing to your books of record.
155+
Choose how a live connection and RoboSystems share the books. 'qb_authoritative', the default, makes
156+
QuickBooks the book of record: RoboSystems-originated entries (manual JEs, schedule drafts) publish
157+
to QuickBooks when executed or at close. 'shadow' keeps QuickBooks the book of record and writes
158+
nothing to it: the close posts nothing locally either, its drafts become shadowed expectations
159+
compared with what QuickBooks holds, and its gates are recorded as findings. 'native' is not a
160+
choice here: it is what disconnecting or severing leaves, books kept in RoboSystems with no
161+
connection to write to. This is the explicit operator opt-in for writing to your books of record.
156162
157163
Args:
158164
graph_id (str):
@@ -187,10 +193,13 @@ async def asyncio_detailed(
187193
) -> Response[ConnectionResponse | ErrorResponse | HTTPValidationError]:
188194
"""Set Connection Write Policy
189195
190-
Opt a connection into or out of outbound write-back. 'qb_authoritative' makes QuickBooks the source
191-
of truth — RoboSystems-originated entries (manual JEs, schedule drafts) publish to QuickBooks when
192-
executed or at close. 'native' keeps RoboSystems authoritative with no write-back. This is the
193-
explicit operator opt-in for writing to your books of record.
196+
Choose how a live connection and RoboSystems share the books. 'qb_authoritative', the default, makes
197+
QuickBooks the book of record: RoboSystems-originated entries (manual JEs, schedule drafts) publish
198+
to QuickBooks when executed or at close. 'shadow' keeps QuickBooks the book of record and writes
199+
nothing to it: the close posts nothing locally either, its drafts become shadowed expectations
200+
compared with what QuickBooks holds, and its gates are recorded as findings. 'native' is not a
201+
choice here: it is what disconnecting or severing leaves, books kept in RoboSystems with no
202+
connection to write to. This is the explicit operator opt-in for writing to your books of record.
194203
195204
Args:
196205
graph_id (str):
@@ -228,10 +237,13 @@ async def asyncio(
228237
) -> ConnectionResponse | ErrorResponse | HTTPValidationError | None:
229238
"""Set Connection Write Policy
230239
231-
Opt a connection into or out of outbound write-back. 'qb_authoritative' makes QuickBooks the source
232-
of truth — RoboSystems-originated entries (manual JEs, schedule drafts) publish to QuickBooks when
233-
executed or at close. 'native' keeps RoboSystems authoritative with no write-back. This is the
234-
explicit operator opt-in for writing to your books of record.
240+
Choose how a live connection and RoboSystems share the books. 'qb_authoritative', the default, makes
241+
QuickBooks the book of record: RoboSystems-originated entries (manual JEs, schedule drafts) publish
242+
to QuickBooks when executed or at close. 'shadow' keeps QuickBooks the book of record and writes
243+
nothing to it: the close posts nothing locally either, its drafts become shadowed expectations
244+
compared with what QuickBooks holds, and its gates are recorded as findings. 'native' is not a
245+
choice here: it is what disconnecting or severing leaves, books kept in RoboSystems with no
246+
connection to write to. This is the explicit operator opt-in for writing to your books of record.
235247
236248
Args:
237249
graph_id (str):

‎robosystems_client/api/robo_ledger_fiscal_close/close_period.py‎

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,10 @@ def sync_detailed(
120120
isn't set up). Period must be exactly `closed_through + 1` — sequence violations return 422 with
121121
structured `blockers`. Common blockers: `sync_stale` (override with `allow_stale_sync=true` after
122122
manual verification), `period_incomplete` (draft entries unbalanced), `sequence_violation` (out-of-
123-
order).
123+
order). Under a QuickBooks connection whose write_policy is `shadow`, the close observes instead:
124+
nothing is written to QuickBooks or posted, the drafts become `shadowed` expectations
125+
(`entries_shadowed`), and the gates that would have blocked are returned as `gate_findings` rather
126+
than enforced.
124127
125128
**Idempotency**: supply an `Idempotency-Key` header to make safe retries; replays within 24 hours
126129
return the same envelope. Reusing the key with a different body returns HTTP 409 Conflict.
@@ -170,7 +173,10 @@ def sync(
170173
isn't set up). Period must be exactly `closed_through + 1` — sequence violations return 422 with
171174
structured `blockers`. Common blockers: `sync_stale` (override with `allow_stale_sync=true` after
172175
manual verification), `period_incomplete` (draft entries unbalanced), `sequence_violation` (out-of-
173-
order).
176+
order). Under a QuickBooks connection whose write_policy is `shadow`, the close observes instead:
177+
nothing is written to QuickBooks or posted, the drafts become `shadowed` expectations
178+
(`entries_shadowed`), and the gates that would have blocked are returned as `gate_findings` rather
179+
than enforced.
174180
175181
**Idempotency**: supply an `Idempotency-Key` header to make safe retries; replays within 24 hours
176182
return the same envelope. Reusing the key with a different body returns HTTP 409 Conflict.
@@ -215,7 +221,10 @@ async def asyncio_detailed(
215221
isn't set up). Period must be exactly `closed_through + 1` — sequence violations return 422 with
216222
structured `blockers`. Common blockers: `sync_stale` (override with `allow_stale_sync=true` after
217223
manual verification), `period_incomplete` (draft entries unbalanced), `sequence_violation` (out-of-
218-
order).
224+
order). Under a QuickBooks connection whose write_policy is `shadow`, the close observes instead:
225+
nothing is written to QuickBooks or posted, the drafts become `shadowed` expectations
226+
(`entries_shadowed`), and the gates that would have blocked are returned as `gate_findings` rather
227+
than enforced.
219228
220229
**Idempotency**: supply an `Idempotency-Key` header to make safe retries; replays within 24 hours
221230
return the same envelope. Reusing the key with a different body returns HTTP 409 Conflict.
@@ -263,7 +272,10 @@ async def asyncio(
263272
isn't set up). Period must be exactly `closed_through + 1` — sequence violations return 422 with
264273
structured `blockers`. Common blockers: `sync_stale` (override with `allow_stale_sync=true` after
265274
manual verification), `period_incomplete` (draft entries unbalanced), `sequence_violation` (out-of-
266-
order).
275+
order). Under a QuickBooks connection whose write_policy is `shadow`, the close observes instead:
276+
nothing is written to QuickBooks or posted, the drafts become `shadowed` expectations
277+
(`entries_shadowed`), and the gates that would have blocked are returned as `gate_findings` rather
278+
than enforced.
267279
268280
**Idempotency**: supply an `Idempotency-Key` header to make safe retries; replays within 24 hours
269281
return the same envelope. Reusing the key with a different body returns HTTP 409 Conflict.

‎robosystems_client/graphql/schema.graphql‎

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2376,7 +2376,8 @@ type PeriodCloseStatus {
23762376
One schedule's contribution to a period close — drafted closing
23772377
entry plus its reversal (when `auto_reverse=True`).
23782378
2379-
`status` is the closing entry's draft/posted lifecycle. The
2379+
`status` is the closing entry's draft/posted lifecycle (`shadowed` when a
2380+
shadow close took the draft as an expectation and posted nothing). The
23802381
reversal mirrors the same shape with `reversal_*` fields.
23812382
"""
23822383
type PeriodCloseItem {
@@ -2403,7 +2404,9 @@ schema and both SDKs derive from it, and an opaque blob would push the
24032404
shape onto every reader to rediscover.
24042405
"""
24052406
type CloseReceipt {
2406-
"""Receipt schema version; 1 is the first shipped shape"""
2407+
"""
2408+
Receipt schema version; 1 is the first shipped shape, 2 adds the shadow fields
2409+
"""
24072410
version: Int!
24082411

24092412
"""Period this receipt is for (YYYY-MM)"""
@@ -2436,6 +2439,18 @@ type CloseReceipt {
24362439
"""structure_id -> minted fact_set_id"""
24372440
stampedStatementSets: JSON!
24382441
statementRuleSummary: JSON
2442+
2443+
"""
2444+
The close ran in shadow: nothing written to QuickBooks, nothing posted, the drafts shadowed, the gates recorded as findings
2445+
"""
2446+
shadow: Boolean!
2447+
entriesShadowed: Int!
2448+
2449+
"""Blocker codes a shadow close recorded instead of enforcing"""
2450+
gateFindings: [String!]!
2451+
2452+
"""Each finding's size: days stale, or a count"""
2453+
gateFindingCounts: JSON
24392454
}
24402455

24412456
"""
@@ -2610,7 +2625,7 @@ type PeriodDrafts {
26102625
qbWritebackConnectionId: String
26112626

26122627
"""
2613-
write_policy of the publishing QB connection ('qb_authoritative' / 'hybrid'), or null when there is no write-back connection.
2628+
write_policy of the publishing QB connection ('qb_authoritative' / 'hybrid'), 'shadow' when the connection runs in shadow, or null when there is no write-back connection.
26142629
"""
26152630
qbWritePolicy: String
26162631

@@ -2619,6 +2634,14 @@ type PeriodDrafts {
26192634

26202635
"""Number of drafts that post locally only (no QB write-back)."""
26212636
localOnlyCount: Int!
2637+
2638+
"""
2639+
True when the connection runs in shadow: the close writes nothing to QuickBooks and posts nothing; every draft becomes a shadowed expectation compared with what QuickBooks holds.
2640+
"""
2641+
shadow: Boolean!
2642+
2643+
"""Number of drafts the close will shadow (all of them, in shadow)."""
2644+
shadowedCount: Int!
26222645
drafts: [DraftEntry!]!
26232646
}
26242647

@@ -2656,6 +2679,11 @@ type DraftEntry {
26562679
True if closing the period will publish this draft to QuickBooks — i.e. the graph has a qb_authoritative/hybrid QB connection AND this is an RL-originated draft (schedule/manual) not already in QB. False means it posts locally only.
26572680
"""
26582681
willPublishToQb: Boolean!
2682+
2683+
"""
2684+
What the close does with this draft: 'publish' writes it to QuickBooks, 'post' posts it locally, 'shadow' takes it as an expectation with nothing written or posted (a shadow connection).
2685+
"""
2686+
closeDisposition: String!
26592687
}
26602688

26612689
"""A single line item within a draft entry."""

‎robosystems_client/models/__init__.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@
5959
from .classification_lite import ClassificationLite
6060
from .close_period_operation import ClosePeriodOperation
6161
from .close_period_response import ClosePeriodResponse
62+
from .close_period_response_gate_finding_counts import (
63+
ClosePeriodResponseGateFindingCounts,
64+
)
6265
from .close_period_response_rule_summary_type_0 import (
6366
ClosePeriodResponseRuleSummaryType0,
6467
)
@@ -1165,6 +1168,7 @@
11651168
"ClassificationLite",
11661169
"ClosePeriodOperation",
11671170
"ClosePeriodResponse",
1171+
"ClosePeriodResponseGateFindingCounts",
11681172
"ClosePeriodResponseRuleSummaryType0",
11691173
"ClosePeriodResponseStampedStatementSets",
11701174
"ClosePeriodResponseStatementRuleSummaryType0",

0 commit comments

Comments
 (0)