@robosystems/client 0.3.10 → 0.3.12
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.
- package/artifacts/LedgerClient.d.ts +89 -72
- package/artifacts/LedgerClient.js +170 -105
- package/artifacts/LedgerClient.ts +260 -220
- package/artifacts/OperationClient.js +14 -0
- package/artifacts/OperationClient.ts +15 -0
- package/artifacts/SSEClient.js +21 -3
- package/artifacts/SSEClient.ts +26 -3
- package/artifacts/graphql/generated/graphql.d.ts +32 -0
- package/artifacts/graphql/generated/graphql.ts +35 -0
- package/index.ts +2 -2
- package/package.json +1 -1
- package/sdk/index.d.ts +2 -2
- package/sdk/index.js +9 -9
- package/sdk/index.ts +2 -2
- package/sdk/sdk.gen.d.ts +31 -31
- package/sdk/sdk.gen.js +51 -51
- package/sdk/sdk.gen.ts +41 -41
- package/sdk/types.gen.d.ts +538 -390
- package/sdk/types.gen.ts +543 -393
- package/sdk.gen.d.ts +31 -31
- package/sdk.gen.js +51 -51
- package/sdk.gen.ts +41 -41
- package/types.gen.d.ts +538 -390
- package/types.gen.ts +543 -393
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AutoMapElementsOperation, CreateMappingAssociationOperation, CreateTaxonomyBlockRequest, CreateViewRequest, DeleteMappingAssociationOperation, DeleteTaxonomyBlockRequest,
|
|
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';
|
|
2
2
|
import type { TokenProvider } from './graphql/client';
|
|
3
3
|
import { type GetInformationBlockQuery, type GetLedgerAccountRollupsQuery, type GetLedgerAccountTreeQuery, type GetLedgerClosingBookStructuresQuery, type GetLedgerEntityQuery, type GetLedgerFiscalCalendarQuery, type GetLedgerMappedTrialBalanceQuery, type GetLedgerMappingCoverageQuery, type GetLedgerMappingQuery, type GetLedgerPeriodCloseStatusQuery, type GetLedgerPeriodDraftsQuery, type GetLedgerPublishListQuery, type GetLedgerReportingTaxonomyQuery, type GetLedgerReportQuery, type GetLedgerStatementQuery, type GetLedgerSummaryQuery, type GetLedgerTransactionQuery, type GetLedgerTrialBalanceQuery, type ListInformationBlocksQuery, type ListLedgerAccountsQuery, type ListLedgerElementsQuery, type ListLedgerEntitiesQuery, 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']>;
|
|
@@ -77,18 +77,6 @@ export interface ClosePeriodResult {
|
|
|
77
77
|
targetAutoAdvanced: boolean;
|
|
78
78
|
fiscalCalendar: LedgerFiscalCalendar;
|
|
79
79
|
}
|
|
80
|
-
export type ClosingEntryOutcome = 'created' | 'unchanged' | 'regenerated' | 'removed' | 'skipped';
|
|
81
|
-
export interface ClosingEntry {
|
|
82
|
-
outcome: ClosingEntryOutcome;
|
|
83
|
-
entryId: string | null;
|
|
84
|
-
status: string | null;
|
|
85
|
-
postingDate: string | null;
|
|
86
|
-
memo: string | null;
|
|
87
|
-
debitElementId: string | null;
|
|
88
|
-
creditElementId: string | null;
|
|
89
|
-
amount: number | null;
|
|
90
|
-
reason: string | null;
|
|
91
|
-
}
|
|
92
80
|
export interface ScheduleCreated {
|
|
93
81
|
structureId: string;
|
|
94
82
|
name: string;
|
|
@@ -96,12 +84,6 @@ export interface ScheduleCreated {
|
|
|
96
84
|
totalPeriods: number;
|
|
97
85
|
totalFacts: number;
|
|
98
86
|
}
|
|
99
|
-
export interface TruncateScheduleResult {
|
|
100
|
-
structureId: string;
|
|
101
|
-
newEndDate: string;
|
|
102
|
-
factsDeleted: number;
|
|
103
|
-
reason: string;
|
|
104
|
-
}
|
|
105
87
|
export type LedgerEntryType = 'standard' | 'adjusting' | 'closing' | 'reversing';
|
|
106
88
|
export interface InitializeLedgerOptions {
|
|
107
89
|
closedThrough?: string | null;
|
|
@@ -114,22 +96,6 @@ export interface ClosePeriodOptions {
|
|
|
114
96
|
note?: string | null;
|
|
115
97
|
allowStaleSync?: boolean;
|
|
116
98
|
}
|
|
117
|
-
export interface ManualClosingLineItem {
|
|
118
|
-
elementId: string;
|
|
119
|
-
debitAmount?: number;
|
|
120
|
-
creditAmount?: number;
|
|
121
|
-
description?: string | null;
|
|
122
|
-
}
|
|
123
|
-
export interface CreateManualClosingEntryOptions {
|
|
124
|
-
postingDate: string;
|
|
125
|
-
memo: string;
|
|
126
|
-
lineItems: ManualClosingLineItem[];
|
|
127
|
-
entryType?: LedgerEntryType;
|
|
128
|
-
}
|
|
129
|
-
export interface TruncateScheduleOptions {
|
|
130
|
-
newEndDate: string;
|
|
131
|
-
reason: string;
|
|
132
|
-
}
|
|
133
99
|
export interface CreateScheduleOptions {
|
|
134
100
|
name: string;
|
|
135
101
|
elementIds: string[];
|
|
@@ -228,30 +194,6 @@ export declare class LedgerClient {
|
|
|
228
194
|
}): Promise<LedgerTransactionList | null>;
|
|
229
195
|
/** Get transaction detail with entries + line items. */
|
|
230
196
|
getTransaction(graphId: string, transactionId: string): Promise<LedgerTransaction | null>;
|
|
231
|
-
/**
|
|
232
|
-
* Create a standalone business-event Transaction without entries.
|
|
233
|
-
*
|
|
234
|
-
* Returns a `transaction_id` that can be passed to `createJournalEntry`
|
|
235
|
-
* to attach entries to this event. Use when a single event (invoice,
|
|
236
|
-
* payment, deposit) produces multiple entries over its lifecycle.
|
|
237
|
-
*
|
|
238
|
-
* `amount` is in minor currency units (cents).
|
|
239
|
-
* `type` is free-form: invoice, payment, bill, expense, deposit, etc.
|
|
240
|
-
*/
|
|
241
|
-
createTransaction(graphId: string, options: {
|
|
242
|
-
type: string;
|
|
243
|
-
date: string;
|
|
244
|
-
amount: number;
|
|
245
|
-
currency?: string;
|
|
246
|
-
description?: string;
|
|
247
|
-
merchantName?: string;
|
|
248
|
-
referenceNumber?: string;
|
|
249
|
-
number?: string;
|
|
250
|
-
category?: string;
|
|
251
|
-
dueDate?: string;
|
|
252
|
-
status?: 'pending' | 'posted';
|
|
253
|
-
idempotencyKey?: string;
|
|
254
|
-
}): Promise<Record<string, unknown>>;
|
|
255
197
|
/** Trial balance by raw CoA account. */
|
|
256
198
|
getTrialBalance(graphId: string, options?: {
|
|
257
199
|
startDate?: string;
|
|
@@ -350,10 +292,22 @@ export declare class LedgerClient {
|
|
|
350
292
|
deleteSchedule(graphId: string, structureId: string): Promise<{
|
|
351
293
|
deleted: boolean;
|
|
352
294
|
}>;
|
|
353
|
-
/**
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
295
|
+
/**
|
|
296
|
+
* Dispose of a schedule asset — atomically truncates forward facts,
|
|
297
|
+
* deletes the SumEquals rule, and posts a balanced disposal entry.
|
|
298
|
+
*
|
|
299
|
+
* Routes through `create-event-block` with `event_type='asset_disposed'`.
|
|
300
|
+
* `occurred_at` is required and represents the disposal date.
|
|
301
|
+
*/
|
|
302
|
+
disposeSchedule(graphId: string, options: {
|
|
303
|
+
scheduleId: string;
|
|
304
|
+
occurredAt: string;
|
|
305
|
+
proceeds?: number;
|
|
306
|
+
proceedsElementId?: string | null;
|
|
307
|
+
gainLossElementId?: string | null;
|
|
308
|
+
memo?: string | null;
|
|
309
|
+
reason?: string;
|
|
310
|
+
}): Promise<Record<string, unknown>>;
|
|
357
311
|
/** Evaluate taxonomy rules against facts in a structure. */
|
|
358
312
|
evaluateRules(graphId: string, body: EvaluateRulesRequest): Promise<Record<string, unknown>>;
|
|
359
313
|
/** Close status for all schedules in a fiscal period. */
|
|
@@ -362,14 +316,14 @@ export declare class LedgerClient {
|
|
|
362
316
|
listPeriodDrafts(graphId: string, period: string): Promise<LedgerPeriodDrafts | null>;
|
|
363
317
|
/**
|
|
364
318
|
* Idempotently create (or refresh) a draft closing entry from a
|
|
365
|
-
* schedule for a period.
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
*
|
|
370
|
-
*
|
|
319
|
+
* schedule for a period.
|
|
320
|
+
*
|
|
321
|
+
* Routes through `create-event-block` with
|
|
322
|
+
* `event_type='schedule_entry_due'`. Returns the EventBlockEnvelope —
|
|
323
|
+
* the underlying handler is idempotent and dispatches to one of
|
|
324
|
+
* created / unchanged / regenerated / removed / skipped internally.
|
|
371
325
|
*/
|
|
372
|
-
|
|
326
|
+
createClosingEntry(graphId: string, structureId: string, postingDate: string, periodStart: string, periodEnd: string, memo?: string): Promise<Record<string, unknown>>;
|
|
373
327
|
/** Grouped closing book structures for the close-screen sidebar. */
|
|
374
328
|
getClosingBookStructures(graphId: string): Promise<LedgerClosingBookStructures | null>;
|
|
375
329
|
/** Current fiscal calendar state — pointers, gap, closeable status. */
|
|
@@ -385,12 +339,17 @@ export declare class LedgerClient {
|
|
|
385
339
|
/**
|
|
386
340
|
* Create a journal entry with balanced line items (DR=CR enforced).
|
|
387
341
|
*
|
|
388
|
-
*
|
|
389
|
-
*
|
|
342
|
+
* Routes through `create-event-block` with
|
|
343
|
+
* `event_type='journal_entry_recorded'` — the Python handler forwards
|
|
344
|
+
* to the internal journal-entry command. Defaults to `status='draft'`;
|
|
345
|
+
* pass `status='posted'` for historical data imports.
|
|
390
346
|
*
|
|
391
347
|
* Supply `idempotencyKey` to make the call safe to retry — replays
|
|
392
348
|
* within 24 hours return the same envelope. Reusing the key with a
|
|
393
349
|
* different body returns HTTP 409.
|
|
350
|
+
*
|
|
351
|
+
* Returns the EventBlockEnvelope (event row fields); query the ledger
|
|
352
|
+
* separately if you need the resulting entry_id.
|
|
394
353
|
*/
|
|
395
354
|
createJournalEntry(graphId: string, options: CreateJournalEntryOptions): Promise<Record<string, unknown>>;
|
|
396
355
|
/** Update a draft journal entry. Posted entries are immutable. */
|
|
@@ -402,11 +361,69 @@ export declare class LedgerClient {
|
|
|
402
361
|
/**
|
|
403
362
|
* Reverse a posted journal entry — creates an offsetting entry and marks
|
|
404
363
|
* the original as reversed.
|
|
364
|
+
*
|
|
365
|
+
* Routes through `create-event-block` with
|
|
366
|
+
* `event_type='journal_entry_reversed'`.
|
|
405
367
|
*/
|
|
406
368
|
reverseJournalEntry(graphId: string, entryId: string, options?: {
|
|
407
369
|
postingDate?: string | null;
|
|
408
370
|
memo?: string | null;
|
|
371
|
+
reason?: string | null;
|
|
409
372
|
}): Promise<Record<string, unknown>>;
|
|
373
|
+
/**
|
|
374
|
+
* Dry-run an event block — resolve the handler, evaluate metadata, and
|
|
375
|
+
* return the planned GL rows without writing anything. Companion to
|
|
376
|
+
* `createJournalEntry` / `reverseJournalEntry` / `createClosingEntry` /
|
|
377
|
+
* `disposeSchedule`: pass the same body you'd send to those methods
|
|
378
|
+
* (the underlying `CreateEventBlockRequest`) and inspect what the
|
|
379
|
+
* handler would do.
|
|
380
|
+
*/
|
|
381
|
+
previewEventBlock(graphId: string, body: CreateEventBlockRequest): Promise<Record<string, unknown>>;
|
|
382
|
+
/**
|
|
383
|
+
* Apply a status transition and/or field corrections to an existing
|
|
384
|
+
* event block. Use for posting drafts (`classified` → `committed` →
|
|
385
|
+
* `fulfilled`), voiding, superseding (correction chains), or patching
|
|
386
|
+
* `description` / `effective_at` / `metadata`.
|
|
387
|
+
*/
|
|
388
|
+
updateEventBlock(graphId: string, body: UpdateEventBlockRequest): Promise<Record<string, unknown>>;
|
|
389
|
+
/**
|
|
390
|
+
* Create an agent — REA counterparty (customer, vendor, employee, etc.)
|
|
391
|
+
* referenced by event blocks via `agent_id`. `(source, external_id)` is
|
|
392
|
+
* unique when `external_id` is provided, so external-source ingestion is
|
|
393
|
+
* idempotent at the DB level.
|
|
394
|
+
*/
|
|
395
|
+
createAgent(graphId: string, body: CreateAgentRequest, idempotencyKey?: string): Promise<Record<string, unknown>>;
|
|
396
|
+
/**
|
|
397
|
+
* Update an agent. `metadata_patch` is a partial merge into the existing
|
|
398
|
+
* metadata object; all other fields replace.
|
|
399
|
+
*/
|
|
400
|
+
updateAgent(graphId: string, body: UpdateAgentRequest): Promise<Record<string, unknown>>;
|
|
401
|
+
/**
|
|
402
|
+
* Register a tenant-configurable event handler — DSL row in the
|
|
403
|
+
* `event_handlers` table that drives `create-event-block` for event
|
|
404
|
+
* types not covered by a Python handler. Match selectors plus a
|
|
405
|
+
* `transaction_template` describing the GL rows to produce.
|
|
406
|
+
*/
|
|
407
|
+
createEventHandler(graphId: string, body: CreateEventHandlerRequest): Promise<Record<string, unknown>>;
|
|
408
|
+
/**
|
|
409
|
+
* Update a registered event handler. Pass `approve: true` to flip an
|
|
410
|
+
* AI-suggested handler from unapproved to active.
|
|
411
|
+
*/
|
|
412
|
+
updateEventHandler(graphId: string, body: UpdateEventHandlerRequest): Promise<Record<string, unknown>>;
|
|
413
|
+
/**
|
|
414
|
+
* Live financial statement — pulls facts directly from the graph for
|
|
415
|
+
* an explicit period window (or fiscal year) and returns the statement
|
|
416
|
+
* shape without a persisted Report row. Useful for ad-hoc previews and
|
|
417
|
+
* dashboards.
|
|
418
|
+
*/
|
|
419
|
+
liveFinancialStatement(graphId: string, body: LiveFinancialStatementRequest): Promise<Record<string, unknown>>;
|
|
420
|
+
/**
|
|
421
|
+
* Run a financial statement analysis against an existing report.
|
|
422
|
+
* On shared-repo graphs (e.g. SEC), `ticker` is required; on tenant
|
|
423
|
+
* graphs it's ignored. Either pass an explicit `report_id` or let the
|
|
424
|
+
* server auto-resolve via `fiscal_year` + `period_type`.
|
|
425
|
+
*/
|
|
426
|
+
financialStatementAnalysis(graphId: string, body: FinancialStatementAnalysisRequest): Promise<Record<string, unknown>>;
|
|
410
427
|
/**
|
|
411
428
|
* Build a multi-dimensional fact grid against the graph schema.
|
|
412
429
|
*
|
|
@@ -76,36 +76,6 @@ class LedgerClient {
|
|
|
76
76
|
async getTransaction(graphId, transactionId) {
|
|
77
77
|
return this.gqlQuery(graphId, graphql_1.GetLedgerTransactionDocument, { transactionId }, 'Get transaction', (data) => data.transaction);
|
|
78
78
|
}
|
|
79
|
-
/**
|
|
80
|
-
* Create a standalone business-event Transaction without entries.
|
|
81
|
-
*
|
|
82
|
-
* Returns a `transaction_id` that can be passed to `createJournalEntry`
|
|
83
|
-
* to attach entries to this event. Use when a single event (invoice,
|
|
84
|
-
* payment, deposit) produces multiple entries over its lifecycle.
|
|
85
|
-
*
|
|
86
|
-
* `amount` is in minor currency units (cents).
|
|
87
|
-
* `type` is free-form: invoice, payment, bill, expense, deposit, etc.
|
|
88
|
-
*/
|
|
89
|
-
async createTransaction(graphId, options) {
|
|
90
|
-
const body = {
|
|
91
|
-
type: options.type,
|
|
92
|
-
date: options.date,
|
|
93
|
-
amount: options.amount,
|
|
94
|
-
currency: options.currency ?? 'USD',
|
|
95
|
-
status: options.status ?? 'pending',
|
|
96
|
-
description: options.description ?? null,
|
|
97
|
-
merchant_name: options.merchantName ?? null,
|
|
98
|
-
reference_number: options.referenceNumber ?? null,
|
|
99
|
-
number: options.number ?? null,
|
|
100
|
-
category: options.category ?? null,
|
|
101
|
-
due_date: options.dueDate ?? null,
|
|
102
|
-
};
|
|
103
|
-
const headers = options.idempotencyKey
|
|
104
|
-
? { 'Idempotency-Key': options.idempotencyKey }
|
|
105
|
-
: undefined;
|
|
106
|
-
const envelope = await this.callOperation('Create transaction', (0, sdk_gen_1.opCreateTransaction)({ path: { graph_id: graphId }, body, headers }));
|
|
107
|
-
return (envelope.result ?? {});
|
|
108
|
-
}
|
|
109
79
|
// ── Trial Balance ──────────────────────────────────────────────────
|
|
110
80
|
/** Trial balance by raw CoA account. */
|
|
111
81
|
async getTrialBalance(graphId, options) {
|
|
@@ -297,25 +267,30 @@ class LedgerClient {
|
|
|
297
267
|
const envelope = await this.callOperation('Delete schedule', (0, sdk_gen_1.opDeleteInformationBlock)({ path: { graph_id: graphId }, body }));
|
|
298
268
|
return (envelope.result ?? { deleted: true });
|
|
299
269
|
}
|
|
300
|
-
/**
|
|
301
|
-
|
|
270
|
+
/**
|
|
271
|
+
* Dispose of a schedule asset — atomically truncates forward facts,
|
|
272
|
+
* deletes the SumEquals rule, and posts a balanced disposal entry.
|
|
273
|
+
*
|
|
274
|
+
* Routes through `create-event-block` with `event_type='asset_disposed'`.
|
|
275
|
+
* `occurred_at` is required and represents the disposal date.
|
|
276
|
+
*/
|
|
277
|
+
async disposeSchedule(graphId, options) {
|
|
302
278
|
const body = {
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
279
|
+
event_type: 'asset_disposed',
|
|
280
|
+
event_category: 'adjustment',
|
|
281
|
+
source: 'native',
|
|
282
|
+
occurred_at: options.occurredAt,
|
|
283
|
+
apply_handlers: true,
|
|
284
|
+
metadata: {
|
|
285
|
+
schedule_id: options.scheduleId,
|
|
286
|
+
proceeds: options.proceeds ?? 0,
|
|
287
|
+
proceeds_element_id: options.proceedsElementId ?? null,
|
|
288
|
+
gain_loss_element_id: options.gainLossElementId ?? null,
|
|
289
|
+
memo: options.memo ?? null,
|
|
290
|
+
reason: options.reason ?? 'asset_disposed_event',
|
|
291
|
+
},
|
|
314
292
|
};
|
|
315
|
-
|
|
316
|
-
/** Dispose of a schedule asset — post a disposal entry and delete forward facts. */
|
|
317
|
-
async disposeSchedule(graphId, body) {
|
|
318
|
-
const envelope = await this.callOperation('Dispose schedule', (0, sdk_gen_1.opDisposeSchedule)({ path: { graph_id: graphId }, body }));
|
|
293
|
+
const envelope = await this.callOperation('Dispose schedule', (0, sdk_gen_1.opCreateEventBlock)({ path: { graph_id: graphId }, body }));
|
|
319
294
|
return (envelope.result ?? {});
|
|
320
295
|
}
|
|
321
296
|
/** Evaluate taxonomy rules against facts in a structure. */
|
|
@@ -334,37 +309,30 @@ class LedgerClient {
|
|
|
334
309
|
}
|
|
335
310
|
/**
|
|
336
311
|
* Idempotently create (or refresh) a draft closing entry from a
|
|
337
|
-
* schedule for a period.
|
|
312
|
+
* schedule for a period.
|
|
313
|
+
*
|
|
314
|
+
* Routes through `create-event-block` with
|
|
315
|
+
* `event_type='schedule_entry_due'`. Returns the EventBlockEnvelope —
|
|
316
|
+
* the underlying handler is idempotent and dispatches to one of
|
|
317
|
+
* created / unchanged / regenerated / removed / skipped internally.
|
|
338
318
|
*/
|
|
339
319
|
async createClosingEntry(graphId, structureId, postingDate, periodStart, periodEnd, memo) {
|
|
340
320
|
const body = {
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
*/
|
|
354
|
-
async createManualClosingEntry(graphId, options) {
|
|
355
|
-
const body = {
|
|
356
|
-
posting_date: options.postingDate,
|
|
357
|
-
memo: options.memo,
|
|
358
|
-
entry_type: options.entryType,
|
|
359
|
-
line_items: options.lineItems.map((li) => ({
|
|
360
|
-
element_id: li.elementId,
|
|
361
|
-
debit_amount: li.debitAmount ?? 0,
|
|
362
|
-
credit_amount: li.creditAmount ?? 0,
|
|
363
|
-
description: li.description ?? null,
|
|
364
|
-
})),
|
|
321
|
+
event_type: 'schedule_entry_due',
|
|
322
|
+
event_category: 'recognition',
|
|
323
|
+
source: 'scheduled',
|
|
324
|
+
occurred_at: `${postingDate}T00:00:00Z`,
|
|
325
|
+
apply_handlers: true,
|
|
326
|
+
metadata: {
|
|
327
|
+
schedule_id: structureId,
|
|
328
|
+
posting_date: postingDate,
|
|
329
|
+
period_start: periodStart,
|
|
330
|
+
period_end: periodEnd,
|
|
331
|
+
memo: memo ?? null,
|
|
332
|
+
},
|
|
365
333
|
};
|
|
366
|
-
const envelope = await this.callOperation('Create
|
|
367
|
-
return
|
|
334
|
+
const envelope = await this.callOperation('Create closing entry', (0, sdk_gen_1.opCreateEventBlock)({ path: { graph_id: graphId }, body }));
|
|
335
|
+
return (envelope.result ?? {});
|
|
368
336
|
}
|
|
369
337
|
// ── Closing book ───────────────────────────────────────────────────
|
|
370
338
|
/** Grouped closing book structures for the close-screen sidebar. */
|
|
@@ -429,28 +397,43 @@ class LedgerClient {
|
|
|
429
397
|
/**
|
|
430
398
|
* Create a journal entry with balanced line items (DR=CR enforced).
|
|
431
399
|
*
|
|
432
|
-
*
|
|
433
|
-
*
|
|
400
|
+
* Routes through `create-event-block` with
|
|
401
|
+
* `event_type='journal_entry_recorded'` — the Python handler forwards
|
|
402
|
+
* to the internal journal-entry command. Defaults to `status='draft'`;
|
|
403
|
+
* pass `status='posted'` for historical data imports.
|
|
434
404
|
*
|
|
435
405
|
* Supply `idempotencyKey` to make the call safe to retry — replays
|
|
436
406
|
* within 24 hours return the same envelope. Reusing the key with a
|
|
437
407
|
* different body returns HTTP 409.
|
|
408
|
+
*
|
|
409
|
+
* Returns the EventBlockEnvelope (event row fields); query the ledger
|
|
410
|
+
* separately if you need the resulting entry_id.
|
|
438
411
|
*/
|
|
439
412
|
async createJournalEntry(graphId, options) {
|
|
440
413
|
const body = {
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
414
|
+
event_type: 'journal_entry_recorded',
|
|
415
|
+
event_category: 'adjustment',
|
|
416
|
+
source: 'native',
|
|
417
|
+
occurred_at: `${options.postingDate}T00:00:00Z`,
|
|
418
|
+
apply_handlers: true,
|
|
419
|
+
metadata: {
|
|
420
|
+
posting_date: options.postingDate,
|
|
421
|
+
memo: options.memo,
|
|
422
|
+
line_items: options.lineItems.map((li) => ({
|
|
423
|
+
element_id: li.elementId,
|
|
424
|
+
debit_amount: li.debitAmount,
|
|
425
|
+
credit_amount: li.creditAmount,
|
|
426
|
+
description: li.description ?? null,
|
|
427
|
+
})),
|
|
428
|
+
type: options.type ?? 'standard',
|
|
429
|
+
status: options.status ?? 'draft',
|
|
430
|
+
transaction_id: options.transactionId ?? null,
|
|
431
|
+
},
|
|
452
432
|
};
|
|
453
|
-
const
|
|
433
|
+
const headers = options.idempotencyKey
|
|
434
|
+
? { 'Idempotency-Key': options.idempotencyKey }
|
|
435
|
+
: undefined;
|
|
436
|
+
const envelope = await this.callOperation('Create journal entry', (0, sdk_gen_1.opCreateEventBlock)({ path: { graph_id: graphId }, body, headers }));
|
|
454
437
|
return (envelope.result ?? {});
|
|
455
438
|
}
|
|
456
439
|
/** Update a draft journal entry. Posted entries are immutable. */
|
|
@@ -467,14 +450,109 @@ class LedgerClient {
|
|
|
467
450
|
/**
|
|
468
451
|
* Reverse a posted journal entry — creates an offsetting entry and marks
|
|
469
452
|
* the original as reversed.
|
|
453
|
+
*
|
|
454
|
+
* Routes through `create-event-block` with
|
|
455
|
+
* `event_type='journal_entry_reversed'`.
|
|
470
456
|
*/
|
|
471
457
|
async reverseJournalEntry(graphId, entryId, options) {
|
|
458
|
+
const occurredDate = options?.postingDate ?? new Date().toISOString().slice(0, 10);
|
|
472
459
|
const body = {
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
460
|
+
event_type: 'journal_entry_reversed',
|
|
461
|
+
event_category: 'adjustment',
|
|
462
|
+
source: 'native',
|
|
463
|
+
occurred_at: `${occurredDate}T00:00:00Z`,
|
|
464
|
+
apply_handlers: true,
|
|
465
|
+
metadata: {
|
|
466
|
+
entry_id: entryId,
|
|
467
|
+
posting_date: options?.postingDate ?? null,
|
|
468
|
+
memo: options?.memo ?? null,
|
|
469
|
+
reason: options?.reason ?? null,
|
|
470
|
+
},
|
|
476
471
|
};
|
|
477
|
-
const envelope = await this.callOperation('Reverse journal entry', (0, sdk_gen_1.
|
|
472
|
+
const envelope = await this.callOperation('Reverse journal entry', (0, sdk_gen_1.opCreateEventBlock)({ path: { graph_id: graphId }, body }));
|
|
473
|
+
return (envelope.result ?? {});
|
|
474
|
+
}
|
|
475
|
+
// ── Event blocks (generic preview + status transitions) ──────────────
|
|
476
|
+
/**
|
|
477
|
+
* Dry-run an event block — resolve the handler, evaluate metadata, and
|
|
478
|
+
* return the planned GL rows without writing anything. Companion to
|
|
479
|
+
* `createJournalEntry` / `reverseJournalEntry` / `createClosingEntry` /
|
|
480
|
+
* `disposeSchedule`: pass the same body you'd send to those methods
|
|
481
|
+
* (the underlying `CreateEventBlockRequest`) and inspect what the
|
|
482
|
+
* handler would do.
|
|
483
|
+
*/
|
|
484
|
+
async previewEventBlock(graphId, body) {
|
|
485
|
+
const envelope = await this.callOperation('Preview event block', (0, sdk_gen_1.opPreviewEventBlock)({ path: { graph_id: graphId }, body }));
|
|
486
|
+
return (envelope.result ?? {});
|
|
487
|
+
}
|
|
488
|
+
/**
|
|
489
|
+
* Apply a status transition and/or field corrections to an existing
|
|
490
|
+
* event block. Use for posting drafts (`classified` → `committed` →
|
|
491
|
+
* `fulfilled`), voiding, superseding (correction chains), or patching
|
|
492
|
+
* `description` / `effective_at` / `metadata`.
|
|
493
|
+
*/
|
|
494
|
+
async updateEventBlock(graphId, body) {
|
|
495
|
+
const envelope = await this.callOperation('Update event block', (0, sdk_gen_1.opUpdateEventBlock)({ path: { graph_id: graphId }, body }));
|
|
496
|
+
return (envelope.result ?? {});
|
|
497
|
+
}
|
|
498
|
+
// ── Agents (REA counterparties) ───────────────────────────────────────
|
|
499
|
+
/**
|
|
500
|
+
* Create an agent — REA counterparty (customer, vendor, employee, etc.)
|
|
501
|
+
* referenced by event blocks via `agent_id`. `(source, external_id)` is
|
|
502
|
+
* unique when `external_id` is provided, so external-source ingestion is
|
|
503
|
+
* idempotent at the DB level.
|
|
504
|
+
*/
|
|
505
|
+
async createAgent(graphId, body, idempotencyKey) {
|
|
506
|
+
const headers = idempotencyKey ? { 'Idempotency-Key': idempotencyKey } : undefined;
|
|
507
|
+
const envelope = await this.callOperation('Create agent', (0, sdk_gen_1.opCreateAgent)({ path: { graph_id: graphId }, body, headers }));
|
|
508
|
+
return (envelope.result ?? {});
|
|
509
|
+
}
|
|
510
|
+
/**
|
|
511
|
+
* Update an agent. `metadata_patch` is a partial merge into the existing
|
|
512
|
+
* metadata object; all other fields replace.
|
|
513
|
+
*/
|
|
514
|
+
async updateAgent(graphId, body) {
|
|
515
|
+
const envelope = await this.callOperation('Update agent', (0, sdk_gen_1.opUpdateAgent)({ path: { graph_id: graphId }, body }));
|
|
516
|
+
return (envelope.result ?? {});
|
|
517
|
+
}
|
|
518
|
+
// ── Event handlers (DSL handler registry) ────────────────────────────
|
|
519
|
+
/**
|
|
520
|
+
* Register a tenant-configurable event handler — DSL row in the
|
|
521
|
+
* `event_handlers` table that drives `create-event-block` for event
|
|
522
|
+
* types not covered by a Python handler. Match selectors plus a
|
|
523
|
+
* `transaction_template` describing the GL rows to produce.
|
|
524
|
+
*/
|
|
525
|
+
async createEventHandler(graphId, body) {
|
|
526
|
+
const envelope = await this.callOperation('Create event handler', (0, sdk_gen_1.opCreateEventHandler)({ path: { graph_id: graphId }, body }));
|
|
527
|
+
return (envelope.result ?? {});
|
|
528
|
+
}
|
|
529
|
+
/**
|
|
530
|
+
* Update a registered event handler. Pass `approve: true` to flip an
|
|
531
|
+
* AI-suggested handler from unapproved to active.
|
|
532
|
+
*/
|
|
533
|
+
async updateEventHandler(graphId, body) {
|
|
534
|
+
const envelope = await this.callOperation('Update event handler', (0, sdk_gen_1.opUpdateEventHandler)({ path: { graph_id: graphId }, body }));
|
|
535
|
+
return (envelope.result ?? {});
|
|
536
|
+
}
|
|
537
|
+
// ── Financial statements (graph-backed) ──────────────────────────────
|
|
538
|
+
/**
|
|
539
|
+
* Live financial statement — pulls facts directly from the graph for
|
|
540
|
+
* an explicit period window (or fiscal year) and returns the statement
|
|
541
|
+
* shape without a persisted Report row. Useful for ad-hoc previews and
|
|
542
|
+
* dashboards.
|
|
543
|
+
*/
|
|
544
|
+
async liveFinancialStatement(graphId, body) {
|
|
545
|
+
const envelope = await this.callOperation('Live financial statement', (0, sdk_gen_1.opLiveFinancialStatement)({ path: { graph_id: graphId }, body }));
|
|
546
|
+
return (envelope.result ?? {});
|
|
547
|
+
}
|
|
548
|
+
/**
|
|
549
|
+
* Run a financial statement analysis against an existing report.
|
|
550
|
+
* On shared-repo graphs (e.g. SEC), `ticker` is required; on tenant
|
|
551
|
+
* graphs it's ignored. Either pass an explicit `report_id` or let the
|
|
552
|
+
* server auto-resolve via `fiscal_year` + `period_type`.
|
|
553
|
+
*/
|
|
554
|
+
async financialStatementAnalysis(graphId, body) {
|
|
555
|
+
const envelope = await this.callOperation('Financial statement analysis', (0, sdk_gen_1.opFinancialStatementAnalysis)({ path: { graph_id: graphId }, body }));
|
|
478
556
|
return (envelope.result ?? {});
|
|
479
557
|
}
|
|
480
558
|
// ── Fact grid (graph-backed analytical query) ─────────────────────
|
|
@@ -680,19 +758,6 @@ class LedgerClient {
|
|
|
680
758
|
}
|
|
681
759
|
exports.LedgerClient = LedgerClient;
|
|
682
760
|
// ── Module-private conversion helpers ─────────────────────────────────
|
|
683
|
-
function rawToClosingEntry(data) {
|
|
684
|
-
return {
|
|
685
|
-
outcome: data.outcome,
|
|
686
|
-
entryId: data.entry_id ?? null,
|
|
687
|
-
status: data.status ?? null,
|
|
688
|
-
postingDate: data.posting_date ?? null,
|
|
689
|
-
memo: data.memo ?? null,
|
|
690
|
-
debitElementId: data.debit_element_id ?? null,
|
|
691
|
-
creditElementId: data.credit_element_id ?? null,
|
|
692
|
-
amount: data.amount ?? null,
|
|
693
|
-
reason: data.reason ?? null,
|
|
694
|
-
};
|
|
695
|
-
}
|
|
696
761
|
function rawFiscalCalendarToCamel(raw) {
|
|
697
762
|
return {
|
|
698
763
|
graphId: raw.graph_id,
|