@robosystems/client 0.2.48 → 0.3.0

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.
Files changed (190) hide show
  1. package/extensions/InvestorClient.d.ts +91 -0
  2. package/extensions/InvestorClient.js +223 -0
  3. package/extensions/InvestorClient.ts +501 -0
  4. package/extensions/LedgerClient.d.ts +213 -165
  5. package/extensions/LedgerClient.js +315 -393
  6. package/extensions/LedgerClient.ts +887 -564
  7. package/extensions/ReportClient.d.ts +77 -115
  8. package/extensions/ReportClient.js +124 -211
  9. package/extensions/ReportClient.ts +298 -358
  10. package/extensions/config.js +1 -1
  11. package/extensions/config.ts +1 -1
  12. package/extensions/graphql/client.d.ts +46 -0
  13. package/extensions/graphql/client.js +75 -0
  14. package/extensions/graphql/client.ts +82 -0
  15. package/extensions/graphql/generated/graphql.d.ts +1786 -0
  16. package/extensions/graphql/generated/graphql.js +2671 -0
  17. package/extensions/graphql/generated/graphql.ts +4491 -0
  18. package/extensions/graphql/queries/investor/holdings.d.ts +8 -0
  19. package/extensions/graphql/queries/investor/holdings.js +36 -0
  20. package/extensions/graphql/queries/investor/holdings.ts +34 -0
  21. package/extensions/graphql/queries/investor/portfolio.d.ts +4 -0
  22. package/extensions/graphql/queries/investor/portfolio.js +21 -0
  23. package/extensions/graphql/queries/investor/portfolio.ts +19 -0
  24. package/extensions/graphql/queries/investor/portfolios.d.ts +4 -0
  25. package/extensions/graphql/queries/investor/portfolios.js +29 -0
  26. package/extensions/graphql/queries/investor/portfolios.ts +27 -0
  27. package/extensions/graphql/queries/investor/position.d.ts +4 -0
  28. package/extensions/graphql/queries/investor/position.js +33 -0
  29. package/extensions/graphql/queries/investor/position.ts +31 -0
  30. package/extensions/graphql/queries/investor/positions.d.ts +8 -0
  31. package/extensions/graphql/queries/investor/positions.js +57 -0
  32. package/extensions/graphql/queries/investor/positions.ts +55 -0
  33. package/extensions/graphql/queries/investor/securities.d.ts +8 -0
  34. package/extensions/graphql/queries/investor/securities.js +50 -0
  35. package/extensions/graphql/queries/investor/securities.ts +48 -0
  36. package/extensions/graphql/queries/investor/security.d.ts +4 -0
  37. package/extensions/graphql/queries/investor/security.js +26 -0
  38. package/extensions/graphql/queries/investor/security.ts +24 -0
  39. package/extensions/graphql/queries/ledger/accountRollups.d.ts +7 -0
  40. package/extensions/graphql/queries/ledger/accountRollups.js +36 -0
  41. package/extensions/graphql/queries/ledger/accountRollups.ts +34 -0
  42. package/extensions/graphql/queries/ledger/accountTree.d.ts +11 -0
  43. package/extensions/graphql/queries/ledger/accountTree.js +61 -0
  44. package/extensions/graphql/queries/ledger/accountTree.ts +59 -0
  45. package/extensions/graphql/queries/ledger/accounts.d.ts +8 -0
  46. package/extensions/graphql/queries/ledger/accounts.js +45 -0
  47. package/extensions/graphql/queries/ledger/accounts.ts +43 -0
  48. package/extensions/graphql/queries/ledger/closingBookStructures.d.ts +6 -0
  49. package/extensions/graphql/queries/ledger/closingBookStructures.js +27 -0
  50. package/extensions/graphql/queries/ledger/closingBookStructures.ts +25 -0
  51. package/extensions/graphql/queries/ledger/elements.d.ts +6 -0
  52. package/extensions/graphql/queries/ledger/elements.js +56 -0
  53. package/extensions/graphql/queries/ledger/elements.ts +54 -0
  54. package/extensions/graphql/queries/ledger/entities.d.ts +7 -0
  55. package/extensions/graphql/queries/ledger/entities.js +31 -0
  56. package/extensions/graphql/queries/ledger/entities.ts +29 -0
  57. package/extensions/graphql/queries/ledger/entity.d.ts +14 -0
  58. package/extensions/graphql/queries/ledger/entity.js +55 -0
  59. package/extensions/graphql/queries/ledger/entity.ts +54 -0
  60. package/extensions/graphql/queries/ledger/fiscalCalendar.d.ts +8 -0
  61. package/extensions/graphql/queries/ledger/fiscalCalendar.js +35 -0
  62. package/extensions/graphql/queries/ledger/fiscalCalendar.ts +33 -0
  63. package/extensions/graphql/queries/ledger/mappedTrialBalance.d.ts +9 -0
  64. package/extensions/graphql/queries/ledger/mappedTrialBalance.js +29 -0
  65. package/extensions/graphql/queries/ledger/mappedTrialBalance.ts +27 -0
  66. package/extensions/graphql/queries/ledger/mapping.d.ts +5 -0
  67. package/extensions/graphql/queries/ledger/mapping.js +35 -0
  68. package/extensions/graphql/queries/ledger/mapping.ts +33 -0
  69. package/extensions/graphql/queries/ledger/mappingCoverage.d.ts +5 -0
  70. package/extensions/graphql/queries/ledger/mappingCoverage.js +22 -0
  71. package/extensions/graphql/queries/ledger/mappingCoverage.ts +20 -0
  72. package/extensions/graphql/queries/ledger/mappings.d.ts +6 -0
  73. package/extensions/graphql/queries/ledger/mappings.js +23 -0
  74. package/extensions/graphql/queries/ledger/mappings.ts +21 -0
  75. package/extensions/graphql/queries/ledger/periodCloseStatus.d.ts +6 -0
  76. package/extensions/graphql/queries/ledger/periodCloseStatus.js +29 -0
  77. package/extensions/graphql/queries/ledger/periodCloseStatus.ts +27 -0
  78. package/extensions/graphql/queries/ledger/periodDrafts.d.ts +8 -0
  79. package/extensions/graphql/queries/ledger/periodDrafts.js +45 -0
  80. package/extensions/graphql/queries/ledger/periodDrafts.ts +43 -0
  81. package/extensions/graphql/queries/ledger/publishList.d.ts +5 -0
  82. package/extensions/graphql/queries/ledger/publishList.js +29 -0
  83. package/extensions/graphql/queries/ledger/publishList.ts +27 -0
  84. package/extensions/graphql/queries/ledger/publishLists.d.ts +5 -0
  85. package/extensions/graphql/queries/ledger/publishLists.js +29 -0
  86. package/extensions/graphql/queries/ledger/publishLists.ts +27 -0
  87. package/extensions/graphql/queries/ledger/report.d.ts +5 -0
  88. package/extensions/graphql/queries/ledger/report.js +40 -0
  89. package/extensions/graphql/queries/ledger/report.ts +38 -0
  90. package/extensions/graphql/queries/ledger/reportingTaxonomy.d.ts +6 -0
  91. package/extensions/graphql/queries/ledger/reportingTaxonomy.js +27 -0
  92. package/extensions/graphql/queries/ledger/reportingTaxonomy.ts +25 -0
  93. package/extensions/graphql/queries/ledger/reports.d.ts +8 -0
  94. package/extensions/graphql/queries/ledger/reports.js +45 -0
  95. package/extensions/graphql/queries/ledger/reports.ts +43 -0
  96. package/extensions/graphql/queries/ledger/scheduleFacts.d.ts +7 -0
  97. package/extensions/graphql/queries/ledger/scheduleFacts.js +24 -0
  98. package/extensions/graphql/queries/ledger/scheduleFacts.ts +22 -0
  99. package/extensions/graphql/queries/ledger/schedules.d.ts +6 -0
  100. package/extensions/graphql/queries/ledger/schedules.js +24 -0
  101. package/extensions/graphql/queries/ledger/schedules.ts +22 -0
  102. package/extensions/graphql/queries/ledger/statement.d.ts +9 -0
  103. package/extensions/graphql/queries/ledger/statement.js +43 -0
  104. package/extensions/graphql/queries/ledger/statement.ts +41 -0
  105. package/extensions/graphql/queries/ledger/structures.d.ts +5 -0
  106. package/extensions/graphql/queries/ledger/structures.js +22 -0
  107. package/extensions/graphql/queries/ledger/structures.ts +20 -0
  108. package/extensions/graphql/queries/ledger/summary.d.ts +7 -0
  109. package/extensions/graphql/queries/ledger/summary.js +25 -0
  110. package/extensions/graphql/queries/ledger/summary.ts +23 -0
  111. package/extensions/graphql/queries/ledger/taxonomies.d.ts +5 -0
  112. package/extensions/graphql/queries/ledger/taxonomies.js +28 -0
  113. package/extensions/graphql/queries/ledger/taxonomies.ts +26 -0
  114. package/extensions/graphql/queries/ledger/transaction.d.ts +6 -0
  115. package/extensions/graphql/queries/ledger/transaction.js +49 -0
  116. package/extensions/graphql/queries/ledger/transaction.ts +47 -0
  117. package/extensions/graphql/queries/ledger/transactions.d.ts +7 -0
  118. package/extensions/graphql/queries/ledger/transactions.js +49 -0
  119. package/extensions/graphql/queries/ledger/transactions.ts +47 -0
  120. package/extensions/graphql/queries/ledger/trialBalance.d.ts +7 -0
  121. package/extensions/graphql/queries/ledger/trialBalance.js +28 -0
  122. package/extensions/graphql/queries/ledger/trialBalance.ts +26 -0
  123. package/extensions/graphql/queries/ledger/unmappedElements.d.ts +8 -0
  124. package/extensions/graphql/queries/ledger/unmappedElements.js +29 -0
  125. package/extensions/graphql/queries/ledger/unmappedElements.ts +27 -0
  126. package/extensions/hooks.d.ts +1 -1
  127. package/extensions/index.d.ts +5 -1
  128. package/extensions/index.js +13 -1
  129. package/extensions/index.ts +14 -0
  130. package/index.ts +2 -2
  131. package/package.json +14 -5
  132. package/sdk/index.d.ts +2 -2
  133. package/sdk/index.js +38 -65
  134. package/sdk/index.ts +2 -2
  135. package/sdk/sdk.gen.d.ts +101 -220
  136. package/sdk/sdk.gen.js +251 -445
  137. package/sdk/sdk.gen.ts +216 -409
  138. package/sdk/types.gen.d.ts +4586 -7045
  139. package/sdk/types.gen.ts +4702 -7334
  140. package/sdk.gen.d.ts +101 -220
  141. package/sdk.gen.js +251 -445
  142. package/sdk.gen.ts +216 -409
  143. package/types.gen.d.ts +4586 -7045
  144. package/types.gen.ts +4702 -7334
  145. package/extensions/AgentClient.test.ts +0 -403
  146. package/extensions/LedgerClient.test.ts +0 -1138
  147. package/extensions/OperationClient.test.ts +0 -365
  148. package/extensions/QueryClient.test.ts +0 -432
  149. package/extensions/ReportClient.test.ts +0 -828
  150. package/extensions/SSEClient.test.ts +0 -375
  151. package/extensions/config.test.ts +0 -199
  152. package/extensions/hooks.test.ts +0 -373
  153. package/extensions/index.test.ts +0 -420
  154. package/sdk-extensions/AgentClient.d.ts +0 -82
  155. package/sdk-extensions/AgentClient.js +0 -218
  156. package/sdk-extensions/AgentClient.test.ts +0 -403
  157. package/sdk-extensions/AgentClient.ts +0 -321
  158. package/sdk-extensions/LedgerClient.d.ts +0 -242
  159. package/sdk-extensions/LedgerClient.js +0 -496
  160. package/sdk-extensions/LedgerClient.test.ts +0 -1138
  161. package/sdk-extensions/LedgerClient.ts +0 -800
  162. package/sdk-extensions/OperationClient.d.ts +0 -65
  163. package/sdk-extensions/OperationClient.js +0 -251
  164. package/sdk-extensions/OperationClient.test.ts +0 -365
  165. package/sdk-extensions/OperationClient.ts +0 -324
  166. package/sdk-extensions/QueryClient.d.ts +0 -52
  167. package/sdk-extensions/QueryClient.js +0 -313
  168. package/sdk-extensions/QueryClient.test.ts +0 -432
  169. package/sdk-extensions/QueryClient.ts +0 -420
  170. package/sdk-extensions/README.md +0 -901
  171. package/sdk-extensions/ReportClient.d.ts +0 -151
  172. package/sdk-extensions/ReportClient.js +0 -278
  173. package/sdk-extensions/ReportClient.test.ts +0 -828
  174. package/sdk-extensions/ReportClient.ts +0 -486
  175. package/sdk-extensions/SSEClient.d.ts +0 -62
  176. package/sdk-extensions/SSEClient.js +0 -154
  177. package/sdk-extensions/SSEClient.test.ts +0 -375
  178. package/sdk-extensions/SSEClient.ts +0 -210
  179. package/sdk-extensions/config.d.ts +0 -57
  180. package/sdk-extensions/config.js +0 -152
  181. package/sdk-extensions/config.test.ts +0 -199
  182. package/sdk-extensions/config.ts +0 -175
  183. package/sdk-extensions/hooks.d.ts +0 -110
  184. package/sdk-extensions/hooks.js +0 -384
  185. package/sdk-extensions/hooks.test.ts +0 -373
  186. package/sdk-extensions/hooks.ts +0 -459
  187. package/sdk-extensions/index.d.ts +0 -63
  188. package/sdk-extensions/index.js +0 -164
  189. package/sdk-extensions/index.test.ts +0 -420
  190. package/sdk-extensions/index.ts +0 -203
