@robosystems/client 0.3.19 → 0.3.21

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.
@@ -63,7 +63,7 @@ class InvestorClient {
63
63
  confirm_active_positions: options?.confirmActivePositions ?? false,
64
64
  };
65
65
  const envelope = await this.callOperation('Delete portfolio block', (0, sdk_gen_1.opDeletePortfolioBlock)({ path: { graph_id: graphId }, body }));
66
- return (envelope.result ?? { deleted: true });
66
+ return envelope.result ?? { deleted: true };
67
67
  }
68
68
  // ── Securities ──────────────────────────────────────────────────────
69
69
  /** List securities with pagination and filters. */
@@ -105,7 +105,7 @@ class InvestorClient {
105
105
  path: { graph_id: graphId },
106
106
  body: { security_id: securityId },
107
107
  }));
108
- return (envelope.result ?? { deleted: true });
108
+ return envelope.result ?? { deleted: true };
109
109
  }
110
110
  // ── Positions (reads only — writes folded into Portfolio Block) ─────
111
111
  /** List positions with pagination and filters. */
@@ -146,6 +146,11 @@ class InvestorClient {
146
146
  throw err;
147
147
  }
148
148
  }
149
+ // Generic over the SDK call's response shape so typed ops (e.g.
150
+ // `opCreatePortfolioBlock`, which returns
151
+ // `OperationEnvelopePortfolioBlockEnvelope`) flow through with a typed
152
+ // `envelope.result` instead of being widened to `unknown`. Untyped ops
153
+ // continue to land as `OperationEnvelope` automatically.
149
154
  async callOperation(label, call) {
150
155
  const response = await call;
151
156
  if (response.error !== undefined) {
@@ -36,7 +36,6 @@ import type {
36
36
  CreatePortfolioBlockRequest,
37
37
  CreateSecurityRequest,
38
38
  DeletePortfolioBlockOperation,
39
- OperationEnvelope,
40
39
  PortfolioBlockPortfolioPatch,
41
40
  PortfolioBlockPositions,
42
41
  UpdatePortfolioBlockOperation,
@@ -206,7 +205,7 @@ export class InvestorClient {
206
205
  'Delete portfolio block',
207
206
  opDeletePortfolioBlock({ path: { graph_id: graphId }, body })
208
207
  )
209
- return (envelope.result ?? { deleted: true }) as { deleted: boolean }
208
+ return envelope.result ?? { deleted: true }
210
209
  }
211
210
 
212
211
  // ── Securities ──────────────────────────────────────────────────────
@@ -288,7 +287,7 @@ export class InvestorClient {
288
287
  body: { security_id: securityId },
289
288
  })
290
289
  )
291
- return (envelope.result ?? { deleted: true }) as { deleted: boolean }
290
+ return envelope.result ?? { deleted: true }
292
291
  }
293
292
 
294
293
  // ── Positions (reads only — writes folded into Portfolio Block) ─────
@@ -370,10 +369,15 @@ export class InvestorClient {
370
369
  }
371
370
  }
372
371
 
