@robosystems/client 0.2.49 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (191) hide show
  1. package/extensions/InvestorClient.d.ts +98 -0
  2. package/extensions/InvestorClient.js +223 -0
  3. package/extensions/InvestorClient.ts +508 -0
  4. package/extensions/LedgerClient.d.ts +190 -309
  5. package/extensions/LedgerClient.js +268 -587
  6. package/extensions/LedgerClient.ts +784 -903
  7. package/extensions/ReportClient.d.ts +82 -113
  8. package/extensions/ReportClient.js +124 -211
  9. package/extensions/ReportClient.ts +305 -358
  10. package/extensions/config.d.ts +19 -0
  11. package/extensions/config.js +1 -1
  12. package/extensions/config.ts +22 -2
  13. package/extensions/graphql/client.d.ts +82 -0
  14. package/extensions/graphql/client.js +149 -0
  15. package/extensions/graphql/client.ts +189 -0
  16. package/extensions/graphql/generated/graphql.d.ts +1786 -0
  17. package/extensions/graphql/generated/graphql.js +2671 -0
  18. package/extensions/graphql/generated/graphql.ts +4491 -0
  19. package/extensions/graphql/queries/investor/holdings.d.ts +8 -0
  20. package/extensions/graphql/queries/investor/holdings.js +36 -0
  21. package/extensions/graphql/queries/investor/holdings.ts +34 -0
  22. package/extensions/graphql/queries/investor/portfolio.d.ts +4 -0
  23. package/extensions/graphql/queries/investor/portfolio.js +21 -0
  24. package/extensions/graphql/queries/investor/portfolio.ts +19 -0
  25. package/extensions/graphql/queries/investor/portfolios.d.ts +4 -0
  26. package/extensions/graphql/queries/investor/portfolios.js +29 -0
  27. package/extensions/graphql/queries/investor/portfolios.ts +27 -0
  28. package/extensions/graphql/queries/investor/position.d.ts +4 -0
  29. package/extensions/graphql/queries/investor/position.js +33 -0
  30. package/extensions/graphql/queries/investor/position.ts +31 -0
  31. package/extensions/graphql/queries/investor/positions.d.ts +8 -0
  32. package/extensions/graphql/queries/investor/positions.js +57 -0
  33. package/extensions/graphql/queries/investor/positions.ts +55 -0
  34. package/extensions/graphql/queries/investor/securities.d.ts +8 -0
  35. package/extensions/graphql/queries/investor/securities.js +50 -0
  36. package/extensions/graphql/queries/investor/securities.ts +48 -0
  37. package/extensions/graphql/queries/investor/security.d.ts +4 -0
  38. package/extensions/graphql/queries/investor/security.js +26 -0
  39. package/extensions/graphql/queries/investor/security.ts +24 -0
  40. package/extensions/graphql/queries/ledger/accountRollups.d.ts +7 -0
  41. package/extensions/graphql/queries/ledger/accountRollups.js +36 -0
  42. package/extensions/graphql/queries/ledger/accountRollups.ts +34 -0
  43. package/extensions/graphql/queries/ledger/accountTree.d.ts +11 -0
  44. package/extensions/graphql/queries/ledger/accountTree.js +61 -0
  45. package/extensions/graphql/queries/ledger/accountTree.ts +59 -0
  46. package/extensions/graphql/queries/ledger/accounts.d.ts +8 -0
  47. package/extensions/graphql/queries/ledger/accounts.js +45 -0
  48. package/extensions/graphql/queries/ledger/accounts.ts +43 -0
  49. package/extensions/graphql/queries/ledger/closingBookStructures.d.ts +6 -0
  50. package/extensions/graphql/queries/ledger/closingBookStructures.js +27 -0
  51. package/extensions/graphql/queries/ledger/closingBookStructures.ts +25 -0
  52. package/extensions/graphql/queries/ledger/elements.d.ts +6 -0
  53. package/extensions/graphql/queries/ledger/elements.js +56 -0
  54. package/extensions/graphql/queries/ledger/elements.ts +54 -0
  55. package/extensions/graphql/queries/ledger/entities.d.ts +7 -0
  56. package/extensions/graphql/queries/ledger/entities.js +31 -0
  57. package/extensions/graphql/queries/ledger/entities.ts +29 -0
  58. package/extensions/graphql/queries/ledger/entity.d.ts +14 -0
  59. package/extensions/graphql/queries/ledger/entity.js +55 -0
  60. package/extensions/graphql/queries/ledger/entity.ts +54 -0
  61. package/extensions/graphql/queries/ledger/fiscalCalendar.d.ts +8 -0
  62. package/extensions/graphql/queries/ledger/fiscalCalendar.js +35 -0
  63. package/extensions/graphql/queries/ledger/fiscalCalendar.ts +33 -0
  64. package/extensions/graphql/queries/ledger/mappedTrialBalance.d.ts +9 -0
  65. package/extensions/graphql/queries/ledger/mappedTrialBalance.js +29 -0
  66. package/extensions/graphql/queries/ledger/mappedTrialBalance.ts +27 -0
  67. package/extensions/graphql/queries/ledger/mapping.d.ts +5 -0
  68. package/extensions/graphql/queries/ledger/mapping.js +35 -0
  69. package/extensions/graphql/queries/ledger/mapping.ts +33 -0
  70. package/extensions/graphql/queries/ledger/mappingCoverage.d.ts +5 -0
  71. package/extensions/graphql/queries/ledger/mappingCoverage.js +22 -0
  72. package/extensions/graphql/queries/ledger/mappingCoverage.ts +20 -0
  73. package/extensions/graphql/queries/ledger/mappings.d.ts +6 -0
  74. package/extensions/graphql/queries/ledger/mappings.js +23 -0
  75. package/extensions/graphql/queries/ledger/mappings.ts +21 -0
  76. package/extensions/graphql/queries/ledger/periodCloseStatus.d.ts +6 -0
  77. package/extensions/graphql/queries/ledger/periodCloseStatus.js +29 -0
  78. package/extensions/graphql/queries/ledger/periodCloseStatus.ts +27 -0
  79. package/extensions/graphql/queries/ledger/periodDrafts.d.ts +8 -0
  80. package/extensions/graphql/queries/ledger/periodDrafts.js +45 -0
  81. package/extensions/graphql/queries/ledger/periodDrafts.ts +43 -0
  82. package/extensions/graphql/queries/ledger/publishList.d.ts +5 -0
  83. package/extensions/graphql/queries/ledger/publishList.js +29 -0
  84. package/extensions/graphql/queries/ledger/publishList.ts +27 -0
  85. package/extensions/graphql/queries/ledger/publishLists.d.ts +5 -0
  86. package/extensions/graphql/queries/ledger/publishLists.js +29 -0
  87. package/extensions/graphql/queries/ledger/publishLists.ts +27 -0
  88. package/extensions/graphql/queries/ledger/report.d.ts +5 -0
  89. package/extensions/graphql/queries/ledger/report.js +40 -0
  90. package/extensions/graphql/queries/ledger/report.ts +38 -0
  91. package/extensions/graphql/queries/ledger/reportingTaxonomy.d.ts +6 -0
  92. package/extensions/graphql/queries/ledger/reportingTaxonomy.js +27 -0
  93. package/extensions/graphql/queries/ledger/reportingTaxonomy.ts +25 -0
  94. package/extensions/graphql/queries/ledger/reports.d.ts +8 -0
  95. package/extensions/graphql/queries/ledger/reports.js +45 -0
  96. package/extensions/graphql/queries/ledger/reports.ts +43 -0
  97. package/extensions/graphql/queries/ledger/scheduleFacts.d.ts +7 -0
  98. package/extensions/graphql/queries/ledger/scheduleFacts.js +24 -0
  99. package/extensions/graphql/queries/ledger/scheduleFacts.ts +22 -0
  100. package/extensions/graphql/queries/ledger/schedules.d.ts +6 -0
  101. package/extensions/graphql/queries/ledger/schedules.js +24 -0
  102. package/extensions/graphql/queries/ledger/schedules.ts +22 -0
  103. package/extensions/graphql/queries/ledger/statement.d.ts +9 -0
  104. package/extensions/graphql/queries/ledger/statement.js +43 -0
  105. package/extensions/graphql/queries/ledger/statement.ts +41 -0
  106. package/extensions/graphql/queries/ledger/structures.d.ts +5 -0
  107. package/extensions/graphql/queries/ledger/structures.js +22 -0
  108. package/extensions/graphql/queries/ledger/structures.ts +20 -0
  109. package/extensions/graphql/queries/ledger/summary.d.ts +7 -0
  110. package/extensions/graphql/queries/ledger/summary.js +25 -0
  111. package/extensions/graphql/queries/ledger/summary.ts +23 -0
  112. package/extensions/graphql/queries/ledger/taxonomies.d.ts +5 -0
  113. package/extensions/graphql/queries/ledger/taxonomies.js +28 -0
  114. package/extensions/graphql/queries/ledger/taxonomies.ts +26 -0
  115. package/extensions/graphql/queries/ledger/transaction.d.ts +6 -0
  116. package/extensions/graphql/queries/ledger/transaction.js +49 -0
  117. package/extensions/graphql/queries/ledger/transaction.ts +47 -0
  118. package/extensions/graphql/queries/ledger/transactions.d.ts +7 -0
  119. package/extensions/graphql/queries/ledger/transactions.js +49 -0
  120. package/extensions/graphql/queries/ledger/transactions.ts +47 -0
  121. package/extensions/graphql/queries/ledger/trialBalance.d.ts +7 -0
  122. package/extensions/graphql/queries/ledger/trialBalance.js +28 -0
  123. package/extensions/graphql/queries/ledger/trialBalance.ts +26 -0
  124. package/extensions/graphql/queries/ledger/unmappedElements.d.ts +8 -0
  125. package/extensions/graphql/queries/ledger/unmappedElements.js +29 -0
  126. package/extensions/graphql/queries/ledger/unmappedElements.ts +27 -0
  127. package/extensions/hooks.d.ts +1 -1
  128. package/extensions/index.d.ts +18 -1
  129. package/extensions/index.js +26 -1
  130. package/extensions/index.ts +49 -2
  131. package/index.ts +2 -2
  132. package/package.json +14 -5
  133. package/sdk/index.d.ts +2 -2
  134. package/sdk/index.js +38 -73
  135. package/sdk/index.ts +2 -2
  136. package/sdk/sdk.gen.d.ts +100 -325
  137. package/sdk/sdk.gen.js +228 -592
  138. package/sdk/sdk.gen.ts +193 -556
  139. package/sdk/types.gen.d.ts +4522 -7708
  140. package/sdk/types.gen.ts +4569 -7983
  141. package/sdk.gen.d.ts +100 -325
  142. package/sdk.gen.js +228 -592
  143. package/sdk.gen.ts +193 -556
  144. package/types.gen.d.ts +4522 -7708
  145. package/types.gen.ts +4569 -7983
  146. package/extensions/AgentClient.test.ts +0 -403
  147. package/extensions/LedgerClient.test.ts +0 -1655
  148. package/extensions/OperationClient.test.ts +0 -365
  149. package/extensions/QueryClient.test.ts +0 -432
  150. package/extensions/ReportClient.test.ts +0 -828
  151. package/extensions/SSEClient.test.ts +0 -375
  152. package/extensions/config.test.ts +0 -199
  153. package/extensions/hooks.test.ts +0 -373
  154. package/extensions/index.test.ts +0 -420
  155. package/sdk-extensions/AgentClient.d.ts +0 -82
  156. package/sdk-extensions/AgentClient.js +0 -218
  157. package/sdk-extensions/AgentClient.test.ts +0 -403
  158. package/sdk-extensions/AgentClient.ts +0 -321
  159. package/sdk-extensions/LedgerClient.d.ts +0 -416
  160. package/sdk-extensions/LedgerClient.js +0 -737
  161. package/sdk-extensions/LedgerClient.test.ts +0 -1655
  162. package/sdk-extensions/LedgerClient.ts +0 -1249
  163. package/sdk-extensions/OperationClient.d.ts +0 -65
  164. package/sdk-extensions/OperationClient.js +0 -251
  165. package/sdk-extensions/OperationClient.test.ts +0 -365
  166. package/sdk-extensions/OperationClient.ts +0 -324
  167. package/sdk-extensions/QueryClient.d.ts +0 -52
  168. package/sdk-extensions/QueryClient.js +0 -313
  169. package/sdk-extensions/QueryClient.test.ts +0 -432
  170. package/sdk-extensions/QueryClient.ts +0 -420
  171. package/sdk-extensions/README.md +0 -901
  172. package/sdk-extensions/ReportClient.d.ts +0 -151
  173. package/sdk-extensions/ReportClient.js +0 -278
  174. package/sdk-extensions/ReportClient.test.ts +0 -828
  175. package/sdk-extensions/ReportClient.ts +0 -486
  176. package/sdk-extensions/SSEClient.d.ts +0 -62
  177. package/sdk-extensions/SSEClient.js +0 -154
  178. package/sdk-extensions/SSEClient.test.ts +0 -375
  179. package/sdk-extensions/SSEClient.ts +0 -210
  180. package/sdk-extensions/config.d.ts +0 -57
  181. package/sdk-extensions/config.js +0 -152
  182. package/sdk-extensions/config.test.ts +0 -199
  183. package/sdk-extensions/config.ts +0 -175
  184. package/sdk-extensions/hooks.d.ts +0 -110
  185. package/sdk-extensions/hooks.js +0 -384
  186. package/sdk-extensions/hooks.test.ts +0 -373
  187. package/sdk-extensions/hooks.ts +0 -459
  188. package/sdk-extensions/index.d.ts +0 -63
  189. package/sdk-extensions/index.js +0 -164
  190. package/sdk-extensions/index.test.ts +0 -420
  191. package/sdk-extensions/index.ts +0 -203
