@robosystems/client 2.5.3 → 2.6.1

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.
@@ -13,13 +13,16 @@
13
13
  * Code Generator). The graph is in the URL, not in the query.
14
14
  * - **Writes** go through named command operations at
15
15
  * `/extensions/roboledger/{graph_id}/operations/{operation_name}`
16
- * (via the OpenAPI-generated command functions in `../sdk/sdk.gen`).
16
+ * (via the OpenAPI-generated command functions in `../sdk/sdk.gen`,
17
+ * called with this facade's own `baseUrl`, credential and headers).
17
18
  * Each command returns an `OperationEnvelope`; the facade unwraps
18
- * `envelope.result` and returns a friendly camelCase type.
19
+ * `envelope.result`.
19
20
  *
20
21
  * Consumers don't need to know which transport a method uses — the
21
- * facade signature stays stable. The only trick is that write method
22
- * results are cast from the envelope's untyped `result` field.
22
+ * facade signature stays stable. Most write results are the generated
23
+ * (snake_case) response types the typed envelopes carry; a few are
24
+ * mapped to the camelCase read shapes, and ops whose envelope `result`
25
+ * is untyped are cast to a local raw type before mapping.
23
26
  */
24
27
 
25
28
  import type { TypedDocumentNode } from '@graphql-typed-document-node/core'
@@ -249,6 +252,7 @@ import {
249
252
  type ReportDownloadFormat,
250
253
  type ReportLifecycle,
251
254
  } from './graphql/generated/graphql'
255
+ import { restCallOptions, withIdempotencyKey, type RestCallOptions } from './rest'
252
256
 
253
257
  // Re-export the structured GraphQL error type so consumers importing
254
258
  // from the `@robosystems/client/ledger` subpath can `instanceof` it.
@@ -741,7 +745,7 @@ interface LedgerClientConfig {
741
745
  token?: string
742
746
  /**
743
747
  * Dynamic credential callback. When set, invoked on every GraphQL
744
- * request so refreshes flow through automatically.
748
+ * request and REST write so refreshes flow through automatically.
745
749
  */
746
750
  tokenProvider?: TokenProvider
747
751
  /** GraphQL request timeout in milliseconds (default 60s). */
@@ -805,12 +809,8 @@ export class LedgerClient {
805
809
  * Returns the updated entity.
806
810
  */
807
811
  async updateEntity(graphId: string, updates: UpdateEntityRequest): Promise<LedgerEntity> {
808
- const envelope = await this.callOperation(
809
- 'Update entity',
810
- updateEntity({
811
- path: { graph_id: graphId },
812
- body: updates,
813
- })
812
+ const envelope = await this.callOperation('Update entity', (o) =>
813
+ updateEntity({ ...o, path: { graph_id: graphId }, body: updates })
814
814
  )
815
815
  // The REST envelope carries LedgerEntityResponse (snake_case); LedgerEntity
816
816
  // is the GraphQL camelCase shape that getEntity returns. The old
@@ -1145,9 +1145,8 @@ export class LedgerClient {
1145
1145
  graphId: string,
1146
1146
  body: LinkEntityTaxonomyRequest
1147
1147
  ): Promise<EntityTaxonomyResponse> {
1148
- const envelope = await this.callOperation(
1149
- 'Link entity taxonomy',
1150
- linkEntityTaxonomy({ path: { graph_id: graphId }, body })
1148
+ const envelope = await this.callOperation('Link entity taxonomy', (o) =>
1149
+ linkEntityTaxonomy({ ...o, path: { graph_id: graphId }, body })
1151
1150
  )
1152
1151
  return this.requireResult('Link entity taxonomy', envelope.result)
1153
1152
  }
@@ -1161,10 +1160,12 @@ export class LedgerClient {
1161
1160
  body: CreateTaxonomyBlockRequest,
1162
1161
  idempotencyKey?: string
1163
1162
  ): Promise<TaxonomyBlockEnvelope> {
1164
- const headers = idempotencyKey ? { 'Idempotency-Key': idempotencyKey } : undefined
1165
- const envelope = await this.callOperation(
1166
- 'Create taxonomy block',
1167
- createTaxonomyBlock({ path: { graph_id: graphId }, body, headers })
1163
+ const envelope = await this.callOperation('Create taxonomy block', (o) =>
1164
+ createTaxonomyBlock({
1165
+ ...withIdempotencyKey(o, idempotencyKey),
1166
+ path: { graph_id: graphId },
1167
+ body,
1168
+ })
1168
1169
  )
1169
1170
  return this.requireResult('Create taxonomy block', envelope.result)
1170
1171
  }
@@ -1174,9 +1175,8 @@ export class LedgerClient {
1174
1175
  graphId: string,
1175
1176
  body: UpdateTaxonomyBlockRequest
1176
1177
  ): Promise<TaxonomyBlockEnvelope> {
1177
- const envelope = await this.callOperation(
1178
- 'Update taxonomy block',
1179
- updateTaxonomyBlock({ path: { graph_id: graphId }, body })
1178
+ const envelope = await this.callOperation('Update taxonomy block', (o) =>
1179
+ updateTaxonomyBlock({ ...o, path: { graph_id: graphId }, body })
1180
1180
  )
1181
1181
  return this.requireResult('Update taxonomy block', envelope.result)
1182
1182
  }
@@ -1186,9 +1186,8 @@ export class LedgerClient {
1186
1186
  graphId: string,
1187
1187
  body: DeleteTaxonomyBlockRequest
1188
1188
  ): Promise<DeleteTaxonomyBlockResponse> {
1189
- const envelope = await this.callOperation(
1190
- 'Delete taxonomy block',
1191
- deleteTaxonomyBlock({ path: { graph_id: graphId }, body })
1189
+ const envelope = await this.callOperation('Delete taxonomy block', (o) =>
1190
+ deleteTaxonomyBlock({ ...o, path: { graph_id: graphId }, body })
1192
1191
  )
1193
1192
  return (envelope.result ?? { deleted: true }) as DeleteTaxonomyBlockResponse
1194
1193
  }
@@ -1204,10 +1203,8 @@ export class LedgerClient {
1204
1203
  body: BindTextBlockRequest,
1205
1204
  idempotencyKey?: string
1206
1205
  ): Promise<BindTextBlockResponse> {
1207
- const headers = idempotencyKey ? { 'Idempotency-Key': idempotencyKey } : undefined
1208
- const envelope = await this.callOperation(
1209
- 'Bind text block',
1210
- bindTextBlock({ path: { graph_id: graphId }, body, headers })
1206
+ const envelope = await this.callOperation('Bind text block', (o) =>
1207
+ bindTextBlock({ ...withIdempotencyKey(o, idempotencyKey), path: { graph_id: graphId }, body })
1211
1208
  )
1212
1209
  return this.requireResult('Bind text block', envelope.result)
1213
1210
  }
@@ -1341,9 +1338,8 @@ export class LedgerClient {
1341
1338
  graphId: string,
1342
1339
  body: CreateMappingAssociationOperation
1343
1340
  ): Promise<AssociationResponse> {
1344
- const envelope = await this.callOperation(
1345
- 'Create mapping association',
1346
- createMappingAssociation({ path: { graph_id: graphId }, body })
1341
+ const envelope = await this.callOperation('Create mapping association', (o) =>
1342
+ createMappingAssociation({ ...o, path: { graph_id: graphId }, body })
1347
1343
  )
1348
1344
  return this.requireResult('Create mapping association', envelope.result)
1349
1345
  }
@@ -1353,9 +1349,8 @@ export class LedgerClient {
1353
1349
  graphId: string,
1354
1350
  body: DeleteMappingAssociationOperation
1355
1351
  ): Promise<DeleteResult> {
1356
- const envelope = await this.callOperation(
1357
- 'Delete mapping association',
1358
- deleteMappingAssociation({ path: { graph_id: graphId }, body })
1352
+ const envelope = await this.callOperation('Delete mapping association', (o) =>
1353
+ deleteMappingAssociation({ ...o, path: { graph_id: graphId }, body })
1359
1354
  )
1360
1355
  return (envelope.result ?? { deleted: true }) as DeleteResult
1361
1356
  }
@@ -1369,9 +1364,8 @@ export class LedgerClient {
1369
1364
  graphId: string,
1370
1365
  body: AutoMapElementsOperation
1371
1366
  ): Promise<{ operationId: string; status: OperationEnvelope['status'] }> {
1372
- const envelope = await this.callOperation(
1373
- 'Auto-map elements',
1374
- autoMapElements({ path: { graph_id: graphId }, body })
1367
+ const envelope = await this.callOperation('Auto-map elements', (o) =>
1368
+ autoMapElements({ ...o, path: { graph_id: graphId }, body })
1375
1369
  )
1376
1370
  return { operationId: envelope.operationId, status: envelope.status }
1377
1371
  }
@@ -1476,7 +1470,6 @@ export class LedgerClient {
1476
1470
 
1477
1471
  // ── Schedules ──────────────────────────────────────────────────────
1478
1472
 
1479
- /** Create a new schedule with pre-generated monthly facts. */
1480
1473
  /**
1481
1474
  * Create an Information Block of any registered block_type.
1482
1475
  *
@@ -1492,14 +1485,11 @@ export class LedgerClient {
1492
1485
  body: CreateInformationBlockRequest,
1493
1486
  options?: { idempotencyKey?: string }
1494
1487
  ): Promise<InformationBlockEnvelope> {
1495
- const envelope = await this.callOperation(
1496
- 'Create information block',
1488
+ const envelope = await this.callOperation('Create information block', (o) =>
1497
1489
  createInformationBlock({
1490
+ ...withIdempotencyKey(o, options?.idempotencyKey),
1498
1491
  path: { graph_id: graphId },
1499
1492
  body,
1500
- headers: options?.idempotencyKey
1501
- ? { 'Idempotency-Key': options.idempotencyKey }
1502
- : undefined,
1503
1493
  })
1504
1494
  )
1505
1495
  return this.requireResult('Create information block', envelope.result)
@@ -1513,9 +1503,8 @@ export class LedgerClient {
1513
1503
  graphId: string,
1514
1504
  body: UpdateInformationBlockRequest
1515
1505
  ): Promise<InformationBlockEnvelope> {
1516
- const envelope = await this.callOperation(
1517
- 'Update information block',
1518
- updateInformationBlock({ path: { graph_id: graphId }, body })
1506
+ const envelope = await this.callOperation('Update information block', (o) =>
1507
+ updateInformationBlock({ ...o, path: { graph_id: graphId }, body })
1519
1508
  )
1520
1509
  return this.requireResult('Update information block', envelope.result)
1521
1510
  }
@@ -1529,13 +1518,13 @@ export class LedgerClient {
1529
1518
  graphId: string,
1530
1519
  body: DeleteInformationBlockRequest
1531
1520
  ): Promise<DeleteInformationBlockResponse> {
1532
- const envelope = await this.callOperation(
1533
- 'Delete information block',
1534
- deleteInformationBlock({ path: { graph_id: graphId }, body })
1521
+ const envelope = await this.callOperation('Delete information block', (o) =>
1522
+ deleteInformationBlock({ ...o, path: { graph_id: graphId }, body })
1535
1523
  )
1536
1524
  return (envelope.result ?? { deleted: true }) as DeleteInformationBlockResponse
1537
1525
  }
1538
1526
 
1527
+ /** Create a new schedule with pre-generated monthly facts. */
1539
1528
  async createSchedule(
1540
1529
  graphId: string,
1541
1530
  options: CreateScheduleOptions
@@ -1567,9 +1556,8 @@ export class LedgerClient {
1567
1556
  : undefined,
1568
1557
  },
1569
1558
  }
1570
- const envelope = await this.callOperation(
1571
- 'Create schedule',
1572
- createInformationBlock({ path: { graph_id: graphId }, body })
1559
+ const envelope = await this.callOperation('Create schedule', (o) =>
1560
+ createInformationBlock({ ...o, path: { graph_id: graphId }, body })
1573
1561
  )
1574
1562
  // `create-information-block` returns an InformationBlockEnvelope, not the
1575
1563
  // ScheduleCreatedResponse shape this used to decode — there is no
@@ -1587,7 +1575,10 @@ export class LedgerClient {
1587
1575
  }
1588
1576
  }
1589
1577
 
1590
- /** Update mutable fields on a schedule (name, entry_template, metadata). */
1578
+ /**
1579
+ * Rename a schedule. For other block fields use `updateInformationBlock`
1580
+ * with a `schedule` payload.
1581
+ */
1591
1582
  async updateSchedule(
1592
1583
  graphId: string,
1593
1584
  structureId: string,
@@ -1597,9 +1588,8 @@ export class LedgerClient {
1597
1588
  block_type: 'schedule',
1598
1589
  payload: { structure_id: structureId, ...options },
1599
1590
  }
1600
- const envelope = await this.callOperation(
1601
- 'Update schedule',
1602
- updateInformationBlock({ path: { graph_id: graphId }, body })
1591
+ const envelope = await this.callOperation('Update schedule', (o) =>
1592
+ updateInformationBlock({ ...o, path: { graph_id: graphId }, body })
1603
1593
  )
1604
1594
  return this.requireResult('Update schedule', envelope.result)
1605
1595
  }
@@ -1613,9 +1603,8 @@ export class LedgerClient {
1613
1603
  block_type: 'schedule',
1614
1604
  payload: { structure_id: structureId },
1615
1605
  }
1616
- const envelope = await this.callOperation(
1617
- 'Delete schedule',
1618
- deleteInformationBlock({ path: { graph_id: graphId }, body })
1606
+ const envelope = await this.callOperation('Delete schedule', (o) =>
1607
+ deleteInformationBlock({ ...o, path: { graph_id: graphId }, body })
1619
1608
  )
1620
1609
  return (envelope.result ?? { deleted: true }) as DeleteInformationBlockResponse
1621
1610
  }
@@ -1631,7 +1620,8 @@ export class LedgerClient {
1631
1620
  * a rebuild re-scopes the schedule to today's close state. Use this to
1632
1621
  * pick up a fixed generator without orphaning obligations.
1633
1622
  *
1634
- * Returns the same shape as `createSchedule`.
1623
+ * Returns the {@link ScheduleCreated} rebuild summary (periods, facts,
1624
+ * rule results) — richer than `createSchedule`'s {@link ScheduleBlockCreated}.
1635
1625
  */
1636
1626
  async rebuildSchedule(
1637
1627
  graphId: string,
@@ -1639,14 +1629,11 @@ export class LedgerClient {
1639
1629
  options?: { idempotencyKey?: string }
1640
1630
  ): Promise<ScheduleCreated> {
1641
1631
  const body: RebuildScheduleRequest = { structure_id: structureId }
1642
- const envelope = await this.callOperation(
1643
- 'Rebuild schedule',
1632
+ const envelope = await this.callOperation('Rebuild schedule', (o) =>
1644
1633
  rebuildSchedule({
1634
+ ...withIdempotencyKey(o, options?.idempotencyKey),
1645
1635
  path: { graph_id: graphId },
1646
1636
  body,
1647
- headers: options?.idempotencyKey
1648
- ? { 'Idempotency-Key': options.idempotencyKey }
1649
- : undefined,
1650
1637
  })
1651
1638
  )
1652
1639
  const raw = envelope.result as unknown as RawScheduleCreatedResult
@@ -1697,18 +1684,16 @@ export class LedgerClient {
1697
1684
  reason: options.reason ?? 'asset_disposed_event',
1698
1685
  },
1699
1686
  }
1700
- const envelope = await this.callOperation(
1701
- 'Dispose schedule',
1702
- createEventBlock({ path: { graph_id: graphId }, body })
1687
+ const envelope = await this.callOperation('Dispose schedule', (o) =>
1688
+ createEventBlock({ ...o, path: { graph_id: graphId }, body })
1703
1689
  )
1704
1690
  return this.requireResult('Dispose schedule', envelope.result)
1705
1691
  }
1706
1692
 
1707
1693
  /** Evaluate taxonomy rules against facts in a structure. */
1708
1694
  async evaluateRules(graphId: string, body: EvaluateRulesRequest): Promise<EvaluateRulesResponse> {
1709
- const envelope = await this.callOperation(
1710
- 'Evaluate rules',
1711
- evaluateRules({ path: { graph_id: graphId }, body })
1695
+ const envelope = await this.callOperation('Evaluate rules', (o) =>
1696
+ evaluateRules({ ...o, path: { graph_id: graphId }, body })
1712
1697
  )
1713
1698
  return this.requireResult('Evaluate rules', envelope.result)
1714
1699
  }
@@ -1726,14 +1711,11 @@ export class LedgerClient {
1726
1711
  body: ComputeMetricsRequest,
1727
1712
  options?: { idempotencyKey?: string }
1728
1713
  ): Promise<ComputeMetricsResponse> {
1729
- const envelope = await this.callOperation(
1730
- 'Compute metrics',
1714
+ const envelope = await this.callOperation('Compute metrics', (o) =>
1731
1715
  computeMetrics({
1716
+ ...withIdempotencyKey(o, options?.idempotencyKey),
1732
1717
  path: { graph_id: graphId },
1733
1718
  body,
1734
- headers: options?.idempotencyKey
1735
- ? { 'Idempotency-Key': options.idempotencyKey }
1736
- : undefined,
1737
1719
  })
1738
1720
  )
1739
1721
  return this.requireResult('Compute metrics', envelope.result)
@@ -1799,9 +1781,8 @@ export class LedgerClient {
1799
1781
  memo: memo ?? null,
1800
1782
  },
1801
1783
  }
1802
- const envelope = await this.callOperation(
1803
- 'Create closing entry',
1804
- createEventBlock({ path: { graph_id: graphId }, body })
1784
+ const envelope = await this.callOperation('Create closing entry', (o) =>
1785
+ createEventBlock({ ...o, path: { graph_id: graphId }, body })
1805
1786
  )
1806
1787
  return this.requireResult('Create closing entry', envelope.result)
1807
1788
  }
@@ -1844,9 +1825,8 @@ export class LedgerClient {
1844
1825
  auto_seed_schedules: options?.autoSeedSchedules,
1845
1826
  note: options?.note ?? null,
1846
1827
  }
1847
- const envelope = await this.callOperation(
1848
- 'Initialize ledger',
1849
- initializeLedger({ path: { graph_id: graphId }, body })
1828
+ const envelope = await this.callOperation('Initialize ledger', (o) =>
1829
+ initializeLedger({ ...o, path: { graph_id: graphId }, body })
1850
1830
  )
1851
1831
  const raw = envelope.result as unknown as RawInitializeLedgerResult
1852
1832
  return {
@@ -1885,9 +1865,8 @@ export class LedgerClient {
1885
1865
  entity_type: options?.entityType ?? null,
1886
1866
  name: options?.name ?? null,
1887
1867
  }
1888
- const envelope = await this.callOperation(
1889
- 'Initialize chart of accounts',
1890
- initializeChartOfAccounts({ path: { graph_id: graphId }, body })
1868
+ const envelope = await this.callOperation('Initialize chart of accounts', (o) =>
1869
+ initializeChartOfAccounts({ ...o, path: { graph_id: graphId }, body })
1891
1870
  )
1892
1871
  const raw = envelope.result as unknown as InitializeChartOfAccountsResponse
1893
1872
  return {
@@ -1909,9 +1888,8 @@ export class LedgerClient {
1909
1888
  note?: string | null
1910
1889
  ): Promise<LedgerFiscalCalendar> {
1911
1890
  const body: SetCloseTargetOperation = { period, note: note ?? null }
1912
- const envelope = await this.callOperation(
1913
- 'Set close target',
1914
- setCloseTarget({ path: { graph_id: graphId }, body })
1891
+ const envelope = await this.callOperation('Set close target', (o) =>
1892
+ setCloseTarget({ ...o, path: { graph_id: graphId }, body })
1915
1893
  )
1916
1894
  return rawFiscalCalendarToCamel(envelope.result as unknown as RawFiscalCalendar)
1917
1895
  }
@@ -1931,9 +1909,8 @@ export class LedgerClient {
1931
1909
  allow_reconciling_items: options?.allowReconcilingItems,
1932
1910
  allow_unposted_source_events: options?.allowUnpostedSourceEvents,
1933
1911
  }
1934
- const envelope = await this.callOperation(
1935
- 'Close period',
1936
- closePeriod({ path: { graph_id: graphId }, body })
1912
+ const envelope = await this.callOperation('Close period', (o) =>
1913
+ closePeriod({ ...o, path: { graph_id: graphId }, body })
1937
1914
  )
1938
1915
  const raw = envelope.result as unknown as RawClosePeriodResult
1939
1916
  return {
@@ -1960,9 +1937,8 @@ export class LedgerClient {
1960
1937
  reason,
1961
1938
  note: note ?? null,
1962
1939
  }
1963
- const envelope = await this.callOperation(
1964
- 'Reopen period',
1965
- reopenPeriod({ path: { graph_id: graphId }, body })
1940
+ const envelope = await this.callOperation('Reopen period', (o) =>
1941
+ reopenPeriod({ ...o, path: { graph_id: graphId }, body })
1966
1942
  )
1967
1943
  return rawFiscalCalendarToCamel(envelope.result as unknown as RawFiscalCalendar)
1968
1944
  }
@@ -1992,9 +1968,8 @@ export class LedgerClient {
1992
1968
  * List the items with `listEventBlocks(graphId, { isReconcilingItem: true })`.
1993
1969
  */
1994
1970
  async previewReconcilingItem(graphId: string, eventId: string): Promise<ReconcilingItemPlan> {
1995
- const envelope = await this.callOperation(
1996
- 'Preview reconciling item',
1997
- previewReconcilingItem({ path: { graph_id: graphId }, body: { event_id: eventId } })
1971
+ const envelope = await this.callOperation('Preview reconciling item', (o) =>
1972
+ previewReconcilingItem({ ...o, path: { graph_id: graphId }, body: { event_id: eventId } })
1998
1973
  )
1999
1974
  return this.requireResult('Preview reconciling item', envelope.result)
2000
1975
  }
@@ -2003,15 +1978,16 @@ export class LedgerClient {
2003
1978
  * Decide one reconciling item: `restate` the affected months, `catch_up`
2004
1979
  * with an entry in the open period, or `acknowledge` that it was handled
2005
1980
  * elsewhere (a note is required). Omit `disposition` to take the default
2006
- * the preview reports.
1981
+ * the preview reports. Pass the preview's `drift_detected_at` as
1982
+ * `expected_drift_detected_at`: the resolution is refused when the item
1983
+ * was flagged again since, and must be previewed again.
2007
1984
  */
2008
1985
  async resolveReconcilingItem(
2009
1986
  graphId: string,
2010
1987
  body: ResolveReconcilingItemRequest
2011
1988
  ): Promise<ResolveReconcilingItemResponse> {
2012
- const envelope = await this.callOperation(
2013
- 'Resolve reconciling item',
2014
- resolveReconcilingItem({ path: { graph_id: graphId }, body })
1989
+ const envelope = await this.callOperation('Resolve reconciling item', (o) =>
1990
+ resolveReconcilingItem({ ...o, path: { graph_id: graphId }, body })
2015
1991
  )
2016
1992
  return this.requireResult('Resolve reconciling item', envelope.result)
2017
1993
  }
@@ -2025,9 +2001,8 @@ export class LedgerClient {
2025
2001
  graphId: string,
2026
2002
  body: PromoteObligationsRequest = {}
2027
2003
  ): Promise<PromoteObligationsResponse> {
2028
- const envelope = await this.callOperation(
2029
- 'Promote obligations',
2030
- promoteObligations({ path: { graph_id: graphId }, body })
2004
+ const envelope = await this.callOperation('Promote obligations', (o) =>
2005
+ promoteObligations({ ...o, path: { graph_id: graphId }, body })
2031
2006
  )
2032
2007
  return this.requireResult('Promote obligations', envelope.result)
2033
2008
  }
@@ -2043,9 +2018,8 @@ export class LedgerClient {
2043
2018
  method: options?.method,
2044
2019
  include_tied: options?.includeTied,
2045
2020
  }
2046
- const envelope = await this.callOperation(
2047
- 'Preview reconciliations',
2048
- previewReconciliations({ path: { graph_id: graphId }, body })
2021
+ const envelope = await this.callOperation('Preview reconciliations', (o) =>
2022
+ previewReconciliations({ ...o, path: { graph_id: graphId }, body })
2049
2023
  )
2050
2024
  return reconciliationPreviewToCamel(envelope.result as unknown as ReconciliationPreviewResponse)
2051
2025
  }
@@ -2056,9 +2030,8 @@ export class LedgerClient {
2056
2030
  */
2057
2031
  async refreshReconciliations(graphId: string, period: string): Promise<LedgerReconciliationList> {
2058
2032
  const body: RefreshReconciliationsRequest = { period }
2059
- const envelope = await this.callOperation(
2060
- 'Refresh reconciliations',
2061
- refreshReconciliations({ path: { graph_id: graphId }, body })
2033
+ const envelope = await this.callOperation('Refresh reconciliations', (o) =>
2034
+ refreshReconciliations({ ...o, path: { graph_id: graphId }, body })
2062
2035
  )
2063
2036
  return reconciliationListToCamel(envelope.result as unknown as ReconciliationListResponse)
2064
2037
  }
@@ -2078,9 +2051,8 @@ export class LedgerClient {
2078
2051
  document_id: input.documentId ?? null,
2079
2052
  note: input.note ?? null,
2080
2053
  }
2081
- const envelope = await this.callOperation(
2082
- 'Record statement balance',
2083
- recordStatementBalance({ path: { graph_id: graphId }, body })
2054
+ const envelope = await this.callOperation('Record statement balance', (o) =>
2055
+ recordStatementBalance({ ...o, path: { graph_id: graphId }, body })
2084
2056
  )
2085
2057
  return reconciliationSummaryToCamel(envelope.result as unknown as ReconciliationSummary)
2086
2058
  }
@@ -2098,9 +2070,8 @@ export class LedgerClient {
2098
2070
  review_required: changes.reviewRequired,
2099
2071
  separate_reviewer: changes.separateReviewer,
2100
2072
  }
2101
- const envelope = await this.callOperation(
2102
- 'Set reconciliation policy',
2103
- setReconciliationPolicy({ path: { graph_id: graphId }, body })
2073
+ const envelope = await this.callOperation('Set reconciliation policy', (o) =>
2074
+ setReconciliationPolicy({ ...o, path: { graph_id: graphId }, body })
2104
2075
  )
2105
2076
  const raw = envelope.result as unknown as ReconciliationPolicyResponse
2106
2077
  return {
@@ -2127,9 +2098,8 @@ export class LedgerClient {
2127
2098
  period,
2128
2099
  note: note ?? null,
2129
2100
  }
2130
- const envelope = await this.callOperation(
2131
- 'Sign off reconciliation',
2132
- signOffReconciliation({ path: { graph_id: graphId }, body })
2101
+ const envelope = await this.callOperation('Sign off reconciliation', (o) =>
2102
+ signOffReconciliation({ ...o, path: { graph_id: graphId }, body })
2133
2103
  )
2134
2104
  return reconciliationSummaryToCamel(envelope.result as unknown as ReconciliationSummary)
2135
2105
  }
@@ -2175,12 +2145,12 @@ export class LedgerClient {
2175
2145
  transaction_id: options.transactionId ?? null,
2176
2146
  },
2177
2147
  }
2178
- const headers = options.idempotencyKey
2179
- ? { 'Idempotency-Key': options.idempotencyKey }
2180
- : undefined
2181
- const envelope = await this.callOperation(
2182
- 'Create journal entry',
2183
- createEventBlock({ path: { graph_id: graphId }, body, headers })
2148
+ const envelope = await this.callOperation('Create journal entry', (o) =>
2149
+ createEventBlock({
2150
+ ...withIdempotencyKey(o, options.idempotencyKey),
2151
+ path: { graph_id: graphId },
2152
+ body,
2153
+ })
2184
2154
  )
2185
2155
  return this.requireResult('Create journal entry', envelope.result)
2186
2156
  }
@@ -2190,9 +2160,8 @@ export class LedgerClient {
2190
2160
  graphId: string,
2191
2161
  body: UpdateJournalEntryRequest
2192
2162
  ): Promise<JournalEntryResponse> {
2193
- const envelope = await this.callOperation(
2194
- 'Update journal entry',
2195
- updateJournalEntry({ path: { graph_id: graphId }, body })
2163
+ const envelope = await this.callOperation('Update journal entry', (o) =>
2164
+ updateJournalEntry({ ...o, path: { graph_id: graphId }, body })
2196
2165
  )
2197
2166
  return this.requireResult('Update journal entry', envelope.result)
2198
2167
  }
@@ -2200,9 +2169,8 @@ export class LedgerClient {
2200
2169
  /** Hard-delete a draft journal entry. Posted entries must be reversed. */
2201
2170
  async deleteJournalEntry(graphId: string, entryId: string): Promise<DeleteResult> {
2202
2171
  const body: DeleteJournalEntryRequest = { entry_id: entryId }
2203
- const envelope = await this.callOperation(
2204
- 'Delete journal entry',
2205
- deleteJournalEntry({ path: { graph_id: graphId }, body })
2172
+ const envelope = await this.callOperation('Delete journal entry', (o) =>
2173
+ deleteJournalEntry({ ...o, path: { graph_id: graphId }, body })
2206
2174
  )
2207
2175
  return (envelope.result ?? { deleted: true }) as DeleteResult
2208
2176
  }
@@ -2239,15 +2207,40 @@ export class LedgerClient {
2239
2207
  reason: options?.reason ?? null,
2240
2208
  },
2241
2209
  }
2242
- const envelope = await this.callOperation(
2243
- 'Reverse journal entry',
2244
- createEventBlock({ path: { graph_id: graphId }, body })
2210
+ const envelope = await this.callOperation('Reverse journal entry', (o) =>
2211
+ createEventBlock({ ...o, path: { graph_id: graphId }, body })
2245
2212
  )
2246
2213
  return this.requireResult('Reverse journal entry', envelope.result)
2247
2214
  }
2248
2215
 
2249
2216
  // ── Event blocks (generic preview + status transitions) ──────────────
2250
2217
 
2218
+ /**
2219
+ * Create an event block directly. Use for support-class events
2220
+ * (`event_class: 'support'`) with categories `approval`, `control`,
2221
+ * `reconciliation`, or `inquiry`, which the specialized helpers don't
2222
+ * cover. Economic events should generally go through
2223
+ * `createJournalEntry`, `createClosingEntry`, etc., but this works for
2224
+ * those too.
2225
+ *
2226
+ * Supply `idempotencyKey` to make the call safe to retry — replays
2227
+ * within 24 hours return the same envelope.
2228
+ */
2229
+ async createEventBlock(
2230
+ graphId: string,
2231
+ body: CreateEventBlockRequest,
2232
+ idempotencyKey?: string
2233
+ ): Promise<EventBlockEnvelope> {
2234
+ const envelope = await this.callOperation('Create event block', (o) =>
2235
+ createEventBlock({
2236
+ ...withIdempotencyKey(o, idempotencyKey),
2237
+ path: { graph_id: graphId },
2238
+ body,
2239
+ })
2240
+ )
2241
+ return this.requireResult('Create event block', envelope.result)
2242
+ }
2243
+
2251
2244
  /**
2252
2245
  * Dry-run an event block — resolve the handler, evaluate metadata, and
2253
2246
  * return the planned GL rows without writing anything. Companion to
@@ -2260,9 +2253,8 @@ export class LedgerClient {
2260
2253
  graphId: string,
2261
2254
  body: CreateEventBlockRequest
2262
2255
  ): Promise<PreviewEventBlockResponse> {
2263
- const envelope = await this.callOperation(
2264
- 'Preview event block',
2265
- previewEventBlock({ path: { graph_id: graphId }, body })
2256
+ const envelope = await this.callOperation('Preview event block', (o) =>
2257
+ previewEventBlock({ ...o, path: { graph_id: graphId }, body })
2266
2258
  )
2267
2259
  return this.requireResult('Preview event block', envelope.result)
2268
2260
  }
@@ -2277,9 +2269,8 @@ export class LedgerClient {
2277
2269
  graphId: string,
2278
2270
  body: UpdateEventBlockRequest
2279
2271
  ): Promise<EventBlockEnvelope> {
2280
- const envelope = await this.callOperation(
2281
- 'Update event block',
2282
- updateEventBlock({ path: { graph_id: graphId }, body })
2272
+ const envelope = await this.callOperation('Update event block', (o) =>
2273
+ updateEventBlock({ ...o, path: { graph_id: graphId }, body })
2283
2274
  )
2284
2275
  return this.requireResult('Update event block', envelope.result)
2285
2276
  }
@@ -2297,10 +2288,8 @@ export class LedgerClient {
2297
2288
  body: CreateAgentRequest,
2298
2289
  idempotencyKey?: string
2299
2290
  ): Promise<LedgerAgentResponse> {
2300
- const headers = idempotencyKey ? { 'Idempotency-Key': idempotencyKey } : undefined
2301
- const envelope = await this.callOperation(
2302
- 'Create agent',
2303
- createAgent({ path: { graph_id: graphId }, body, headers })
2291
+ const envelope = await this.callOperation('Create agent', (o) =>
2292
+ createAgent({ ...withIdempotencyKey(o, idempotencyKey), path: { graph_id: graphId }, body })
2304
2293
  )
2305
2294
  return this.requireResult('Create agent', envelope.result)
2306
2295
  }
@@ -2310,9 +2299,8 @@ export class LedgerClient {
2310
2299
  * metadata object; all other fields replace.
2311
2300
  */
2312
2301
  async updateAgent(graphId: string, body: UpdateAgentRequest): Promise<LedgerAgentResponse> {
2313
- const envelope = await this.callOperation(
2314
- 'Update agent',
2315
- updateAgent({ path: { graph_id: graphId }, body })
2302
+ const envelope = await this.callOperation('Update agent', (o) =>
2303
+ updateAgent({ ...o, path: { graph_id: graphId }, body })
2316
2304
  )
2317
2305
  return this.requireResult('Update agent', envelope.result)
2318
2306
  }
@@ -2329,9 +2317,8 @@ export class LedgerClient {
2329
2317
  graphId: string,
2330
2318
  body: CreateEventHandlerRequest
2331
2319
  ): Promise<EventHandlerResponse> {
2332
- const envelope = await this.callOperation(
2333
- 'Create event handler',
2334
- createEventHandler({ path: { graph_id: graphId }, body })
2320
+ const envelope = await this.callOperation('Create event handler', (o) =>
2321
+ createEventHandler({ ...o, path: { graph_id: graphId }, body })
2335
2322
  )
2336
2323
  return this.requireResult('Create event handler', envelope.result)
2337
2324
  }
@@ -2344,9 +2331,8 @@ export class LedgerClient {
2344
2331
  graphId: string,
2345
2332
  body: UpdateEventHandlerRequest
2346
2333
  ): Promise<EventHandlerResponse> {
2347
- const envelope = await this.callOperation(
2348
- 'Update event handler',
2349
- updateEventHandler({ path: { graph_id: graphId }, body })
2334
+ const envelope = await this.callOperation('Update event handler', (o) =>
2335
+ updateEventHandler({ ...o, path: { graph_id: graphId }, body })
2350
2336
  )
2351
2337
  return this.requireResult('Update event handler', envelope.result)
2352
2338
  }
@@ -2363,9 +2349,8 @@ export class LedgerClient {
2363
2349
  graphId: string,
2364
2350
  body: LiveFinancialStatementRequest
2365
2351
  ): Promise<LiveFinancialStatementResponse> {
2366
- const envelope = await this.callOperation(
2367
- 'Live financial statement',
2368
- liveFinancialStatement({ path: { graph_id: graphId }, body })
2352
+ const envelope = await this.callOperation('Live financial statement', (o) =>
2353
+ liveFinancialStatement({ ...o, path: { graph_id: graphId }, body })
2369
2354
  )
2370
2355
  return this.requireResult('Live financial statement', envelope.result)
2371
2356
  }
@@ -2380,9 +2365,8 @@ export class LedgerClient {
2380
2365
  graphId: string,
2381
2366
  body: FinancialStatementAnalysisRequest
2382
2367
  ): Promise<FinancialStatementAnalysisResponse> {
2383
- const envelope = await this.callOperation(
2384
- 'Financial statement analysis',
2385
- financialStatementAnalysis({ path: { graph_id: graphId }, body })
2368
+ const envelope = await this.callOperation('Financial statement analysis', (o) =>
2369
+ financialStatementAnalysis({ ...o, path: { graph_id: graphId }, body })
2386
2370
  )
2387
2371
  return this.requireResult('Financial statement analysis', envelope.result)
2388
2372
  }
@@ -2397,9 +2381,8 @@ export class LedgerClient {
2397
2381
  * tenant graphs (after materialization) and the SEC shared repository.
2398
2382
  */
2399
2383
  async buildFactGrid(graphId: string, body: CreateViewRequest): Promise<ViewResponse> {
2400
- const envelope = await this.callOperation(
2401
- 'Build fact grid',
2402
- buildFactGrid({ path: { graph_id: graphId }, body })
2384
+ const envelope = await this.callOperation('Build fact grid', (o) =>
2385
+ buildFactGrid({ ...o, path: { graph_id: graphId }, body })
2403
2386
  )
2404
2387
  return this.requireResult('Build fact grid', envelope.result)
2405
2388
  }
@@ -2456,9 +2439,8 @@ export class LedgerClient {
2456
2439
  if (options.periods && options.periods.length > 0) {
2457
2440
  body.periods = options.periods
2458
2441
  }
2459
- const envelope = await this.callOperation(
2460
- 'Create report',
2461
- createReport({ path: { graph_id: graphId }, body })
2442
+ const envelope = await this.callOperation('Create report', (o) =>
2443
+ createReport({ ...o, path: { graph_id: graphId }, body })
2462
2444
  )
2463
2445
  return this.requireResult('Create report', envelope.result)
2464
2446
  }
@@ -2540,9 +2522,9 @@ export class LedgerClient {
2540
2522
  periodStart?: string,
2541
2523
  periodEnd?: string
2542
2524
  ): Promise<ReportResponse> {
2543
- const envelope = await this.callOperation(
2544
- 'Regenerate report',
2525
+ const envelope = await this.callOperation('Regenerate report', (o) =>
2545
2526
  regenerateReport({
2527
+ ...o,
2546
2528
  path: { graph_id: graphId },
2547
2529
  body: {
2548
2530
  report_id: reportId,
@@ -2556,12 +2538,8 @@ export class LedgerClient {
2556
2538
 
2557
2539
  /** Delete a report and its generated facts. */
2558
2540
  async deleteReport(graphId: string, reportId: string): Promise<DeleteResult> {
2559
- const envelope = await this.callOperation(
2560
- 'Delete report',
2561
- deleteReport({
2562
- path: { graph_id: graphId },
2563
- body: { report_id: reportId },
2564
- })
2541
+ const envelope = await this.callOperation('Delete report', (o) =>
2542
+ deleteReport({ ...o, path: { graph_id: graphId }, body: { report_id: reportId } })
2565
2543
  )
2566
2544
  return (envelope.result ?? { deleted: true }) as DeleteResult
2567
2545
  }
@@ -2630,9 +2608,9 @@ export class LedgerClient {
2630
2608
  reportId: string,
2631
2609
  publishListId: string
2632
2610
  ): Promise<ShareReportResponse> {
2633
- const envelope = await this.callOperation(
2634
- 'Share report',
2611
+ const envelope = await this.callOperation('Share report', (o) =>
2635
2612
  shareReport({
2613
+ ...o,
2636
2614
  path: { graph_id: graphId },
2637
2615
  body: {
2638
2616
  report_id: reportId,
@@ -2651,9 +2629,8 @@ export class LedgerClient {
2651
2629
  */
2652
2630
  async fileReport(graphId: string, reportId: string): Promise<ReportResponse> {
2653
2631
  const body: FileReportRequest = { report_id: reportId }
2654
- const envelope = await this.callOperation(
2655
- 'File report',
2656
- fileReport({ path: { graph_id: graphId }, body })
2632
+ const envelope = await this.callOperation('File report', (o) =>
2633
+ fileReport({ ...o, path: { graph_id: graphId }, body })
2657
2634
  )
2658
2635
  return this.requireResult('File report', envelope.result)
2659
2636
  }
@@ -2674,9 +2651,8 @@ export class LedgerClient {
2674
2651
  report_id: reportId,
2675
2652
  target_status: targetStatus,
2676
2653
  }
2677
- const envelope = await this.callOperation(
2678
- 'Transition filing status',
2679
- transitionFilingStatus({ path: { graph_id: graphId }, body })
2654
+ const envelope = await this.callOperation('Transition filing status', (o) =>
2655
+ transitionFilingStatus({ ...o, path: { graph_id: graphId }, body })
2680
2656
  )
2681
2657
  return this.requireResult('Transition filing status', envelope.result)
2682
2658
  }
@@ -2704,9 +2680,9 @@ export class LedgerClient {
2704
2680
  reportId: string,
2705
2681
  targetGraphId: string
2706
2682
  ): Promise<RevokeReportShareResponse> {
2707
- const envelope = await this.callOperation(
2708
- 'Revoke report share',
2683
+ const envelope = await this.callOperation('Revoke report share', (o) =>
2709
2684
  revokeReportShare({
2685
+ ...o,
2710
2686
  path: { graph_id: graphId },
2711
2687
  body: {
2712
2688
  report_id: reportId,
@@ -2757,9 +2733,9 @@ export class LedgerClient {
2757
2733
  sourceGraphId: string,
2758
2734
  options?: { reason?: string; purge?: boolean }
2759
2735
  ): Promise<BlockSourceGraphResult> {
2760
- const envelope = await this.callOperation(
2761
- 'Block source graph',
2736
+ const envelope = await this.callOperation('Block source graph', (o) =>
2762
2737
  blockSourceGraph({
2738
+ ...o,
2763
2739
  path: { graph_id: graphId },
2764
2740
  body: {
2765
2741
  source_graph_id: sourceGraphId,
@@ -2781,9 +2757,9 @@ export class LedgerClient {
2781
2757
  graphId: string,
2782
2758
  sourceGraphId: string
2783
2759
  ): Promise<BlockedSourceGraphResponse> {
2784
- const envelope = await this.callOperation(
2785
- 'Unblock source graph',
2760
+ const envelope = await this.callOperation('Unblock source graph', (o) =>
2786
2761
  unblockSourceGraph({
2762
+ ...o,
2787
2763
  path: { graph_id: graphId },
2788
2764
  body: {
2789
2765
  source_graph_id: sourceGraphId,
@@ -2823,9 +2799,8 @@ export class LedgerClient {
2823
2799
  name,
2824
2800
  description: description ?? null,
2825
2801
  }
2826
- const envelope = await this.callOperation(
2827
- 'Create publish list',
2828
- createPublishList({ path: { graph_id: graphId }, body })
2802
+ const envelope = await this.callOperation('Create publish list', (o) =>
2803
+ createPublishList({ ...o, path: { graph_id: graphId }, body })
2829
2804
  )
2830
2805
  return this.requireResult('Create publish list', envelope.result)
2831
2806
  }
@@ -2847,28 +2822,21 @@ export class LedgerClient {
2847
2822
  listId: string,
2848
2823
  updates: { name?: string; description?: string | null }
2849
2824
  ): Promise<PublishListResponse> {
2850
- const envelope = await this.callOperation(
2851
- 'Update publish list',
2852
- updatePublishList({
2853
- path: { graph_id: graphId },
2854
- body: {
2855
- list_id: listId,
2856
- name: updates.name,
2857
- description: updates.description ?? null,
2858
- } as UpdatePublishListOperation,
2859
- })
2825
+ // The server applies only the fields present, so an omitted key must
2826
+ // stay off the wire; an explicit `description: null` still clears it.
2827
+ const body: UpdatePublishListOperation = { list_id: listId }
2828
+ if (updates.name !== undefined) body.name = updates.name
2829
+ if (updates.description !== undefined) body.description = updates.description
2830
+ const envelope = await this.callOperation('Update publish list', (o) =>
2831
+ updatePublishList({ ...o, path: { graph_id: graphId }, body })
2860
2832
  )
2861
2833
  return this.requireResult('Update publish list', envelope.result)
2862
2834
  }
2863
2835
 
2864
2836
  /** Delete a publish list. */
2865
2837
  async deletePublishList(graphId: string, listId: string): Promise<DeleteResult> {
2866
- const envelope = await this.callOperation(
2867
- 'Delete publish list',
2868
- deletePublishList({
2869
- path: { graph_id: graphId },
2870
- body: { list_id: listId },
2871
- })
2838
+ const envelope = await this.callOperation('Delete publish list', (o) =>
2839
+ deletePublishList({ ...o, path: { graph_id: graphId }, body: { list_id: listId } })
2872
2840
  )
2873
2841
  return (envelope.result ?? { deleted: true }) as DeleteResult
2874
2842
  }
@@ -2879,9 +2847,9 @@ export class LedgerClient {
2879
2847
  listId: string,
2880
2848
  targetGraphIds: string[]
2881
2849
  ): Promise<PublishListMemberResponse[]> {
2882
- const envelope = await this.callOperation(
2883
- 'Add publish list members',
2850
+ const envelope = await this.callOperation('Add publish list members', (o) =>
2884
2851
  addPublishListMembers({
2852
+ ...o,
2885
2853
  path: { graph_id: graphId },
2886
2854
  body: {
2887
2855
  list_id: listId,
@@ -2898,9 +2866,9 @@ export class LedgerClient {
2898
2866
  listId: string,
2899
2867
  memberId: string
2900
2868
  ): Promise<DeleteResult> {
2901
- const envelope = await this.callOperation(
2902
- 'Remove publish list member',
2869
+ const envelope = await this.callOperation('Remove publish list member', (o) =>
2903
2870
  removePublishListMember({
2871
+ ...o,
2904
2872
  path: { graph_id: graphId },
2905
2873
  body: { list_id: listId, member_id: memberId },
2906
2874
  })
@@ -2911,8 +2879,9 @@ export class LedgerClient {
2911
2879
  // ── Internal helpers ────────────────────────────────────────────────
2912
2880
 
2913
2881
  /**
2914
- * Await an SDK-generated command call, throw a readable error on
2915
- * non-2xx, and return the parsed envelope on success.
2882
+ * Run an SDK-generated command call with this facade's per-call
2883
+ * transport options (`baseUrl`, credential, headers), throw a readable
2884
+ * error on non-2xx, and return the parsed envelope on success.
2916
2885
  *
2917
2886
  * Generic over the SDK call's response shape so typed ops (e.g.
2918
2887
  * `createEventBlock`, which returns
@@ -2922,9 +2891,9 @@ export class LedgerClient {
2922
2891
  */
2923
2892
  private async callOperation<T>(
2924
2893
  label: string,
2925
- call: Promise<{ data?: T; error?: unknown }>
2894
+ call: (options: RestCallOptions) => Promise<{ data?: T; error?: unknown }>
2926
2895
  ): Promise<T> {
2927
- const response = await call
2896
+ const response = await call(await restCallOptions(this.config))
2928
2897
  if (response.error !== undefined) {
2929
2898
  throw new Error(`${label} failed: ${JSON.stringify(response.error)}`)
2930
2899
  }
@@ -2945,35 +2914,6 @@ export class LedgerClient {
2945
2914
  }
2946
2915
  return result
2947
2916
  }
2948
-
2949
- /**
2950
- * Resolve the current bearer token / API key for non-GraphQL REST
2951
- * calls. Mirrors the GraphQL client's behaviour — dynamic
2952
- * ``tokenProvider`` is consulted first (so JWT rotation flows
2953
- * naturally), then the static ``token`` config. Returns ``null``
2954
- * when no credential is configured (cookie-based / anonymous flows).
2955
- * A ``tokenProvider`` that **throws** fails the call fast instead of
2956
- * silently proceeding unauthenticated — matching the Python client,
2957
- * which raises when its configured credential cannot be resolved.
2958
- */
2959
- private async resolveToken(): Promise<string | null> {
2960
- if (this.config.tokenProvider) {
2961
- let token: string | null | undefined
2962
- try {
2963
- token = await this.config.tokenProvider()
2964
- } catch (err) {
2965
- const detail = err instanceof Error ? err.message : String(err)
2966
- throw new Error(
2967
- `RoboSystems SDK: tokenProvider threw while resolving the request credential (${detail}). ` +
2968
- 'Fix the tokenProvider passed in the client config (or via setSDKClientConfig) so it ' +
2969
- 'returns the current token, or null to send an unauthenticated (cookie-based) request.',
2970
- { cause: err }
2971
- )
2972
- }
2973
- return token ?? null
2974
- }
2975
- return this.config.token ?? null
2976
- }
2977
2917
  }
2978
2918
 
2979
2919
  // ── Module-private conversion helpers ─────────────────────────────────