@@ -1,800 +0,0 @@
1
- 'use client'
2
-
3
- /**
4
- * Ledger Client for RoboSystems API
5
- *
6
- * High-level client for all ledger concerns: chart of accounts, transactions,
7
- * trial balance, taxonomy, mappings, and AI auto-mapping. This is the
8
- * operational backbone — reports consume these as inputs.
9
- */
10
-
11
- import {
12
- autoMapElements,
13
- createClosingEntry,
14
- createMappingAssociation,
15
- createSchedule,
16
- createStructure,
17
- deleteMappingAssociation,
18
- getAccountRollups,
19
- getClosingBookStructures,
20
- getLedgerAccountTree,
21
- getLedgerEntity,
22
- getLedgerSummary,
23
- getLedgerTransaction,
24
- getLedgerTrialBalance,
25
- getMappedTrialBalance,
26
- getMappingCoverage,
27
- getMappingDetail,
28
- getPeriodCloseStatus,
29
- getReportingTaxonomy,
30
- getScheduleFacts,
31
- listElements,
32
- listLedgerAccounts,
33
- listLedgerTransactions,
34
- listMappings,
35
- listSchedules,
36
- listStructures,
37
- } from '../sdk/sdk.gen'
38
- import type {
39
- AccountListResponse,
40
- AccountRollupsResponse,
41
- AccountTreeResponse,
42
- ClosingBookStructuresResponse,
43
- ClosingEntryResponse,
44
- CreateClosingEntryRequest,
45
- CreateScheduleRequest,
46
- LedgerSummaryResponse,
47
- LedgerTransactionDetailResponse,
48
- LedgerTransactionListResponse,
49
- MappingCoverageResponse,
50
- MappingDetailResponse,
51
- PeriodCloseItemResponse,
52
- PeriodCloseStatusResponse,
53
- ScheduleCreatedResponse,
54
- ScheduleFactResponse,
55
- ScheduleFactsResponse,
56
- ScheduleListResponse,
57
- ScheduleSummaryResponse,
58
- TrialBalanceResponse,
59
- } from '../sdk/types.gen'
60
-
61
- // ── Friendly types ──────────────────────────────────────────────────────
62
-
63
- export interface LedgerEntity {
64
- id: string
65
- name: string
66
- legalName: string | null
67
- entityType: string | null
68
- industry: string | null
69
- status: string | null
70
- }
71
-
72
- export interface MappingInfo {
73
- id: string
74
- name: string
75
- description: string | null
76
- structureType: string
77
- taxonomyId: string
78
- isActive: boolean
79
- }
80
-
81
- export interface MappingCoverage {
82
- totalCoaElements: number
83
- mappedCount: number
84
- unmappedCount: number
85
- coveragePercent: number
86
- highConfidence: number
87
- mediumConfidence: number
88
- lowConfidence: number
89
- }
90
-
91
- export interface Structure {
92
- id: string
93
- name: string
94
- structureType: string
95
- }
96
-
97
- export interface Schedule {
98
- structureId: string
99
- name: string
100
- taxonomyName: string
101
- entryTemplate: Record<string, unknown> | null
102
- scheduleMetadata: Record<string, unknown> | null
103
- totalPeriods: number
104
- periodsWithEntries: number
105
- }
106
-
107
- export interface ScheduleCreated {
108
- structureId: string
109
- name: string
110
- taxonomyId: string
111
- totalPeriods: number
112
- totalFacts: number
113
- }
114
-
115
- export interface ScheduleFact {
116
- elementId: string
117
- elementName: string
118
- value: number
119
- periodStart: string
120
- periodEnd: string
121
- }
122
-
123
- export interface PeriodCloseItem {
124
- structureId: string
125
- structureName: string
126
- amount: number
127
- status: string
128
- entryId: string | null
129
- }
130
-
131
- export interface PeriodCloseStatus {
132
- fiscalPeriodStart: string
133
- fiscalPeriodEnd: string
134
- periodStatus: string
135
- schedules: PeriodCloseItem[]
136
- totalDraft: number
137
- totalPosted: number
138
- }
139
-
140
- export interface ClosingEntry {
141
- entryId: string
142
- status: string
143
- postingDate: string
144
- memo: string
145
- debitElementId: string
146
- creditElementId: string
147
- amount: number
148
- }
149
-
150
- export interface CreateScheduleOptions {
151
- name: string
152
- elementIds: string[]
153
- periodStart: string
154
- periodEnd: string
155
- monthlyAmount: number
156
- entryTemplate: {
157
- debitElementId: string
158
- creditElementId: string
159
- entryType?: string
160
- memoTemplate?: string
161
- }
162
- taxonomyId?: string
163
- scheduleMetadata?: {
164
- method?: string
165
- originalAmount?: number
166
- residualValue?: number
167
- usefulLifeMonths?: number
168
- assetElementId?: string
169
- }
170
- }
171
-
172
- // ── Client ──────────────────────────────────────────────────────────────
173
-
174
- export class LedgerClient {
175
- private config: {
176
- baseUrl: string
177
- credentials?: 'include' | 'same-origin' | 'omit'
178
- headers?: Record<string, string>
179
- token?: string
180
- }
181
-
182
- constructor(config: {
183
- baseUrl: string
184
- credentials?: 'include' | 'same-origin' | 'omit'
185
- headers?: Record<string, string>
186
- token?: string
187
- }) {
188
- this.config = config
189
- }
190
-
191
- // ── Entity ──────────────────────────────────────────────────────────
192
-
193
- /**
194
- * Get the entity (company/organization) for this graph.
195
- */
196
- async getEntity(graphId: string): Promise<LedgerEntity | null> {
197
- const response = await getLedgerEntity({
198
- path: { graph_id: graphId },
199
- })
200
-
201
- if (response.response.status === 404) return null
202
- if (response.error) {
203
- throw new Error(`Get entity failed: ${JSON.stringify(response.error)}`)
204
- }
205
-
206
- const data = response.data as Record<string, unknown>
207
- return {
208
- id: data.id as string,
209
- name: data.name as string,
210
- legalName: (data.legal_name as string) ?? null,
211
- entityType: (data.entity_type as string) ?? null,
212
- industry: (data.industry as string) ?? null,
213
- status: (data.status as string) ?? null,
214
- }
215
- }
216
-
217
- // ── Accounts (Chart of Accounts) ───────────────────────────────────
218
-
219
- /**
220
- * List accounts (flat).
221
- */
222
- async listAccounts(graphId: string): Promise<AccountListResponse> {
223
- const response = await listLedgerAccounts({
224
- path: { graph_id: graphId },
225
- })
226
-
227
- if (response.error) {
228
- throw new Error(`List accounts failed: ${JSON.stringify(response.error)}`)
229
- }
230
-
231
- return response.data as AccountListResponse
232
- }
233
-
234
- /**
235
- * Get the account tree (hierarchical).
236
- */
237
- async getAccountTree(graphId: string): Promise<AccountTreeResponse> {
238
- const response = await getLedgerAccountTree({
239
- path: { graph_id: graphId },
240
- })
241
-
242
- if (response.error) {
243
- throw new Error(`Get account tree failed: ${JSON.stringify(response.error)}`)
244
- }
245
-
246
- return response.data as AccountTreeResponse
247
- }
248
-
249
- // ── Transactions ────────────────────────────────────────────────────
250
-
251
- /**
252
- * List transactions with optional date filters.
253
- */
254
- async listTransactions(
255
- graphId: string,
256
- options?: { startDate?: string; endDate?: string; limit?: number; offset?: number }
257
- ): Promise<LedgerTransactionListResponse> {
258
- const response = await listLedgerTransactions({
259
- path: { graph_id: graphId },
260
- query: {
261
- start_date: options?.startDate,
262
- end_date: options?.endDate,
263
- limit: options?.limit,
264
- offset: options?.offset,
265
- },
266
- })
267
-
268
- if (response.error) {
269
- throw new Error(`List transactions failed: ${JSON.stringify(response.error)}`)
270
- }
271
-
272
- return response.data as LedgerTransactionListResponse
273
- }
274
-
275
- /**
276
- * Get transaction detail with entries and line items.
277
- */
278
- async getTransaction(
279
- graphId: string,
280
- transactionId: string
281
- ): Promise<LedgerTransactionDetailResponse> {
282
- const response = await getLedgerTransaction({
283
- path: { graph_id: graphId, transaction_id: transactionId },
284
- })
285
-
286
- if (response.error) {
287
- throw new Error(`Get transaction failed: ${JSON.stringify(response.error)}`)
288
- }
289
-
290
- return response.data as LedgerTransactionDetailResponse
291
- }
292
-
293
- // ── Trial Balance ──────────────────────────────────────────────────
294
-
295
- /**
296
- * Get trial balance (CoA-level debits/credits).
297
- */
298
- async getTrialBalance(
299
- graphId: string,
300
- options?: { startDate?: string; endDate?: string }
301
- ): Promise<TrialBalanceResponse> {
302
- const response = await getLedgerTrialBalance({
303
- path: { graph_id: graphId },
304
- query: {
305
- start_date: options?.startDate,
306
- end_date: options?.endDate,
307
- },
308
- })
309
-
310
- if (response.error) {
311
- throw new Error(`Get trial balance failed: ${JSON.stringify(response.error)}`)
312
- }
313
-
314
- return response.data as TrialBalanceResponse
315
- }
316
-
317
- /**
318
- * Get mapped trial balance (CoA rolled up to GAAP concepts).
319
- */
320
- async getMappedTrialBalance(
321
- graphId: string,
322
- options?: { mappingId?: string; startDate?: string; endDate?: string }
323
- ): Promise<unknown> {
324
- const response = await getMappedTrialBalance({
325
- path: { graph_id: graphId },
326
- query: {
327
- mapping_id: options?.mappingId,
328
- start_date: options?.startDate,
329
- end_date: options?.endDate,
330
- },
331
- })
332
-
333
- if (response.error) {
334
- throw new Error(`Get mapped trial balance failed: ${JSON.stringify(response.error)}`)
335
- }
336
-
337
- return response.data
338
- }
339
-
340
- // ── Summary ────────────────────────────────────────────────────────
341
-
342
- /**
343
- * Get ledger summary (account count, transaction count, date range).
344
- */
345
- async getSummary(graphId: string): Promise<LedgerSummaryResponse> {
346
- const response = await getLedgerSummary({
347
- path: { graph_id: graphId },
348
- })
349
-
350
- if (response.error) {
351
- throw new Error(`Get summary failed: ${JSON.stringify(response.error)}`)
352
- }
353
-
354
- return response.data as LedgerSummaryResponse
355
- }
356
-
357
- // ── Taxonomy ────────────────────────────────────────────────────────
358
-
359
- /**
360
- * Get the reporting taxonomy (US GAAP seed).
361
- */
362
- async getReportingTaxonomy(graphId: string): Promise<unknown> {
363
- const response = await getReportingTaxonomy({
364
- path: { graph_id: graphId },
365
- })
366
-
367
- if (response.error) {
368
- throw new Error(`Get reporting taxonomy failed: ${JSON.stringify(response.error)}`)
369
- }
370
-
371
- return response.data
372
- }
373
-
374
- /**
375
- * List reporting structures (IS, BS, CF) for a taxonomy.
376
- */
377
- async listStructures(graphId: string, taxonomyId?: string): Promise<Structure[]> {
378
- const response = await listStructures({
379
- path: { graph_id: graphId },
380
- query: taxonomyId ? { taxonomy_id: taxonomyId } : undefined,
381
- })
382
-
383
- if (response.error) {
384
- throw new Error(`List structures failed: ${JSON.stringify(response.error)}`)
385
- }
386
-
387
- const data = response.data as { structures?: Array<Record<string, unknown>> }
388
- return (data.structures ?? []).map((s) => ({
389
- id: s.id as string,
390
- name: s.name as string,
391
- structureType: s.structure_type as string,
392
- }))
393
- }
394
-
395
- /**
396
- * List elements (CoA accounts, GAAP concepts, etc.).
397
- */
398
- async listElements(
399
- graphId: string,
400
- options?: {
401
- taxonomyId?: string
402
- source?: string
403
- classification?: string
404
- isAbstract?: boolean
405
- limit?: number
406
- offset?: number
407
- }
408
- ): Promise<unknown> {
409
- const response = await listElements({
410
- path: { graph_id: graphId },
411
- query: {
412
- taxonomy_id: options?.taxonomyId,
413
- source: options?.source,
414
- classification: options?.classification,
415
- is_abstract: options?.isAbstract,
416
- limit: options?.limit,
417
- offset: options?.offset,
418
- },
419
- })
420
-
421
- if (response.error) {
422
- throw new Error(`List elements failed: ${JSON.stringify(response.error)}`)
423
- }
424
-
425
- return response.data
426
- }
427
-
428
- // ── Mappings ────────────────────────────────────────────────────────
429
-
430
- /**
431
- * Create a new CoA→GAAP mapping structure.
432
- * Returns the created mapping info.
433
- */
434
- async createMappingStructure(
435
- graphId: string,
436
- options?: { name?: string; description?: string; taxonomyId?: string }
437
- ): Promise<MappingInfo> {
438
- const response = await createStructure({
439
- path: { graph_id: graphId },
440
- body: {
441
- name: options?.name ?? 'CoA to Reporting',
442
- description: options?.description ?? 'Map Chart of Accounts to US GAAP reporting concepts',
443
- structure_type: 'coa_mapping',
444
- taxonomy_id: options?.taxonomyId ?? 'tax_usgaap_reporting',
445
- },
446
- })
447
-
448
- if (response.error) {
449
- throw new Error(`Create mapping structure failed: ${JSON.stringify(response.error)}`)
450
- }
451
-
452
- const data = response.data as Record<string, unknown>
453
- return {
454
- id: data.id as string,
455
- name: data.name as string,
456
- description: (data.description as string) ?? null,
457
- structureType: data.structure_type as string,
458
- taxonomyId: data.taxonomy_id as string,
459
- isActive: (data.is_active as boolean) ?? true,
460
- }
461
- }
462
-
463
- /**
464
- * List available CoA→GAAP mapping structures.
465
- */
466
- async listMappings(graphId: string): Promise<MappingInfo[]> {
467
- const response = await listMappings({
468
- path: { graph_id: graphId },
469
- })
470
-
471
- if (response.error) {
472
- throw new Error(`List mappings failed: ${JSON.stringify(response.error)}`)
473
- }
474
-
475
- const data = response.data as { structures?: Array<Record<string, unknown>> }
476
- return (data.structures ?? []).map((s) => ({
477
- id: s.id as string,
478
- name: s.name as string,
479
- description: (s.description as string) ?? null,
480
- structureType: s.structure_type as string,
481
- taxonomyId: s.taxonomy_id as string,
482
- isActive: (s.is_active as boolean) ?? true,
483
- }))
484
- }
485
-
486
- /**
487
- * Get mapping detail — all associations with element names.
488
- */
489
- async getMappingDetail(graphId: string, mappingId: string): Promise<MappingDetailResponse> {
490
- const response = await getMappingDetail({
491
- path: { graph_id: graphId, mapping_id: mappingId },
492
- })
493
-
494
- if (response.error) {
495
- throw new Error(`Get mapping detail failed: ${JSON.stringify(response.error)}`)
496
- }
497
-
498
- return response.data as MappingDetailResponse
499
- }
500
-
501
- /**
502
- * Get mapping coverage — how many CoA elements are mapped.
503
- */
504
- async getMappingCoverage(graphId: string, mappingId: string): Promise<MappingCoverage> {
505
- const response = await getMappingCoverage({
506
- path: { graph_id: graphId, mapping_id: mappingId },
507
- })
508
-
509
- if (response.error) {
510
- throw new Error(`Get mapping coverage failed: ${JSON.stringify(response.error)}`)
511
- }
512
-
513
- const data = response.data as MappingCoverageResponse
514
- return {
515
- totalCoaElements: data.total_coa_elements ?? 0,
516
- mappedCount: data.mapped_count ?? 0,
517
- unmappedCount: data.unmapped_count ?? 0,
518
- coveragePercent: data.coverage_percent ?? 0,
519
- highConfidence: data.high_confidence ?? 0,
520
- mediumConfidence: data.medium_confidence ?? 0,
521
- lowConfidence: data.low_confidence ?? 0,
522
- }
523
- }
524
-
525
- /**
526
- * Create a manual mapping association (CoA element → GAAP element).
527
- */
528
- async createMapping(
529
- graphId: string,
530
- mappingId: string,
531
- fromElementId: string,
532
- toElementId: string,
533
- confidence?: number
534
- ): Promise<void> {
535
- const response = await createMappingAssociation({
536
- path: { graph_id: graphId, mapping_id: mappingId },
537
- body: {
538
- from_element_id: fromElementId,
539
- to_element_id: toElementId,
540
- confidence: confidence ?? 1.0,
541
- },
542
- })
543
-
544
- if (response.error) {
545
- throw new Error(`Create mapping failed: ${JSON.stringify(response.error)}`)
546
- }
547
- }
548
-
549
- /**
550
- * Delete a mapping association.
551
- */
552
- async deleteMapping(graphId: string, mappingId: string, associationId: string): Promise<void> {
553
- const response = await deleteMappingAssociation({
554
- path: { graph_id: graphId, mapping_id: mappingId, association_id: associationId },
555
- })
556
-
557
- if (response.error) {
558
- throw new Error(`Delete mapping failed: ${JSON.stringify(response.error)}`)
559
- }
560
- }
561
-
562
- /**
563
- * Trigger AI auto-mapping (MappingAgent).
564
- * Returns immediately — the agent runs in the background.
565
- */
566
- async autoMap(graphId: string, mappingId: string): Promise<{ operationId?: string }> {
567
- const response = await autoMapElements({
568
- path: { graph_id: graphId, mapping_id: mappingId },
569
- })
570
-
571
- if (response.error) {
572
- throw new Error(`Auto-map failed: ${JSON.stringify(response.error)}`)
573
- }
574
-
575
- const data = response.data as Record<string, unknown> | undefined
576
- return {
577
- operationId: data?.operation_id as string | undefined,
578
- }
579
- }
580
-
581
- // ── Schedules ──────────────────────────────────────────────────────
582
-
583
- /**
584
- * Create a schedule with pre-generated monthly facts.
585
- */
586
- async createSchedule(graphId: string, options: CreateScheduleOptions): Promise<ScheduleCreated> {
587
- const body: CreateScheduleRequest = {
588
- name: options.name,
589
- element_ids: options.elementIds,
590
- period_start: options.periodStart,
591
- period_end: options.periodEnd,
592
- monthly_amount: options.monthlyAmount,
593
- entry_template: {
594
- debit_element_id: options.entryTemplate.debitElementId,
595
- credit_element_id: options.entryTemplate.creditElementId,
596
- entry_type: options.entryTemplate.entryType,
597
- memo_template: options.entryTemplate.memoTemplate,
598
- },
599
- taxonomy_id: options.taxonomyId,
600
- schedule_metadata: options.scheduleMetadata
601
- ? {
602
- method: options.scheduleMetadata.method,
603
- original_amount: options.scheduleMetadata.originalAmount,
604
- residual_value: options.scheduleMetadata.residualValue,
605
- useful_life_months: options.scheduleMetadata.usefulLifeMonths,
606
- asset_element_id: options.scheduleMetadata.assetElementId,
607
- }
608
- : undefined,
609
- }
610
-
611
- const response = await createSchedule({
612
- path: { graph_id: graphId },
613
- body,
614
- })
615
-
616
- if (response.error) {
617
- throw new Error(`Create schedule failed: ${JSON.stringify(response.error)}`)
618
- }
619
-
620
- const data = response.data as ScheduleCreatedResponse
621
- return {
622
- structureId: data.structure_id,
623
- name: data.name,
624
- taxonomyId: data.taxonomy_id,
625
- totalPeriods: data.total_periods,
626
- totalFacts: data.total_facts,
627
- }
628
- }
629
-
630
- /**
631
- * List all schedules for a graph.
632
- */
633
- async listSchedules(graphId: string): Promise<Schedule[]> {
634
- const response = await listSchedules({
635
- path: { graph_id: graphId },
636
- })
637
-
638
- if (response.error) {
639
- throw new Error(`List schedules failed: ${JSON.stringify(response.error)}`)
640
- }
641
-
642
- const data = response.data as ScheduleListResponse
643
- return (data.schedules ?? []).map((s: ScheduleSummaryResponse) => ({
644
- structureId: s.structure_id,
645
- name: s.name,
646
- taxonomyName: s.taxonomy_name,
647
- entryTemplate: s.entry_template ?? null,
648
- scheduleMetadata: s.schedule_metadata ?? null,
649
- totalPeriods: s.total_periods,
650
- periodsWithEntries: s.periods_with_entries,
651
- }))
652
- }
653
-
654
- /**
655
- * Get facts for a schedule, optionally filtered by period.
656
- */
657
- async getScheduleFacts(
658
- graphId: string,
659
- structureId: string,
660
- periodStart?: string,
661
- periodEnd?: string
662
- ): Promise<ScheduleFact[]> {
663
- const response = await getScheduleFacts({
664
- path: { graph_id: graphId, structure_id: structureId },
665
- query: {
666
- period_start: periodStart ?? null,
667
- period_end: periodEnd ?? null,
668
- },
669
- })
670
-
671
- if (response.error) {
672
- throw new Error(`Get schedule facts failed: ${JSON.stringify(response.error)}`)
673
- }
674
-
675
- const data = response.data as ScheduleFactsResponse
676
- return (data.facts ?? []).map((f: ScheduleFactResponse) => ({
677
- elementId: f.element_id,
678
- elementName: f.element_name,
679
- value: f.value,
680
- periodStart: f.period_start,
681
- periodEnd: f.period_end,
682
- }))
683
- }
684
-
685
- /**
686
- * Get close status for all schedules in a fiscal period.
687
- */
688
- async getPeriodCloseStatus(
689
- graphId: string,
690
- periodStart: string,
691
- periodEnd: string
692
- ): Promise<PeriodCloseStatus> {
693
- const response = await getPeriodCloseStatus({
694
- path: { graph_id: graphId },
695
- query: { period_start: periodStart, period_end: periodEnd },
696
- })
697
-
698
- if (response.error) {
699
- throw new Error(`Get period close status failed: ${JSON.stringify(response.error)}`)
700
- }
701
-
702
- const data = response.data as PeriodCloseStatusResponse
703
- return {
704
- fiscalPeriodStart: data.fiscal_period_start,
705
- fiscalPeriodEnd: data.fiscal_period_end,
706
- periodStatus: data.period_status,
707
- schedules: (data.schedules ?? []).map((s: PeriodCloseItemResponse) => ({
708
- structureId: s.structure_id,
709
- structureName: s.structure_name,
710
- amount: s.amount,
711
- status: s.status,
712
- entryId: s.entry_id ?? null,
713
- })),
714
- totalDraft: data.total_draft,
715
- totalPosted: data.total_posted,
716
- }
717
- }
718
-
719
- /**
720
- * Create a draft closing entry from a schedule's facts for a period.
721
- */
722
- async createClosingEntry(
723
- graphId: string,
724
- structureId: string,
725
- postingDate: string,
726
- periodStart: string,
727
- periodEnd: string,
728
- memo?: string
729
- ): Promise<ClosingEntry> {
730
- const body: CreateClosingEntryRequest = {
731
- posting_date: postingDate,
732
- period_start: periodStart,
733
- period_end: periodEnd,
734
- memo: memo ?? undefined,
735
- }
736
-
737
- const response = await createClosingEntry({
738
- path: { graph_id: graphId, structure_id: structureId },
739
- body,
740
- })
741
-
742
- if (response.error) {
743
- throw new Error(`Create closing entry failed: ${JSON.stringify(response.error)}`)
744
- }
745
-
746
- const data = response.data as ClosingEntryResponse
747
- return {
748
- entryId: data.entry_id,
749
- status: data.status,
750
- postingDate: data.posting_date,
751
- memo: data.memo,
752
- debitElementId: data.debit_element_id,
753
- creditElementId: data.credit_element_id,
754
- amount: data.amount,
755
- }
756
- }
757
-
758
- // ── Closing Book ─────────────────────────────────────────────────────
759
-
760
- /**
761
- * Get all closing book structure categories for the sidebar.
762
- * Returns statements, account rollups, schedules, trial balance,
763
- * and period close grouped into categories.
764
- */
765
- async getClosingBookStructures(graphId: string): Promise<ClosingBookStructuresResponse> {
766
- const response = await getClosingBookStructures({
767
- path: { graph_id: graphId },
768
- })
769
-
770
- if (response.error) {
771
- throw new Error(`Get closing book structures failed: ${JSON.stringify(response.error)}`)
772
- }
773
-
774
- return response.data as ClosingBookStructuresResponse
775
- }
776
-
777
- /**
778
- * Get account rollups — CoA accounts grouped by reporting element with balances.
779
- * Shows how company-specific accounts roll up to standardized reporting lines.
780
- */
781
- async getAccountRollups(
782
- graphId: string,
783
- options?: { mappingId?: string; startDate?: string; endDate?: string }
784
- ): Promise<AccountRollupsResponse> {
785
- const response = await getAccountRollups({
786
- path: { graph_id: graphId },
787
- query: {
788
- mapping_id: options?.mappingId,
789
- start_date: options?.startDate,
790
- end_date: options?.endDate,
791
- },
792
- })
793
-
794
- if (response.error) {
795
- throw new Error(`Get account rollups failed: ${JSON.stringify(response.error)}`)
796
- }
797
-
798
- return response.data as AccountRollupsResponse
799
- }
800
- }