@@ -1,737 +0,0 @@
1
- 'use client';
2
- "use strict";
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.LedgerClient = void 0;
5
- /**
6
- * Ledger Client for RoboSystems API
7
- *
8
- * High-level client for all ledger concerns: chart of accounts, transactions,
9
- * trial balance, taxonomy, mappings, and AI auto-mapping. This is the
10
- * operational backbone — reports consume these as inputs.
11
- */
12
- const sdk_gen_1 = require("../sdk/sdk.gen");
13
- // ── Client ──────────────────────────────────────────────────────────────
14
- class LedgerClient {
15
- constructor(config) {
16
- this.config = config;
17
- }
18
- // ── Entity ──────────────────────────────────────────────────────────
19
- /**
20
- * Get the entity (company/organization) for this graph.
21
- */
22
- async getEntity(graphId) {
23
- const response = await (0, sdk_gen_1.getLedgerEntity)({
24
- path: { graph_id: graphId },
25
- });
26
- if (response.response.status === 404)
27
- return null;
28
- if (response.error) {
29
- throw new Error(`Get entity failed: ${JSON.stringify(response.error)}`);
30
- }
31
- const data = response.data;
32
- return {
33
- id: data.id,
34
- name: data.name,
35
- legalName: data.legal_name ?? null,
36
- entityType: data.entity_type ?? null,
37
- industry: data.industry ?? null,
38
- status: data.status ?? null,
39
- };
40
- }
41
- // ── Accounts (Chart of Accounts) ───────────────────────────────────
42
- /**
43
- * List accounts (flat).
44
- */
45
- async listAccounts(graphId) {
46
- const response = await (0, sdk_gen_1.listLedgerAccounts)({
47
- path: { graph_id: graphId },
48
- });
49
- if (response.error) {
50
- throw new Error(`List accounts failed: ${JSON.stringify(response.error)}`);
51
- }
52
- return response.data;
53
- }
54
- /**
55
- * Get the account tree (hierarchical).
56
- */
57
- async getAccountTree(graphId) {
58
- const response = await (0, sdk_gen_1.getLedgerAccountTree)({
59
- path: { graph_id: graphId },
60
- });
61
- if (response.error) {
62
- throw new Error(`Get account tree failed: ${JSON.stringify(response.error)}`);
63
- }
64
- return response.data;
65
- }
66
- // ── Transactions ────────────────────────────────────────────────────
67
- /**
68
- * List transactions with optional date filters.
69
- */
70
- async listTransactions(graphId, options) {
71
- const response = await (0, sdk_gen_1.listLedgerTransactions)({
72
- path: { graph_id: graphId },
73
- query: {
74
- start_date: options?.startDate,
75
- end_date: options?.endDate,
76
- limit: options?.limit,
77
- offset: options?.offset,
78
- },
79
- });
80
- if (response.error) {
81
- throw new Error(`List transactions failed: ${JSON.stringify(response.error)}`);
82
- }
83
- return response.data;
84
- }
85
- /**
86
- * Get transaction detail with entries and line items.
87
- */
88
- async getTransaction(graphId, transactionId) {
89
- const response = await (0, sdk_gen_1.getLedgerTransaction)({
90
- path: { graph_id: graphId, transaction_id: transactionId },
91
- });
92
- if (response.error) {
93
- throw new Error(`Get transaction failed: ${JSON.stringify(response.error)}`);
94
- }
95
- return response.data;
96
- }
97
- // ── Trial Balance ──────────────────────────────────────────────────
98
- /**
99
- * Get trial balance (CoA-level debits/credits).
100
- */
101
- async getTrialBalance(graphId, options) {
102
- const response = await (0, sdk_gen_1.getLedgerTrialBalance)({
103
- path: { graph_id: graphId },
104
- query: {
105
- start_date: options?.startDate,
106
- end_date: options?.endDate,
107
- },
108
- });
109
- if (response.error) {
110
- throw new Error(`Get trial balance failed: ${JSON.stringify(response.error)}`);
111
- }
112
- return response.data;
113
- }
114
- /**
115
- * Get mapped trial balance (CoA rolled up to GAAP concepts).
116
- */
117
- async getMappedTrialBalance(graphId, options) {
118
- const response = await (0, sdk_gen_1.getMappedTrialBalance)({
119
- path: { graph_id: graphId },
120
- query: {
121
- mapping_id: options?.mappingId,
122
- start_date: options?.startDate,
123
- end_date: options?.endDate,
124
- },
125
- });
126
- if (response.error) {
127
- throw new Error(`Get mapped trial balance failed: ${JSON.stringify(response.error)}`);
128
- }
129
- return response.data;
130
- }
131
- // ── Summary ────────────────────────────────────────────────────────
132
- /**
133
- * Get ledger summary (account count, transaction count, date range).
134
- */
135
- async getSummary(graphId) {
136
- const response = await (0, sdk_gen_1.getLedgerSummary)({
137
- path: { graph_id: graphId },
138
- });
139
- if (response.error) {
140
- throw new Error(`Get summary failed: ${JSON.stringify(response.error)}`);
141
- }
142
- return response.data;
143
- }
144
- // ── Taxonomy ────────────────────────────────────────────────────────
145
- /**
146
- * Get the reporting taxonomy (US GAAP seed).
147
- */
148
- async getReportingTaxonomy(graphId) {
149
- const response = await (0, sdk_gen_1.getReportingTaxonomy)({
150
- path: { graph_id: graphId },
151
- });
152
- if (response.error) {
153
- throw new Error(`Get reporting taxonomy failed: ${JSON.stringify(response.error)}`);
154
- }
155
- return response.data;
156
- }
157
- /**
158
- * List reporting structures (IS, BS, CF) for a taxonomy.
159
- */
160
- async listStructures(graphId, taxonomyId) {
161
- const response = await (0, sdk_gen_1.listStructures)({
162
- path: { graph_id: graphId },
163
- query: taxonomyId ? { taxonomy_id: taxonomyId } : undefined,
164
- });
165
- if (response.error) {
166
- throw new Error(`List structures failed: ${JSON.stringify(response.error)}`);
167
- }
168
- const data = response.data;
169
- return (data.structures ?? []).map((s) => ({
170
- id: s.id,
171
- name: s.name,
172
- structureType: s.structure_type,
173
- }));
174
- }
175
- /**
176
- * List elements (CoA accounts, GAAP concepts, etc.).
177
- */
178
- async listElements(graphId, options) {
179
- const response = await (0, sdk_gen_1.listElements)({
180
- path: { graph_id: graphId },
181
- query: {
182
- taxonomy_id: options?.taxonomyId,
183
- source: options?.source,
184
- classification: options?.classification,
185
- is_abstract: options?.isAbstract,
186
- limit: options?.limit,
187
- offset: options?.offset,
188
- },
189
- });
190
- if (response.error) {
191
- throw new Error(`List elements failed: ${JSON.stringify(response.error)}`);
192
- }
193
- return response.data;
194
- }
195
- // ── Mappings ────────────────────────────────────────────────────────
196
- /**
197
- * Create a new CoA→GAAP mapping structure.
198
- * Returns the created mapping info.
199
- */
200
- async createMappingStructure(graphId, options) {
201
- const response = await (0, sdk_gen_1.createStructure)({
202
- path: { graph_id: graphId },
203
- body: {
204
- name: options?.name ?? 'CoA to Reporting',
205
- description: options?.description ?? 'Map Chart of Accounts to US GAAP reporting concepts',
206
- structure_type: 'coa_mapping',
207
- taxonomy_id: options?.taxonomyId ?? 'tax_usgaap_reporting',
208
- },
209
- });
210
- if (response.error) {
211
- throw new Error(`Create mapping structure failed: ${JSON.stringify(response.error)}`);
212
- }
213
- const data = response.data;
214
- return {
215
- id: data.id,
216
- name: data.name,
217
- description: data.description ?? null,
218
- structureType: data.structure_type,
219
- taxonomyId: data.taxonomy_id,
220
- isActive: data.is_active ?? true,
221
- };
222
- }
223
- /**
224
- * List available CoA→GAAP mapping structures.
225
- */
226
- async listMappings(graphId) {
227
- const response = await (0, sdk_gen_1.listMappings)({
228
- path: { graph_id: graphId },
229
- });
230
- if (response.error) {
231
- throw new Error(`List mappings failed: ${JSON.stringify(response.error)}`);
232
- }
233
- const data = response.data;
234
- return (data.structures ?? []).map((s) => ({
235
- id: s.id,
236
- name: s.name,
237
- description: s.description ?? null,
238
- structureType: s.structure_type,
239
- taxonomyId: s.taxonomy_id,
240
- isActive: s.is_active ?? true,
241
- }));
242
- }
243
- /**
244
- * Get mapping detail — all associations with element names.
245
- */
246
- async getMappingDetail(graphId, mappingId) {
247
- const response = await (0, sdk_gen_1.getMappingDetail)({
248
- path: { graph_id: graphId, mapping_id: mappingId },
249
- });
250
- if (response.error) {
251
- throw new Error(`Get mapping detail failed: ${JSON.stringify(response.error)}`);
252
- }
253
- return response.data;
254
- }
255
- /**
256
- * Get mapping coverage — how many CoA elements are mapped.
257
- */
258
- async getMappingCoverage(graphId, mappingId) {
259
- const response = await (0, sdk_gen_1.getMappingCoverage)({
260
- path: { graph_id: graphId, mapping_id: mappingId },
261
- });
262
- if (response.error) {
263
- throw new Error(`Get mapping coverage failed: ${JSON.stringify(response.error)}`);
264
- }
265
- const data = response.data;
266
- return {
267
- totalCoaElements: data.total_coa_elements ?? 0,
268
- mappedCount: data.mapped_count ?? 0,
269
- unmappedCount: data.unmapped_count ?? 0,
270
- coveragePercent: data.coverage_percent ?? 0,
271
- highConfidence: data.high_confidence ?? 0,
272
- mediumConfidence: data.medium_confidence ?? 0,
273
- lowConfidence: data.low_confidence ?? 0,
274
- };
275
- }
276
- /**
277
- * Create a manual mapping association (CoA element → GAAP element).
278
- */
279
- async createMapping(graphId, mappingId, fromElementId, toElementId, confidence) {
280
- const response = await (0, sdk_gen_1.createMappingAssociation)({
281
- path: { graph_id: graphId, mapping_id: mappingId },
282
- body: {
283
- from_element_id: fromElementId,
284
- to_element_id: toElementId,
285
- confidence: confidence ?? 1.0,
286
- },
287
- });
288
- if (response.error) {
289
- throw new Error(`Create mapping failed: ${JSON.stringify(response.error)}`);
290
- }
291
- }
292
- /**
293
- * Delete a mapping association.
294
- */
295
- async deleteMapping(graphId, mappingId, associationId) {
296
- const response = await (0, sdk_gen_1.deleteMappingAssociation)({
297
- path: { graph_id: graphId, mapping_id: mappingId, association_id: associationId },
298
- });
299
- if (response.error) {
300
- throw new Error(`Delete mapping failed: ${JSON.stringify(response.error)}`);
301
- }
302
- }
303
- /**
304
- * Trigger AI auto-mapping (MappingAgent).
305
- * Returns immediately — the agent runs in the background.
306
- */
307
- async autoMap(graphId, mappingId) {
308
- const response = await (0, sdk_gen_1.autoMapElements)({
309
- path: { graph_id: graphId, mapping_id: mappingId },
310
- });
311
- if (response.error) {
312
- throw new Error(`Auto-map failed: ${JSON.stringify(response.error)}`);
313
- }
314
- const data = response.data;
315
- return {
316
- operationId: data?.operation_id,
317
- };
318
- }
319
- // ── Schedules ──────────────────────────────────────────────────────
320
- /**
321
- * Create a schedule with pre-generated monthly facts.
322
- */
323
- async createSchedule(graphId, options) {
324
- const body = {
325
- name: options.name,
326
- element_ids: options.elementIds,
327
- period_start: options.periodStart,
328
- period_end: options.periodEnd,
329
- monthly_amount: options.monthlyAmount,
330
- entry_template: {
331
- debit_element_id: options.entryTemplate.debitElementId,
332
- credit_element_id: options.entryTemplate.creditElementId,
333
- entry_type: options.entryTemplate.entryType,
334
- memo_template: options.entryTemplate.memoTemplate,
335
- },
336
- taxonomy_id: options.taxonomyId,
337
- schedule_metadata: options.scheduleMetadata
338
- ? {
339
- method: options.scheduleMetadata.method,
340
- original_amount: options.scheduleMetadata.originalAmount,
341
- residual_value: options.scheduleMetadata.residualValue,
342
- useful_life_months: options.scheduleMetadata.usefulLifeMonths,
343
- asset_element_id: options.scheduleMetadata.assetElementId,
344
- }
345
- : undefined,
346
- };
347
- const response = await (0, sdk_gen_1.createSchedule)({
348
- path: { graph_id: graphId },
349
- body,
350
- });
351
- if (response.error) {
352
- throw new Error(`Create schedule failed: ${JSON.stringify(response.error)}`);
353
- }
354
- const data = response.data;
355
- return {
356
- structureId: data.structure_id,
357
- name: data.name,
358
- taxonomyId: data.taxonomy_id,
359
- totalPeriods: data.total_periods,
360
- totalFacts: data.total_facts,
361
- };
362
- }
363
- /**
364
- * List all schedules for a graph.
365
- */
366
- async listSchedules(graphId) {
367
- const response = await (0, sdk_gen_1.listSchedules)({
368
- path: { graph_id: graphId },
369
- });
370
- if (response.error) {
371
- throw new Error(`List schedules failed: ${JSON.stringify(response.error)}`);
372
- }
373
- const data = response.data;
374
- return (data.schedules ?? []).map((s) => ({
375
- structureId: s.structure_id,
376
- name: s.name,
377
- taxonomyName: s.taxonomy_name,
378
- entryTemplate: s.entry_template ?? null,
379
- scheduleMetadata: s.schedule_metadata ?? null,
380
- totalPeriods: s.total_periods,
381
- periodsWithEntries: s.periods_with_entries,
382
- }));
383
- }
384
- /**
385
- * Get facts for a schedule, optionally filtered by period.
386
- */
387
- async getScheduleFacts(graphId, structureId, periodStart, periodEnd) {
388
- const response = await (0, sdk_gen_1.getScheduleFacts)({
389
- path: { graph_id: graphId, structure_id: structureId },
390
- query: {
391
- period_start: periodStart ?? null,
392
- period_end: periodEnd ?? null,
393
- },
394
- });
395
- if (response.error) {
396
- throw new Error(`Get schedule facts failed: ${JSON.stringify(response.error)}`);
397
- }
398
- const data = response.data;
399
- return (data.facts ?? []).map((f) => ({
400
- elementId: f.element_id,
401
- elementName: f.element_name,
402
- value: f.value,
403
- periodStart: f.period_start,
404
- periodEnd: f.period_end,
405
- }));
406
- }
407
- /**
408
- * Get close status for all schedules in a fiscal period.
409
- */
410
- async getPeriodCloseStatus(graphId, periodStart, periodEnd) {
411
- const response = await (0, sdk_gen_1.getPeriodCloseStatus)({
412
- path: { graph_id: graphId },
413
- query: { period_start: periodStart, period_end: periodEnd },
414
- });
415
- if (response.error) {
416
- throw new Error(`Get period close status failed: ${JSON.stringify(response.error)}`);
417
- }
418
- const data = response.data;
419
- return {
420
- fiscalPeriodStart: data.fiscal_period_start,
421
- fiscalPeriodEnd: data.fiscal_period_end,
422
- periodStatus: data.period_status,
423
- schedules: (data.schedules ?? []).map((s) => ({
424
- structureId: s.structure_id,
425
- structureName: s.structure_name,
426
- amount: s.amount,
427
- status: s.status,
428
- entryId: s.entry_id ?? null,
429
- })),
430
- totalDraft: data.total_draft,
431
- totalPosted: data.total_posted,
432
- };
433
- }
434
- /**
435
- * Idempotently create (or refresh) a draft closing entry from a schedule's
436
- * facts for a period. The `outcome` field describes what actually happened:
437
- *
438
- * - `created` — new draft
439
- * - `unchanged` — existing draft still matches the schedule; no-op
440
- * - `regenerated` — existing draft was stale; replaced
441
- * - `removed` — schedule no longer covers this period; stale draft deleted
442
- * - `skipped` — no existing draft and no in-scope fact; nothing to do
443
- */
444
- async createClosingEntry(graphId, structureId, postingDate, periodStart, periodEnd, memo) {
445
- const body = {
446
- posting_date: postingDate,
447
- period_start: periodStart,
448
- period_end: periodEnd,
449
- memo: memo ?? undefined,
450
- };
451
- const response = await (0, sdk_gen_1.createClosingEntry)({
452
- path: { graph_id: graphId, structure_id: structureId },
453
- body,
454
- });
455
- if (response.error) {
456
- throw new Error(`Create closing entry failed: ${JSON.stringify(response.error)}`);
457
- }
458
- const data = response.data;
459
- return toClosingEntry(data);
460
- }
461
- // ── Closing Book ─────────────────────────────────────────────────────
462
- /**
463
- * Get all closing book structure categories for the sidebar.
464
- * Returns statements, account rollups, schedules, trial balance,
465
- * and period close grouped into categories.
466
- */
467
- async getClosingBookStructures(graphId) {
468
- const response = await (0, sdk_gen_1.getClosingBookStructures)({
469
- path: { graph_id: graphId },
470
- });
471
- if (response.error) {
472
- throw new Error(`Get closing book structures failed: ${JSON.stringify(response.error)}`);
473
- }
474
- return response.data;
475
- }
476
- /**
477
- * Get account rollups — CoA accounts grouped by reporting element with balances.
478
- * Shows how company-specific accounts roll up to standardized reporting lines.
479
- */
480
- async getAccountRollups(graphId, options) {
481
- const response = await (0, sdk_gen_1.getAccountRollups)({
482
- path: { graph_id: graphId },
483
- query: {
484
- mapping_id: options?.mappingId,
485
- start_date: options?.startDate,
486
- end_date: options?.endDate,
487
- },
488
- });
489
- if (response.error) {
490
- throw new Error(`Get account rollups failed: ${JSON.stringify(response.error)}`);
491
- }
492
- return response.data;
493
- }
494
- // ── Fiscal Calendar ─────────────────────────────────────────────────
495
- /**
496
- * Initialize the fiscal calendar for a graph. Creates FiscalPeriod rows
497
- * for the data window, sets `closed_through` / `close_target`, and emits
498
- * an `initialized` audit event. Fails with 409 if already initialized.
499
- */
500
- async initializeLedger(graphId, options) {
501
- const body = {
502
- closed_through: options?.closedThrough ?? null,
503
- fiscal_year_start_month: options?.fiscalYearStartMonth,
504
- earliest_data_period: options?.earliestDataPeriod ?? null,
505
- auto_seed_schedules: options?.autoSeedSchedules,
506
- note: options?.note ?? null,
507
- };
508
- const response = await (0, sdk_gen_1.initializeLedger)({
509
- path: { graph_id: graphId },
510
- body,
511
- });
512
- if (response.error) {
513
- throw new Error(`Initialize ledger failed: ${JSON.stringify(response.error)}`);
514
- }
515
- const data = response.data;
516
- return {
517
- fiscalCalendar: toFiscalCalendarState(data.fiscal_calendar),
518
- periodsCreated: data.periods_created ?? 0,
519
- warnings: data.warnings ?? [],
520
- };
521
- }
522
- /**
523
- * Get the current fiscal calendar state — pointers, gap, closeable status.
524
- */
525
- async getFiscalCalendar(graphId) {
526
- const response = await (0, sdk_gen_1.getFiscalCalendar)({
527
- path: { graph_id: graphId },
528
- });
529
- if (response.error) {
530
- throw new Error(`Get fiscal calendar failed: ${JSON.stringify(response.error)}`);
531
- }
532
- return toFiscalCalendarState(response.data);
533
- }
534
- /**
535
- * Set the close target for a graph. Validates that the target is not in
536
- * the future and not before `closed_through`.
537
- */
538
- async setCloseTarget(graphId, period, note) {
539
- const body = {
540
- period,
541
- note: note ?? null,
542
- };
543
- const response = await (0, sdk_gen_1.setCloseTarget)({
544
- path: { graph_id: graphId },
545
- body,
546
- });
547
- if (response.error) {
548
- throw new Error(`Set close target failed: ${JSON.stringify(response.error)}`);
549
- }
550
- return toFiscalCalendarState(response.data);
551
- }
552
- /**
553
- * Close a fiscal period — the final commit action.
554
- *
555
- * Validates closeable gates, transitions all draft entries in the period
556
- * to `posted`, marks the FiscalPeriod closed, and advances `closed_through`
557
- * (auto-advancing `close_target` when reached).
558
- */
559
- async closePeriod(graphId, period, options) {
560
- const body = {
561
- note: options?.note ?? null,
562
- allow_stale_sync: options?.allowStaleSync,
563
- };
564
- const response = await (0, sdk_gen_1.closeFiscalPeriod)({
565
- path: { graph_id: graphId, period },
566
- body,
567
- });
568
- if (response.error) {
569
- throw new Error(`Close period failed: ${JSON.stringify(response.error)}`);
570
- }
571
- const data = response.data;
572
- return {
573
- period: data.period,
574
- entriesPosted: data.entries_posted ?? 0,
575
- targetAutoAdvanced: data.target_auto_advanced ?? false,
576
- fiscalCalendar: toFiscalCalendarState(data.fiscal_calendar),
577
- };
578
- }
579
- /**
580
- * Reopen a closed fiscal period. Requires a non-empty `reason` for the
581
- * audit log. Posted entries stay posted; the period transitions to
582
- * `closing` so the user can post adjustments and re-close.
583
- */
584
- async reopenPeriod(graphId, period, reason, note) {
585
- const body = {
586
- reason,
587
- note: note ?? null,
588
- };
589
- const response = await (0, sdk_gen_1.reopenFiscalPeriod)({
590
- path: { graph_id: graphId, period },
591
- body,
592
- });
593
- if (response.error) {
594
- throw new Error(`Reopen period failed: ${JSON.stringify(response.error)}`);
595
- }
596
- return toFiscalCalendarState(response.data);
597
- }
598
- /**
599
- * List all draft entries in a fiscal period for review before close.
600
- * Fully expanded with line items, element metadata, and per-entry balance.
601
- *
602
- * Pure read — call repeatedly without side effects.
603
- */
604
- async listPeriodDrafts(graphId, period) {
605
- const response = await (0, sdk_gen_1.listPeriodDrafts)({
606
- path: { graph_id: graphId, period },
607
- });
608
- if (response.error) {
609
- throw new Error(`List period drafts failed: ${JSON.stringify(response.error)}`);
610
- }
611
- const data = response.data;
612
- return {
613
- period: data.period,
614
- periodStart: data.period_start,
615
- periodEnd: data.period_end,
616
- draftCount: data.draft_count,
617
- totalDebit: data.total_debit,
618
- totalCredit: data.total_credit,
619
- allBalanced: data.all_balanced,
620
- drafts: (data.drafts ?? []).map((d) => ({
621
- entryId: d.entry_id,
622
- postingDate: d.posting_date,
623
- type: d.type,
624
- memo: d.memo ?? null,
625
- provenance: d.provenance ?? null,
626
- sourceStructureId: d.source_structure_id ?? null,
627
- sourceStructureName: d.source_structure_name ?? null,
628
- lineItems: d.line_items.map((li) => ({
629
- lineItemId: li.line_item_id,
630
- elementId: li.element_id,
631
- elementCode: li.element_code ?? null,
632
- elementName: li.element_name,
633
- debitAmount: li.debit_amount,
634
- creditAmount: li.credit_amount,
635
- description: li.description ?? null,
636
- })),
637
- totalDebit: d.total_debit,
638
- totalCredit: d.total_credit,
639
- balanced: d.balanced,
640
- })),
641
- };
642
- }
643
- // ── Schedule mutations ──────────────────────────────────────────────
644
- /**
645
- * Truncate a schedule — end it early by deleting facts with
646
- * `period_start > new_end_date`, along with any stale draft entries they
647
- * produced. Historical posted facts are preserved.
648
- *
649
- * `new_end_date` must be a month-end date (service enforces this).
650
- */
651
- async truncateSchedule(graphId, structureId, options) {
652
- const body = {
653
- new_end_date: options.newEndDate,
654
- reason: options.reason,
655
- };
656
- const response = await (0, sdk_gen_1.truncateSchedule)({
657
- path: { graph_id: graphId, structure_id: structureId },
658
- body,
659
- });
660
- if (response.error) {
661
- throw new Error(`Truncate schedule failed: ${JSON.stringify(response.error)}`);
662
- }
663
- const data = response.data;
664
- return {
665
- structureId: data.structure_id,
666
- newEndDate: data.new_end_date,
667
- factsDeleted: data.facts_deleted,
668
- reason: data.reason,
669
- };
670
- }
671
- /**
672
- * Create a manual draft closing entry with arbitrary balanced line items.
673
- * Not tied to a schedule — used for disposals, adjustments, and other
674
- * one-off closing events.
675
- *
676
- * Line items must sum to balanced debits/credits. Rejects entries
677
- * targeting an already-closed period.
678
- */
679
- async createManualClosingEntry(graphId, options) {
680
- const body = {
681
- posting_date: options.postingDate,
682
- memo: options.memo,
683
- entry_type: options.entryType,
684
- line_items: options.lineItems.map((li) => ({
685
- element_id: li.elementId,
686
- debit_amount: li.debitAmount ?? 0,
687
- credit_amount: li.creditAmount ?? 0,
688
- description: li.description ?? null,
689
- })),
690
- };
691
- const response = await (0, sdk_gen_1.createManualClosingEntry)({
692
- path: { graph_id: graphId },
693
- body,
694
- });
695
- if (response.error) {
696
- throw new Error(`Create manual closing entry failed: ${JSON.stringify(response.error)}`);
697
- }
698
- return toClosingEntry(response.data);
699
- }
700
- }
701
- exports.LedgerClient = LedgerClient;
702
- // ── Internal helpers ──────────────────────────────────────────────────
703
- function toClosingEntry(data) {
704
- return {
705
- outcome: data.outcome,
706
- entryId: data.entry_id ?? null,
707
- status: data.status ?? null,
708
- postingDate: data.posting_date ?? null,
709
- memo: data.memo ?? null,
710
- debitElementId: data.debit_element_id ?? null,
711
- creditElementId: data.credit_element_id ?? null,
712
- amount: data.amount ?? null,
713
- reason: data.reason ?? null,
714
- };
715
- }
716
- function toFiscalCalendarState(data) {
717
- return {
718
- graphId: data.graph_id,
719
- fiscalYearStartMonth: data.fiscal_year_start_month,
720
- closedThrough: data.closed_through ?? null,
721
- closeTarget: data.close_target ?? null,
722
- gapPeriods: data.gap_periods ?? 0,
723
- catchUpSequence: data.catch_up_sequence ?? [],
724
- closeableNow: data.closeable_now ?? false,
725
- blockers: data.blockers ?? [],
726
- lastCloseAt: data.last_close_at ?? null,
727
- initializedAt: data.initialized_at ?? null,
728
- lastSyncAt: data.last_sync_at ?? null,
729
- periods: (data.periods ?? []).map((p) => ({
730
- name: p.name,
731
- startDate: p.start_date,
732
- endDate: p.end_date,
733
- status: p.status,
734
- closedAt: p.closed_at ?? null,
735
- })),
736
- };
737
- }