373
- private async callOperation(
372
+ // Generic over the SDK call's response shape so typed ops (e.g.
373
+ // `opCreatePortfolioBlock`, which returns
374
+ // `OperationEnvelopePortfolioBlockEnvelope`) flow through with a typed
375
+ // `envelope.result` instead of being widened to `unknown`. Untyped ops
376
+ // continue to land as `OperationEnvelope` automatically.
377
+ private async callOperation<T>(
374
378
  label: string,
375
- call: Promise<{ data?: OperationEnvelope; error?: unknown }>
376
- ): Promise<OperationEnvelope> {
379
+ call: Promise<{ data?: T; error?: unknown }>
380
+ ): Promise<T> {
377
381
  const response = await call
378
382
  if (response.error !== undefined) {
379
383
  throw new Error(`${label} failed: ${JSON.stringify(response.error)}`)
@@ -1,4 +1,4 @@
1
- import type { AutoMapElementsOperation, CreateAgentRequest, CreateEventBlockRequest, CreateEventHandlerRequest, CreateMappingAssociationOperation, CreateTaxonomyBlockRequest, CreateViewRequest, DeleteMappingAssociationOperation, DeleteTaxonomyBlockRequest, EvaluateRulesRequest, FinancialStatementAnalysisRequest, LinkEntityTaxonomyRequest, LiveFinancialStatementRequest, OperationEnvelope, UpdateAgentRequest, UpdateEntityRequest, UpdateEventBlockRequest, UpdateEventHandlerRequest, UpdateJournalEntryRequest, UpdateTaxonomyBlockRequest } from '../types.gen';
1
+ import type { AssociationResponse, AutoMapElementsOperation, CreateAgentRequest, CreateEventBlockRequest, CreateEventHandlerRequest, CreateMappingAssociationOperation, CreateTaxonomyBlockRequest, CreateViewRequest, DeleteInformationBlockResponse, DeleteMappingAssociationOperation, DeleteResult, DeleteTaxonomyBlockRequest, DeleteTaxonomyBlockResponse, EntityTaxonomyResponse, EvaluateRulesRequest, EvaluateRulesResponse, EventBlockEnvelope, EventHandlerResponse, FinancialStatementAnalysisRequest, InformationBlockEnvelope, JournalEntryResponse, LedgerAgentResponse, LinkEntityTaxonomyRequest, LiveFinancialStatementRequest, OperationEnvelope, PreviewEventBlockResponse, PublishListMemberResponse, PublishListResponse, ReportResponse, ShareReportResponse, TaxonomyBlockEnvelope, UpdateAgentRequest, UpdateEntityRequest, UpdateEventBlockRequest, UpdateEventHandlerRequest, UpdateJournalEntryRequest, UpdateTaxonomyBlockRequest } from '../types.gen';
2
2
  import type { TokenProvider } from './graphql/client';
3
3
  import { type GetInformationBlockQuery, type GetLedgerAccountRollupsQuery, type GetLedgerAccountTreeQuery, type GetLedgerAgentQuery, type GetLedgerClosingBookStructuresQuery, type GetLedgerEntityQuery, type GetLedgerEventBlockQuery, type GetLedgerFiscalCalendarQuery, type GetLedgerMappedTrialBalanceQuery, type GetLedgerMappingCoverageQuery, type GetLedgerMappingQuery, type GetLedgerPeriodCloseStatusQuery, type GetLedgerPeriodDraftsQuery, type GetLedgerPublishListQuery, type GetLedgerReportingTaxonomyQuery, type GetLedgerReportPackageQuery, type GetLedgerReportQuery, type GetLedgerStatementQuery, type GetLedgerSummaryQuery, type GetLedgerTransactionQuery, type GetLedgerTrialBalanceQuery, type ListInformationBlocksQuery, type ListLedgerAccountsQuery, type ListLedgerAgentsQuery, type ListLedgerElementsQuery, type ListLedgerEntitiesQuery, type ListLedgerEventBlocksQuery, type ListLedgerMappingsQuery, type ListLedgerPublishListsQuery, type ListLedgerReportsQuery, type ListLedgerStructuresQuery, type ListLedgerTaxonomiesQuery, type ListLedgerTransactionsQuery, type ListLedgerUnmappedElementsQuery } from './graphql/generated/graphql';
4
4
  export type LedgerEntity = NonNullable<GetLedgerEntityQuery['entity']>;
@@ -67,10 +67,17 @@ export interface CreateReportOptions {
67
67
  comparative?: boolean;
68
68
  periods?: PeriodSpecInput[];
69
69
  }
70
- export interface ReportOperationAck {
70
+ /**
71
+ * Wrapper returned by report write methods — pairs the audit-side
72
+ * envelope fields (`operationId`, `status`) with the typed result
73
+ * payload. Generic on ``T`` so each method advertises its specific
74
+ * result type (e.g. ``ReportResponse`` for creates, ``DeleteResult``
75
+ * for deletes).
76
+ */
77
+ export interface ReportOperationAck<T = unknown> {
71
78
  operationId: string;
72
79
  status: OperationEnvelope['status'];
73
- result: Record<string, unknown> | null;
80
+ result: T | null;
74
81
  }
75
82
  export interface InitializeLedgerResult {
76
83
  fiscalCalendar: LedgerFiscalCalendar;
@@ -136,6 +143,13 @@ export interface CreateJournalEntryOptions {
136
143
  type?: LedgerEntryType;
137
144
  status?: 'draft' | 'posted';
138
145
  transactionId?: string | null;
146
+ /**
147
+ * Who fired the event. Defaults to `'manual'` (user-initiated journal
148
+ * entry). Sync adapters (QuickBooks, Plaid, etc.) override with their
149
+ * adapter name. Must match the server's CHECK constraint set:
150
+ * `manual | schedule | system | quickbooks | xero | plaid`.
151
+ */
152
+ source?: string;
139
153
  idempotencyKey?: string | null;
140
154
  }
141
155
  interface LedgerClientConfig {
@@ -252,18 +266,16 @@ export declare class LedgerClient {
252
266
  * Link the graph's entity to a taxonomy (ENTITY_HAS_TAXONOMY edge).
253
267
  * Idempotent — returns existing linkage if already present.
254
268
  */
255
- linkEntityTaxonomy(graphId: string, body: LinkEntityTaxonomyRequest): Promise<Record<string, unknown>>;
269
+ linkEntityTaxonomy(graphId: string, body: LinkEntityTaxonomyRequest): Promise<EntityTaxonomyResponse>;
256
270
  /**
257
271
  * Create a taxonomy block atomically (taxonomy + structures + elements +
258
272
  * associations + rules in one envelope).
259
273
  */
260
- createTaxonomyBlock(graphId: string, body: CreateTaxonomyBlockRequest, idempotencyKey?: string): Promise<Record<string, unknown>>;
274
+ createTaxonomyBlock(graphId: string, body: CreateTaxonomyBlockRequest, idempotencyKey?: string): Promise<TaxonomyBlockEnvelope>;
261
275
  /** Update a taxonomy block — add/update/remove elements, structures, associations, or rules. */
262
- updateTaxonomyBlock(graphId: string, body: UpdateTaxonomyBlockRequest): Promise<Record<string, unknown>>;
276
+ updateTaxonomyBlock(graphId: string, body: UpdateTaxonomyBlockRequest): Promise<TaxonomyBlockEnvelope>;
263
277
  /** Delete a taxonomy block. Cascades through elements, structures, and associations. */
264
- deleteTaxonomyBlock(graphId: string, body: DeleteTaxonomyBlockRequest): Promise<{
265
- deleted: boolean;
266
- }>;
278
+ deleteTaxonomyBlock(graphId: string, body: DeleteTaxonomyBlockRequest): Promise<DeleteTaxonomyBlockResponse>;
267
279
  /** List elements (CoA accounts, GAAP concepts, etc.) with filters. */
268
280
  listElements(graphId: string, options?: {
269
281
  taxonomyId?: string;
@@ -289,11 +301,9 @@ export declare class LedgerClient {
289
301
  /** Mapping coverage stats — how many CoA elements are mapped. */
290
302
  getMappingCoverage(graphId: string, mappingId: string): Promise<LedgerMappingCoverage | null>;
291
303
  /** Create a manual mapping association between two elements. */
292
- createMappingAssociation(graphId: string, body: CreateMappingAssociationOperation): Promise<Record<string, unknown>>;
304
+ createMappingAssociation(graphId: string, body: CreateMappingAssociationOperation): Promise<AssociationResponse>;
293
305
  /** Delete a mapping association. */
294
- deleteMappingAssociation(graphId: string, body: DeleteMappingAssociationOperation): Promise<{
295
- deleted: boolean;
296
- }>;
306
+ deleteMappingAssociation(graphId: string, body: DeleteMappingAssociationOperation): Promise<DeleteResult>;
297
307
  /**
298
308
  * Trigger the AI MappingAgent. Returns the operation id — async; the
299
309
  * agent runs in the background. Consumers can subscribe to progress
@@ -325,17 +335,17 @@ export declare class LedgerClient {
325
335
  /** Update mutable fields on a schedule (name, entry_template, metadata). */
326
336
  updateSchedule(graphId: string, structureId: string, options: {
327
337
  name?: string;
328
- }): Promise<Record<string, unknown>>;
338
+ }): Promise<InformationBlockEnvelope>;
329
339
  /** Permanently delete a schedule (cascades through facts + associations). */
330
- deleteSchedule(graphId: string, structureId: string): Promise<{
331
- deleted: boolean;
332
- }>;
340
+ deleteSchedule(graphId: string, structureId: string): Promise<DeleteInformationBlockResponse>;
333
341
  /**
334
342
  * Dispose of a schedule asset — atomically truncates forward facts,
335
343
  * deletes the SumEquals rule, and posts a balanced disposal entry.
336
344
  *
337
345
  * Routes through `create-event-block` with `event_type='asset_disposed'`.
338
346
  * `occurred_at` is required and represents the disposal date.
347
+ * `source` defaults to `'manual'` (user-initiated disposal); sync
348
+ * adapters override.
339
349
  */
340
350
  disposeSchedule(graphId: string, options: {
341
351
  scheduleId: string;
@@ -345,9 +355,10 @@ export declare class LedgerClient {
345
355
  gainLossElementId?: string | null;
346
356
  memo?: string | null;
347
357
  reason?: string;
348
- }): Promise<Record<string, unknown>>;
358
+ source?: string;
359
+ }): Promise<EventBlockEnvelope>;
349
360
  /** Evaluate taxonomy rules against facts in a structure. */
350
- evaluateRules(graphId: string, body: EvaluateRulesRequest): Promise<Record<string, unknown>>;
361
+ evaluateRules(graphId: string, body: EvaluateRulesRequest): Promise<EvaluateRulesResponse>;
351
362
  /** Close status for all schedules in a fiscal period. */
352
363
  getPeriodCloseStatus(graphId: string, periodStart: string, periodEnd: string): Promise<LedgerPeriodCloseStatus | null>;
353
364
  /** All draft entries in a period, fully expanded for review pre-close. */
@@ -361,7 +372,7 @@ export declare class LedgerClient {
361
372
  * the underlying handler is idempotent and dispatches to one of
362
373
  * created / unchanged / regenerated / removed / skipped internally.
363
374
  */
364
- createClosingEntry(graphId: string, structureId: string, postingDate: string, periodStart: string, periodEnd: string, memo?: string): Promise<Record<string, unknown>>;
375
+ createClosingEntry(graphId: string, structureId: string, postingDate: string, periodStart: string, periodEnd: string, memo?: string): Promise<EventBlockEnvelope>;
365
376
  /** Grouped closing book structures for the close-screen sidebar. */
366
377
  getClosingBookStructures(graphId: string): Promise<LedgerClosingBookStructures | null>;
367
378
  /** Current fiscal calendar state — pointers, gap, closeable status. */
@@ -389,25 +400,25 @@ export declare class LedgerClient {
389
400
  * Returns the EventBlockEnvelope (event row fields); query the ledger
390
401
  * separately if you need the resulting entry_id.
391
402
  */
392
- createJournalEntry(graphId: string, options: CreateJournalEntryOptions): Promise<Record<string, unknown>>;
403
+ createJournalEntry(graphId: string, options: CreateJournalEntryOptions): Promise<EventBlockEnvelope>;
393
404
  /** Update a draft journal entry. Posted entries are immutable. */
394
- updateJournalEntry(graphId: string, body: UpdateJournalEntryRequest): Promise<Record<string, unknown>>;
405
+ updateJournalEntry(graphId: string, body: UpdateJournalEntryRequest): Promise<JournalEntryResponse>;
395
406
  /** Hard-delete a draft journal entry. Posted entries must be reversed. */
396
- deleteJournalEntry(graphId: string, entryId: string): Promise<{
397
- deleted: boolean;
398
- }>;
407
+ deleteJournalEntry(graphId: string, entryId: string): Promise<DeleteResult>;
399
408
  /**
400
409
  * Reverse a posted journal entry — creates an offsetting entry and marks
401
410
  * the original as reversed.
402
411
  *
403
412
  * Routes through `create-event-block` with
404
- * `event_type='journal_entry_reversed'`.
413
+ * `event_type='journal_entry_reversed'`. `source` defaults to `'manual'`
414
+ * — sync adapters override.
405
415
  */
406
416
  reverseJournalEntry(graphId: string, entryId: string, options?: {
407
417
  postingDate?: string | null;
408
418
  memo?: string | null;
409
419
  reason?: string | null;
410
- }): Promise<Record<string, unknown>>;
420
+ source?: string;
421
+ }): Promise<EventBlockEnvelope>;
411
422
  /**
412
423
  * Dry-run an event block — resolve the handler, evaluate metadata, and
413
424
  * return the planned GL rows without writing anything. Companion to
@@ -416,38 +427,38 @@ export declare class LedgerClient {
416
427
  * (the underlying `CreateEventBlockRequest`) and inspect what the
417
428
  * handler would do.
418
429
  */
419
- previewEventBlock(graphId: string, body: CreateEventBlockRequest): Promise<Record<string, unknown>>;
430
+ previewEventBlock(graphId: string, body: CreateEventBlockRequest): Promise<PreviewEventBlockResponse>;
420
431
  /**
421
432
  * Apply a status transition and/or field corrections to an existing
422
433
  * event block. Use for posting drafts (`classified` → `committed` →
423
434
  * `fulfilled`), voiding, superseding (correction chains), or patching
424
435
  * `description` / `effective_at` / `metadata`.
425
436
  */
426
- updateEventBlock(graphId: string, body: UpdateEventBlockRequest): Promise<Record<string, unknown>>;
437
+ updateEventBlock(graphId: string, body: UpdateEventBlockRequest): Promise<EventBlockEnvelope>;
427
438
  /**
428
439
  * Create an agent — REA counterparty (customer, vendor, employee, etc.)
429
440
  * referenced by event blocks via `agent_id`. `(source, external_id)` is
430
441
  * unique when `external_id` is provided, so external-source ingestion is
431
442
  * idempotent at the DB level.
432
443
  */
433
- createAgent(graphId: string, body: CreateAgentRequest, idempotencyKey?: string): Promise<Record<string, unknown>>;
444
+ createAgent(graphId: string, body: CreateAgentRequest, idempotencyKey?: string): Promise<LedgerAgentResponse>;
434
445
  /**
435
446
  * Update an agent. `metadata_patch` is a partial merge into the existing
436
447
  * metadata object; all other fields replace.
437
448
  */
438
- updateAgent(graphId: string, body: UpdateAgentRequest): Promise<Record<string, unknown>>;
449
+ updateAgent(graphId: string, body: UpdateAgentRequest): Promise<LedgerAgentResponse>;
439
450
  /**
440
451
  * Register a tenant-configurable event handler — DSL row in the
441
452
  * `event_handlers` table that drives `create-event-block` for event
442
453
  * types not covered by a Python handler. Match selectors plus a
443
454
  * `transaction_template` describing the GL rows to produce.
444
455
  */
445
- createEventHandler(graphId: string, body: CreateEventHandlerRequest): Promise<Record<string, unknown>>;
456
+ createEventHandler(graphId: string, body: CreateEventHandlerRequest): Promise<EventHandlerResponse>;
446
457
  /**
447
458
  * Update a registered event handler. Pass `approve: true` to flip an
448
459
  * AI-suggested handler from unapproved to active.
449
460
  */
450
- updateEventHandler(graphId: string, body: UpdateEventHandlerRequest): Promise<Record<string, unknown>>;
461
+ updateEventHandler(graphId: string, body: UpdateEventHandlerRequest): Promise<EventHandlerResponse>;
451
462
  /**
452
463
  * Live financial statement — pulls facts directly from the graph for
453
464
  * an explicit period window (or fiscal year) and returns the statement
@@ -479,7 +490,7 @@ export declare class LedgerClient {
479
490
  * Kick off report creation (async). Use the returned `operationId` to
480
491
  * subscribe to progress via SSE, then call `getReport()` once finished.
481
492
  */
482
- createReport(graphId: string, options: CreateReportOptions): Promise<ReportOperationAck>;
493
+ createReport(graphId: string, options: CreateReportOptions): Promise<ReportOperationAck<ReportResponse>>;
483
494
  /** List all reports for a graph (includes received shared reports). */
484
495
  listReports(graphId: string): Promise<ReportListItem[]>;
485
496
  /** Get a single report with its period list + available structures. */
@@ -501,26 +512,26 @@ export declare class LedgerClient {
501
512
  * Regenerate an existing report (async). Returns an operation id;
502
513
  * subscribe via SSE for progress.
503
514
  */
504
- regenerateReport(graphId: string, reportId: string, periodStart?: string, periodEnd?: string): Promise<ReportOperationAck>;
515
+ regenerateReport(graphId: string, reportId: string, periodStart?: string, periodEnd?: string): Promise<ReportOperationAck<ReportResponse>>;
505
516
  /** Delete a report and its generated facts. */
506
- deleteReport(graphId: string, reportId: string): Promise<void>;
517
+ deleteReport(graphId: string, reportId: string): Promise<DeleteResult>;
507
518
  /**
508
- * Share a published report to every member of a publish list (async).
509
- * Each target graph receives a snapshot copy of the report's facts.
519
+ * Share a published report to every member of a publish list. Each
520
+ * target graph receives a snapshot copy of the report's facts.
510
521
  */
511
- shareReport(graphId: string, reportId: string, publishListId: string): Promise<ReportOperationAck>;
522
+ shareReport(graphId: string, reportId: string, publishListId: string): Promise<ReportOperationAck<ShareReportResponse>>;
512
523
  /**
513
524
  * Transition a Report's filing_status to 'filed' — locks the package.
514
525
  * Allowed from 'draft' or 'under_review'. Stamps filed_at + filed_by
515
526
  * from the auth context + server clock.
516
527
  */
517
- fileReport(graphId: string, reportId: string): Promise<ReportOperationAck>;
528
+ fileReport(graphId: string, reportId: string): Promise<ReportOperationAck<ReportResponse>>;
518
529
  /**
519
530
  * Move a Report along the non-file legs of the filing lifecycle
520
531
  * (draft ↔ under_review, filed → archived). Use ``fileReport`` to
521
532
  * reach 'filed' so the audit fields land cleanly.
522
533
  */
523
- transitionFilingStatus(graphId: string, reportId: string, targetStatus: string): Promise<ReportOperationAck>;
534
+ transitionFilingStatus(graphId: string, reportId: string, targetStatus: string): Promise<ReportOperationAck<ReportResponse>>;
524
535
  /** Check if a report was received via sharing (vs locally created). */
525
536
  isSharedReport(report: Report): boolean;
526
537
  /** List publish lists with pagination. */
@@ -529,26 +540,36 @@ export declare class LedgerClient {
529
540
  offset?: number;
530
541
  }): Promise<PublishList[]>;
531
542
  /** Create a new publish list. */
532
- createPublishList(graphId: string, name: string, description?: string): Promise<Record<string, unknown>>;
543
+ createPublishList(graphId: string, name: string, description?: string): Promise<PublishListResponse>;
533
544
  /** Get a single publish list with its full member list. */
534
545
  getPublishList(graphId: string, listId: string): Promise<PublishListDetail | null>;
535
546
  /** Update a publish list's name or description. */
536
547
  updatePublishList(graphId: string, listId: string, updates: {
537
548
  name?: string;
538
549
  description?: string | null;
539
- }): Promise<Record<string, unknown>>;
550
+ }): Promise<PublishListResponse>;
540
551
  /** Delete a publish list. */
541
- deletePublishList(graphId: string, listId: string): Promise<void>;
552
+ deletePublishList(graphId: string, listId: string): Promise<DeleteResult>;
542
553
  /** Add target graphs as members of a publish list. */
543
- addPublishListMembers(graphId: string, listId: string, targetGraphIds: string[]): Promise<Record<string, unknown>>;
554
+ addPublishListMembers(graphId: string, listId: string, targetGraphIds: string[]): Promise<PublishListMemberResponse[]>;
544
555
  /** Remove a single member from a publish list. */
545
- removePublishListMember(graphId: string, listId: string, memberId: string): Promise<{
546
- deleted: boolean;
547
- }>;
556
+ removePublishListMember(graphId: string, listId: string, memberId: string): Promise<DeleteResult>;
548
557
  /**
549
558
  * Await an SDK-generated `opXxx(...)` call, throw a readable error on
550
- * non-2xx, and return the `OperationEnvelope` on success.
559
+ * non-2xx, and return the parsed envelope on success.
560
+ *
561
+ * Generic over the SDK call's response shape so typed ops (e.g.
562
+ * `opCreateEventBlock`, which returns
563
+ * `OperationEnvelopeEventBlockEnvelope`) flow through with a typed
564
+ * `envelope.result` instead of being widened to `unknown`. Untyped
565
+ * ops continue to land as `OperationEnvelope` automatically.
551
566
  */
552
567
  private callOperation;
568
+ /**
569
+ * Unwrap the typed result from an OperationEnvelope. Throws when the
570
+ * server returned an envelope with no `result` field — generally a
571
+ * sign that a synchronous operation failed silently.
572
+ */
573
+ private requireResult;
553
574
  }
554
575
  export {};
@@ -150,7 +150,7 @@ class LedgerClient {
150
150
  */
151
151
  async linkEntityTaxonomy(graphId, body) {
152
152
  const envelope = await this.callOperation('Link entity taxonomy', (0, sdk_gen_1.opLinkEntityTaxonomy)({ path: { graph_id: graphId }, body }));
153
- return (envelope.result ?? {});
153
+ return this.requireResult('Link entity taxonomy', envelope.result);
154
154
  }
155
155
  /**
156
156
  * Create a taxonomy block atomically (taxonomy + structures + elements +
@@ -159,12 +159,12 @@ class LedgerClient {
159
159
  async createTaxonomyBlock(graphId, body, idempotencyKey) {
160
160
  const headers = idempotencyKey ? { 'Idempotency-Key': idempotencyKey } : undefined;
161
161
  const envelope = await this.callOperation('Create taxonomy block', (0, sdk_gen_1.opCreateTaxonomyBlock)({ path: { graph_id: graphId }, body, headers }));
162
- return (envelope.result ?? {});
162
+ return this.requireResult('Create taxonomy block', envelope.result);
163
163
  }
164
164
  /** Update a taxonomy block — add/update/remove elements, structures, associations, or rules. */
165
165
  async updateTaxonomyBlock(graphId, body) {
166
166
  const envelope = await this.callOperation('Update taxonomy block', (0, sdk_gen_1.opUpdateTaxonomyBlock)({ path: { graph_id: graphId }, body }));
167
- return (envelope.result ?? {});
167
+ return this.requireResult('Update taxonomy block', envelope.result);
168
168
  }
169
169
  /** Delete a taxonomy block. Cascades through elements, structures, and associations. */
170
170
  async deleteTaxonomyBlock(graphId, body) {
@@ -212,7 +212,7 @@ class LedgerClient {
212
212
  /** Create a manual mapping association between two elements. */
213
213
  async createMappingAssociation(graphId, body) {
214
214
  const envelope = await this.callOperation('Create mapping association', (0, sdk_gen_1.opCreateMappingAssociation)({ path: { graph_id: graphId }, body }));
215
- return (envelope.result ?? {});
215
+ return this.requireResult('Create mapping association', envelope.result);
216
216
  }
217
217
  /** Delete a mapping association. */
218
218
  async deleteMappingAssociation(graphId, body) {
@@ -298,7 +298,7 @@ class LedgerClient {
298
298
  payload: { structure_id: structureId, ...options },
299
299
  };
300
300
  const envelope = await this.callOperation('Update schedule', (0, sdk_gen_1.opUpdateInformationBlock)({ path: { graph_id: graphId }, body }));
301
- return (envelope.result ?? {});
301
+ return this.requireResult('Update schedule', envelope.result);
302
302
  }
303
303
  /** Permanently delete a schedule (cascades through facts + associations). */
304
304
  async deleteSchedule(graphId, structureId) {
@@ -315,12 +315,14 @@ class LedgerClient {
315
315
  *
316
316
  * Routes through `create-event-block` with `event_type='asset_disposed'`.
317
317
  * `occurred_at` is required and represents the disposal date.
318
+ * `source` defaults to `'manual'` (user-initiated disposal); sync
319
+ * adapters override.
318
320
  */
319
321
  async disposeSchedule(graphId, options) {
320
322
  const body = {
321
323
  event_type: 'asset_disposed',
322
324
  event_category: 'adjustment',
323
- source: 'native',
325
+ source: options.source ?? 'manual',
324
326
  occurred_at: options.occurredAt,
325
327
  apply_handlers: true,
326
328
  metadata: {
@@ -333,12 +335,12 @@ class LedgerClient {
333
335
  },
334
336
  };
335
337
  const envelope = await this.callOperation('Dispose schedule', (0, sdk_gen_1.opCreateEventBlock)({ path: { graph_id: graphId }, body }));
336
- return (envelope.result ?? {});
338
+ return this.requireResult('Dispose schedule', envelope.result);
337
339
  }
338
340
  /** Evaluate taxonomy rules against facts in a structure. */
339
341
  async evaluateRules(graphId, body) {
340
342
  const envelope = await this.callOperation('Evaluate rules', (0, sdk_gen_1.opEvaluateRules)({ path: { graph_id: graphId }, body }));
341
- return (envelope.result ?? {});
343
+ return this.requireResult('Evaluate rules', envelope.result);
342
344
  }
343
345
  // ── Period close ────────────────────────────────────────────────────
344
346
  /** Close status for all schedules in a fiscal period. */
@@ -362,7 +364,8 @@ class LedgerClient {
362
364
  const body = {
363
365
  event_type: 'schedule_entry_due',
364
366
  event_category: 'recognition',
365
- source: 'scheduled',
367
+ // Always 'schedule' — this op is schedule-driven by definition.
368
+ source: 'schedule',
366
369
  occurred_at: `${postingDate}T00:00:00Z`,
367
370
  apply_handlers: true,
368
371
  metadata: {
@@ -374,7 +377,7 @@ class LedgerClient {
374
377
  },
375
378
  };
376
379
  const envelope = await this.callOperation('Create closing entry', (0, sdk_gen_1.opCreateEventBlock)({ path: { graph_id: graphId }, body }));
377
- return (envelope.result ?? {});
380
+ return this.requireResult('Create closing entry', envelope.result);
378
381
  }
379
382
  // ── Closing book ───────────────────────────────────────────────────
380
383
  /** Grouped closing book structures for the close-screen sidebar. */
@@ -455,7 +458,7 @@ class LedgerClient {
455
458
  const body = {
456
459
  event_type: 'journal_entry_recorded',
457
460
  event_category: 'adjustment',
458
- source: 'native',
461
+ source: options.source ?? 'manual',
459
462
  occurred_at: `${options.postingDate}T00:00:00Z`,
460
463
  apply_handlers: true,
461
464
  metadata: {
@@ -476,12 +479,12 @@ class LedgerClient {
476
479
  ? { 'Idempotency-Key': options.idempotencyKey }
477
480
  : undefined;
478
481
  const envelope = await this.callOperation('Create journal entry', (0, sdk_gen_1.opCreateEventBlock)({ path: { graph_id: graphId }, body, headers }));
479
- return (envelope.result ?? {});
482
+ return this.requireResult('Create journal entry', envelope.result);
480
483
  }
481
484
  /** Update a draft journal entry. Posted entries are immutable. */
482
485
  async updateJournalEntry(graphId, body) {
483
486
  const envelope = await this.callOperation('Update journal entry', (0, sdk_gen_1.opUpdateJournalEntry)({ path: { graph_id: graphId }, body }));
484
- return (envelope.result ?? {});
487
+ return this.requireResult('Update journal entry', envelope.result);
485
488
  }
486
489
  /** Hard-delete a draft journal entry. Posted entries must be reversed. */
487
490
  async deleteJournalEntry(graphId, entryId) {
@@ -494,14 +497,15 @@ class LedgerClient {
494
497
  * the original as reversed.
495
498
  *
496
499
  * Routes through `create-event-block` with
497
- * `event_type='journal_entry_reversed'`.
500
+ * `event_type='journal_entry_reversed'`. `source` defaults to `'manual'`
501
+ * — sync adapters override.
498
502
  */
499
503
  async reverseJournalEntry(graphId, entryId, options) {
500
504
  const occurredDate = options?.postingDate ?? new Date().toISOString().slice(0, 10);
501
505
  const body = {
502
506
  event_type: 'journal_entry_reversed',
503
507
  event_category: 'adjustment',
504
- source: 'native',
508
+ source: options?.source ?? 'manual',
505
509
  occurred_at: `${occurredDate}T00:00:00Z`,
506
510
  apply_handlers: true,
507
511
  metadata: {
@@ -512,7 +516,7 @@ class LedgerClient {
512
516
  },
513
517
  };
514
518
  const envelope = await this.callOperation('Reverse journal entry', (0, sdk_gen_1.opCreateEventBlock)({ path: { graph_id: graphId }, body }));
515
- return (envelope.result ?? {});
519
+ return this.requireResult('Reverse journal entry', envelope.result);
516
520
  }
517
521
  // ── Event blocks (generic preview + status transitions) ──────────────
518
522
  /**
@@ -525,7 +529,7 @@ class LedgerClient {
525
529
  */
526
530
  async previewEventBlock(graphId, body) {
527
531
  const envelope = await this.callOperation('Preview event block', (0, sdk_gen_1.opPreviewEventBlock)({ path: { graph_id: graphId }, body }));
528
- return (envelope.result ?? {});
532
+ return this.requireResult('Preview event block', envelope.result);
529
533
  }
530
534
  /**
531
535
  * Apply a status transition and/or field corrections to an existing
@@ -535,7 +539,7 @@ class LedgerClient {
535
539
  */
536
540
  async updateEventBlock(graphId, body) {
537
541
  const envelope = await this.callOperation('Update event block', (0, sdk_gen_1.opUpdateEventBlock)({ path: { graph_id: graphId }, body }));
538
- return (envelope.result ?? {});
542
+ return this.requireResult('Update event block', envelope.result);
539
543
  }
540
544
  // ── Agents (REA counterparties) ───────────────────────────────────────
541
545
  /**
@@ -547,7 +551,7 @@ class LedgerClient {
547
551
  async createAgent(graphId, body, idempotencyKey) {
548
552
  const headers = idempotencyKey ? { 'Idempotency-Key': idempotencyKey } : undefined;
549
553
  const envelope = await this.callOperation('Create agent', (0, sdk_gen_1.opCreateAgent)({ path: { graph_id: graphId }, body, headers }));
550
- return (envelope.result ?? {});
554
+ return this.requireResult('Create agent', envelope.result);
551
555
  }
552
556
  /**
553
557
  * Update an agent. `metadata_patch` is a partial merge into the existing
@@ -555,7 +559,7 @@ class LedgerClient {
555
559
  */
556
560
  async updateAgent(graphId, body) {
557
561
  const envelope = await this.callOperation('Update agent', (0, sdk_gen_1.opUpdateAgent)({ path: { graph_id: graphId }, body }));
558
- return (envelope.result ?? {});
562
+ return this.requireResult('Update agent', envelope.result);
559
563
  }
560
564
  // ── Event handlers (DSL handler registry) ────────────────────────────
561
565
  /**
@@ -566,7 +570,7 @@ class LedgerClient {
566
570
  */
567
571
  async createEventHandler(graphId, body) {
568
572
  const envelope = await this.callOperation('Create event handler', (0, sdk_gen_1.opCreateEventHandler)({ path: { graph_id: graphId }, body }));
569
- return (envelope.result ?? {});
573
+ return this.requireResult('Create event handler', envelope.result);
570
574
  }
571
575
  /**
572
576
  * Update a registered event handler. Pass `approve: true` to flip an
@@ -574,7 +578,7 @@ class LedgerClient {
574
578
  */
575
579
  async updateEventHandler(graphId, body) {
576
580
  const envelope = await this.callOperation('Update event handler', (0, sdk_gen_1.opUpdateEventHandler)({ path: { graph_id: graphId }, body }));
577
- return (envelope.result ?? {});
581
+ return this.requireResult('Update event handler', envelope.result);
578
582
  }
579
583
  // ── Financial statements (graph-backed) ──────────────────────────────
580
584
  /**
@@ -704,14 +708,15 @@ class LedgerClient {
704
708
  }
705
709
  /** Delete a report and its generated facts. */
706
710
  async deleteReport(graphId, reportId) {
707
- await this.callOperation('Delete report', (0, sdk_gen_1.opDeleteReport)({
711
+ const envelope = await this.callOperation('Delete report', (0, sdk_gen_1.opDeleteReport)({
708
712
  path: { graph_id: graphId },
709
713
  body: { report_id: reportId },
710
714
  }));
715
+ return (envelope.result ?? { deleted: true });
711
716
  }
712
717
  /**
713
- * Share a published report to every member of a publish list (async).
714
- * Each target graph receives a snapshot copy of the report's facts.
718
+ * Share a published report to every member of a publish list. Each
719
+ * target graph receives a snapshot copy of the report's facts.
715
720
  */
716
721
  async shareReport(graphId, reportId, publishListId) {
717
722
  const envelope = await this.callOperation('Share report', (0, sdk_gen_1.opShareReport)({
@@ -778,7 +783,7 @@ class LedgerClient {
778
783
  description: description ?? null,
779
784
  };
780
785
  const envelope = await this.callOperation('Create publish list', (0, sdk_gen_1.opCreatePublishList)({ path: { graph_id: graphId }, body }));
781
- return (envelope.result ?? {});
786
+ return this.requireResult('Create publish list', envelope.result);
782
787
  }
783
788
  /** Get a single publish list with its full member list. */
784
789
  async getPublishList(graphId, listId) {
@@ -794,14 +799,15 @@ class LedgerClient {
794
799
  description: updates.description ?? null,
795
800
  },
796
801
  }));
797
- return (envelope.result ?? {});
802
+ return this.requireResult('Update publish list', envelope.result);
798
803
  }
799
804
  /** Delete a publish list. */
800
805
  async deletePublishList(graphId, listId) {
801
- await this.callOperation('Delete publish list', (0, sdk_gen_1.opDeletePublishList)({
806
+ const envelope = await this.callOperation('Delete publish list', (0, sdk_gen_1.opDeletePublishList)({
802
807
  path: { graph_id: graphId },
803
808
  body: { list_id: listId },
804
809
  }));
810
+ return (envelope.result ?? { deleted: true });
805
811
  }
806
812
  /** Add target graphs as members of a publish list. */
807
813
  async addPublishListMembers(graphId, listId, targetGraphIds) {
@@ -812,7 +818,7 @@ class LedgerClient {
812
818
  target_graph_ids: targetGraphIds,
813
819
  },
814
820
  }));
815
- return (envelope.result ?? {});
821
+ return this.requireResult('Add publish list members', envelope.result);
816
822
  }
817
823
  /** Remove a single member from a publish list. */
818
824
  async removePublishListMember(graphId, listId, memberId) {
@@ -825,7 +831,13 @@ class LedgerClient {
825
831
  // ── Internal helpers ────────────────────────────────────────────────
826
832
  /**
827
833
  * Await an SDK-generated `opXxx(...)` call, throw a readable error on
828
- * non-2xx, and return the `OperationEnvelope` on success.
834
+ * non-2xx, and return the parsed envelope on success.
835
+ *
836
+ * Generic over the SDK call's response shape so typed ops (e.g.
837
+ * `opCreateEventBlock`, which returns
838
+ * `OperationEnvelopeEventBlockEnvelope`) flow through with a typed
839
+ * `envelope.result` instead of being widened to `unknown`. Untyped
840
+ * ops continue to land as `OperationEnvelope` automatically.
829
841
  */
830
842
  async callOperation(label, call) {
831
843
  const response = await call;
@@ -837,6 +849,17 @@ class LedgerClient {
837
849
  }
838
850
  return response.data;
839
851
  }
852
+ /**
853
+ * Unwrap the typed result from an OperationEnvelope. Throws when the
854
+ * server returned an envelope with no `result` field — generally a
855
+ * sign that a synchronous operation failed silently.
856
+ */
857
+ requireResult(label, result) {
858
+ if (result === null || result === undefined) {
859
+ throw new Error(`${label}: operation envelope had no result`);
860
+ }
861
+ return result;
862
+ }
840
863
  }
841
864
  exports.LedgerClient = LedgerClient;
842
865
  // ── Module-private conversion helpers ─────────────────────────────────