@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.
- package/extensions/InvestorClient.d.ts +98 -0
- package/extensions/InvestorClient.js +223 -0
- package/extensions/InvestorClient.ts +508 -0
- package/extensions/LedgerClient.d.ts +190 -309
- package/extensions/LedgerClient.js +268 -587
- package/extensions/LedgerClient.ts +784 -903
- package/extensions/ReportClient.d.ts +82 -113
- package/extensions/ReportClient.js +124 -211
- package/extensions/ReportClient.ts +305 -358
- package/extensions/config.d.ts +19 -0
- package/extensions/config.js +1 -1
- package/extensions/config.ts +22 -2
- package/extensions/graphql/client.d.ts +82 -0
- package/extensions/graphql/client.js +149 -0
- package/extensions/graphql/client.ts +189 -0
- package/extensions/graphql/generated/graphql.d.ts +1786 -0
- package/extensions/graphql/generated/graphql.js +2671 -0
- package/extensions/graphql/generated/graphql.ts +4491 -0
- package/extensions/graphql/queries/investor/holdings.d.ts +8 -0
- package/extensions/graphql/queries/investor/holdings.js +36 -0
- package/extensions/graphql/queries/investor/holdings.ts +34 -0
- package/extensions/graphql/queries/investor/portfolio.d.ts +4 -0
- package/extensions/graphql/queries/investor/portfolio.js +21 -0
- package/extensions/graphql/queries/investor/portfolio.ts +19 -0
- package/extensions/graphql/queries/investor/portfolios.d.ts +4 -0
- package/extensions/graphql/queries/investor/portfolios.js +29 -0
- package/extensions/graphql/queries/investor/portfolios.ts +27 -0
- package/extensions/graphql/queries/investor/position.d.ts +4 -0
- package/extensions/graphql/queries/investor/position.js +33 -0
- package/extensions/graphql/queries/investor/position.ts +31 -0
- package/extensions/graphql/queries/investor/positions.d.ts +8 -0
- package/extensions/graphql/queries/investor/positions.js +57 -0
- package/extensions/graphql/queries/investor/positions.ts +55 -0
- package/extensions/graphql/queries/investor/securities.d.ts +8 -0
- package/extensions/graphql/queries/investor/securities.js +50 -0
- package/extensions/graphql/queries/investor/securities.ts +48 -0
- package/extensions/graphql/queries/investor/security.d.ts +4 -0
- package/extensions/graphql/queries/investor/security.js +26 -0
- package/extensions/graphql/queries/investor/security.ts +24 -0
- package/extensions/graphql/queries/ledger/accountRollups.d.ts +7 -0
- package/extensions/graphql/queries/ledger/accountRollups.js +36 -0
- package/extensions/graphql/queries/ledger/accountRollups.ts +34 -0
- package/extensions/graphql/queries/ledger/accountTree.d.ts +11 -0
- package/extensions/graphql/queries/ledger/accountTree.js +61 -0
- package/extensions/graphql/queries/ledger/accountTree.ts +59 -0
- package/extensions/graphql/queries/ledger/accounts.d.ts +8 -0
- package/extensions/graphql/queries/ledger/accounts.js +45 -0
- package/extensions/graphql/queries/ledger/accounts.ts +43 -0
- package/extensions/graphql/queries/ledger/closingBookStructures.d.ts +6 -0
- package/extensions/graphql/queries/ledger/closingBookStructures.js +27 -0
- package/extensions/graphql/queries/ledger/closingBookStructures.ts +25 -0
- package/extensions/graphql/queries/ledger/elements.d.ts +6 -0
- package/extensions/graphql/queries/ledger/elements.js +56 -0
- package/extensions/graphql/queries/ledger/elements.ts +54 -0
- package/extensions/graphql/queries/ledger/entities.d.ts +7 -0
- package/extensions/graphql/queries/ledger/entities.js +31 -0
- package/extensions/graphql/queries/ledger/entities.ts +29 -0
- package/extensions/graphql/queries/ledger/entity.d.ts +14 -0
- package/extensions/graphql/queries/ledger/entity.js +55 -0
- package/extensions/graphql/queries/ledger/entity.ts +54 -0
- package/extensions/graphql/queries/ledger/fiscalCalendar.d.ts +8 -0
- package/extensions/graphql/queries/ledger/fiscalCalendar.js +35 -0
- package/extensions/graphql/queries/ledger/fiscalCalendar.ts +33 -0
- package/extensions/graphql/queries/ledger/mappedTrialBalance.d.ts +9 -0
- package/extensions/graphql/queries/ledger/mappedTrialBalance.js +29 -0
- package/extensions/graphql/queries/ledger/mappedTrialBalance.ts +27 -0
- package/extensions/graphql/queries/ledger/mapping.d.ts +5 -0
- package/extensions/graphql/queries/ledger/mapping.js +35 -0
- package/extensions/graphql/queries/ledger/mapping.ts +33 -0
- package/extensions/graphql/queries/ledger/mappingCoverage.d.ts +5 -0
- package/extensions/graphql/queries/ledger/mappingCoverage.js +22 -0
- package/extensions/graphql/queries/ledger/mappingCoverage.ts +20 -0
- package/extensions/graphql/queries/ledger/mappings.d.ts +6 -0
- package/extensions/graphql/queries/ledger/mappings.js +23 -0
- package/extensions/graphql/queries/ledger/mappings.ts +21 -0
- package/extensions/graphql/queries/ledger/periodCloseStatus.d.ts +6 -0
- package/extensions/graphql/queries/ledger/periodCloseStatus.js +29 -0
- package/extensions/graphql/queries/ledger/periodCloseStatus.ts +27 -0
- package/extensions/graphql/queries/ledger/periodDrafts.d.ts +8 -0
- package/extensions/graphql/queries/ledger/periodDrafts.js +45 -0
- package/extensions/graphql/queries/ledger/periodDrafts.ts +43 -0
- package/extensions/graphql/queries/ledger/publishList.d.ts +5 -0
- package/extensions/graphql/queries/ledger/publishList.js +29 -0
- package/extensions/graphql/queries/ledger/publishList.ts +27 -0
- package/extensions/graphql/queries/ledger/publishLists.d.ts +5 -0
- package/extensions/graphql/queries/ledger/publishLists.js +29 -0
- package/extensions/graphql/queries/ledger/publishLists.ts +27 -0
- package/extensions/graphql/queries/ledger/report.d.ts +5 -0
- package/extensions/graphql/queries/ledger/report.js +40 -0
- package/extensions/graphql/queries/ledger/report.ts +38 -0
- package/extensions/graphql/queries/ledger/reportingTaxonomy.d.ts +6 -0
- package/extensions/graphql/queries/ledger/reportingTaxonomy.js +27 -0
- package/extensions/graphql/queries/ledger/reportingTaxonomy.ts +25 -0
- package/extensions/graphql/queries/ledger/reports.d.ts +8 -0
- package/extensions/graphql/queries/ledger/reports.js +45 -0
- package/extensions/graphql/queries/ledger/reports.ts +43 -0
- package/extensions/graphql/queries/ledger/scheduleFacts.d.ts +7 -0
- package/extensions/graphql/queries/ledger/scheduleFacts.js +24 -0
- package/extensions/graphql/queries/ledger/scheduleFacts.ts +22 -0
- package/extensions/graphql/queries/ledger/schedules.d.ts +6 -0
- package/extensions/graphql/queries/ledger/schedules.js +24 -0
- package/extensions/graphql/queries/ledger/schedules.ts +22 -0
- package/extensions/graphql/queries/ledger/statement.d.ts +9 -0
- package/extensions/graphql/queries/ledger/statement.js +43 -0
- package/extensions/graphql/queries/ledger/statement.ts +41 -0
- package/extensions/graphql/queries/ledger/structures.d.ts +5 -0
- package/extensions/graphql/queries/ledger/structures.js +22 -0
- package/extensions/graphql/queries/ledger/structures.ts +20 -0
- package/extensions/graphql/queries/ledger/summary.d.ts +7 -0
- package/extensions/graphql/queries/ledger/summary.js +25 -0
- package/extensions/graphql/queries/ledger/summary.ts +23 -0
- package/extensions/graphql/queries/ledger/taxonomies.d.ts +5 -0
- package/extensions/graphql/queries/ledger/taxonomies.js +28 -0
- package/extensions/graphql/queries/ledger/taxonomies.ts +26 -0
- package/extensions/graphql/queries/ledger/transaction.d.ts +6 -0
- package/extensions/graphql/queries/ledger/transaction.js +49 -0
- package/extensions/graphql/queries/ledger/transaction.ts +47 -0
- package/extensions/graphql/queries/ledger/transactions.d.ts +7 -0
- package/extensions/graphql/queries/ledger/transactions.js +49 -0
- package/extensions/graphql/queries/ledger/transactions.ts +47 -0
- package/extensions/graphql/queries/ledger/trialBalance.d.ts +7 -0
- package/extensions/graphql/queries/ledger/trialBalance.js +28 -0
- package/extensions/graphql/queries/ledger/trialBalance.ts +26 -0
- package/extensions/graphql/queries/ledger/unmappedElements.d.ts +8 -0
- package/extensions/graphql/queries/ledger/unmappedElements.js +29 -0
- package/extensions/graphql/queries/ledger/unmappedElements.ts +27 -0
- package/extensions/hooks.d.ts +1 -1
- package/extensions/index.d.ts +18 -1
- package/extensions/index.js +26 -1
- package/extensions/index.ts +49 -2
- package/index.ts +2 -2
- package/package.json +14 -5
- package/sdk/index.d.ts +2 -2
- package/sdk/index.js +38 -73
- package/sdk/index.ts +2 -2
- package/sdk/sdk.gen.d.ts +100 -325
- package/sdk/sdk.gen.js +228 -592
- package/sdk/sdk.gen.ts +193 -556
- package/sdk/types.gen.d.ts +4522 -7708
- package/sdk/types.gen.ts +4569 -7983
- package/sdk.gen.d.ts +100 -325
- package/sdk.gen.js +228 -592
- package/sdk.gen.ts +193 -556
- package/types.gen.d.ts +4522 -7708
- package/types.gen.ts +4569 -7983
- package/extensions/AgentClient.test.ts +0 -403
- package/extensions/LedgerClient.test.ts +0 -1655
- package/extensions/OperationClient.test.ts +0 -365
- package/extensions/QueryClient.test.ts +0 -432
- package/extensions/ReportClient.test.ts +0 -828
- package/extensions/SSEClient.test.ts +0 -375
- package/extensions/config.test.ts +0 -199
- package/extensions/hooks.test.ts +0 -373
- package/extensions/index.test.ts +0 -420
- package/sdk-extensions/AgentClient.d.ts +0 -82
- package/sdk-extensions/AgentClient.js +0 -218
- package/sdk-extensions/AgentClient.test.ts +0 -403
- package/sdk-extensions/AgentClient.ts +0 -321
- package/sdk-extensions/LedgerClient.d.ts +0 -416
- package/sdk-extensions/LedgerClient.js +0 -737
- package/sdk-extensions/LedgerClient.test.ts +0 -1655
- package/sdk-extensions/LedgerClient.ts +0 -1249
- package/sdk-extensions/OperationClient.d.ts +0 -65
- package/sdk-extensions/OperationClient.js +0 -251
- package/sdk-extensions/OperationClient.test.ts +0 -365
- package/sdk-extensions/OperationClient.ts +0 -324
- package/sdk-extensions/QueryClient.d.ts +0 -52
- package/sdk-extensions/QueryClient.js +0 -313
- package/sdk-extensions/QueryClient.test.ts +0 -432
- package/sdk-extensions/QueryClient.ts +0 -420
- package/sdk-extensions/README.md +0 -901
- package/sdk-extensions/ReportClient.d.ts +0 -151
- package/sdk-extensions/ReportClient.js +0 -278
- package/sdk-extensions/ReportClient.test.ts +0 -828
- package/sdk-extensions/ReportClient.ts +0 -486
- package/sdk-extensions/SSEClient.d.ts +0 -62
- package/sdk-extensions/SSEClient.js +0 -154
- package/sdk-extensions/SSEClient.test.ts +0 -375
- package/sdk-extensions/SSEClient.ts +0 -210
- package/sdk-extensions/config.d.ts +0 -57
- package/sdk-extensions/config.js +0 -152
- package/sdk-extensions/config.test.ts +0 -199
- package/sdk-extensions/config.ts +0 -175
- package/sdk-extensions/hooks.d.ts +0 -110
- package/sdk-extensions/hooks.js +0 -384
- package/sdk-extensions/hooks.test.ts +0 -373
- package/sdk-extensions/hooks.ts +0 -459
- package/sdk-extensions/index.d.ts +0 -63
- package/sdk-extensions/index.js +0 -164
- package/sdk-extensions/index.test.ts +0 -420
- package/sdk-extensions/index.ts +0 -203
|
@@ -2,324 +2,192 @@
|
|
|
2
2
|
"use strict";
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
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
|
-
*/
|
|
5
|
+
const graphql_request_1 = require("graphql-request");
|
|
12
6
|
const sdk_gen_1 = require("../sdk.gen");
|
|
13
|
-
|
|
7
|
+
const client_1 = require("./graphql/client");
|
|
8
|
+
const graphql_1 = require("./graphql/generated/graphql");
|
|
14
9
|
class LedgerClient {
|
|
15
10
|
constructor(config) {
|
|
16
11
|
this.config = config;
|
|
12
|
+
this.gql = new client_1.GraphQLClientCache(config);
|
|
17
13
|
}
|
|
18
14
|
// ── Entity ──────────────────────────────────────────────────────────
|
|
19
15
|
/**
|
|
20
16
|
* Get the entity (company/organization) for this graph.
|
|
17
|
+
* Returns null when the ledger has no entity yet.
|
|
21
18
|
*/
|
|
22
19
|
async getEntity(graphId) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
-
};
|
|
20
|
+
return this.gqlQuery(graphId, graphql_1.GetLedgerEntityDocument, undefined, 'Get entity', (data) => data.entity);
|
|
21
|
+
}
|
|
22
|
+
/** List all entities for this graph, optionally filtered by source system. */
|
|
23
|
+
async listEntities(graphId, options) {
|
|
24
|
+
return this.gqlQuery(graphId, graphql_1.ListLedgerEntitiesDocument, { source: options?.source ?? null }, 'List entities', (data) => data.entities);
|
|
40
25
|
}
|
|
41
|
-
// ── Accounts (Chart of Accounts) ───────────────────────────────────
|
|
42
26
|
/**
|
|
43
|
-
*
|
|
27
|
+
* Update the entity for this graph. Only non-null fields are applied.
|
|
28
|
+
* Returns the updated entity.
|
|
44
29
|
*/
|
|
45
|
-
async
|
|
46
|
-
const
|
|
30
|
+
async updateEntity(graphId, updates) {
|
|
31
|
+
const envelope = await this.callOperation('Update entity', (0, sdk_gen_1.opUpdateEntity)({
|
|
47
32
|
path: { graph_id: graphId },
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
return response.data;
|
|
33
|
+
body: updates,
|
|
34
|
+
}));
|
|
35
|
+
return envelope.result;
|
|
53
36
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
37
|
+
// ── Summary ────────────────────────────────────────────────────────
|
|
38
|
+
/** Ledger rollup counts + QB sync metadata. */
|
|
39
|
+
async getSummary(graphId) {
|
|
40
|
+
return this.gqlQuery(graphId, graphql_1.GetLedgerSummaryDocument, undefined, 'Get summary', (data) => data.summary);
|
|
41
|
+
}
|
|
42
|
+
// ── Accounts (Chart of Accounts) ───────────────────────────────────
|
|
43
|
+
/** List CoA accounts with optional filters and pagination. */
|
|
44
|
+
async listAccounts(graphId, options) {
|
|
45
|
+
return this.gqlQuery(graphId, graphql_1.ListLedgerAccountsDocument, {
|
|
46
|
+
classification: options?.classification ?? null,
|
|
47
|
+
isActive: options?.isActive ?? null,
|
|
48
|
+
limit: options?.limit ?? 100,
|
|
49
|
+
offset: options?.offset ?? 0,
|
|
50
|
+
}, 'List accounts', (data) => data.accounts);
|
|
51
|
+
}
|
|
52
|
+
/** Hierarchical Chart of Accounts (up to 4 levels deep). */
|
|
57
53
|
async getAccountTree(graphId) {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
54
|
+
return this.gqlQuery(graphId, graphql_1.GetLedgerAccountTreeDocument, undefined, 'Get account tree', (data) => data.accountTree);
|
|
55
|
+
}
|
|
56
|
+
/** Accounts rolled up to reporting concepts via a mapping structure. */
|
|
57
|
+
async getAccountRollups(graphId, options) {
|
|
58
|
+
return this.gqlQuery(graphId, graphql_1.GetLedgerAccountRollupsDocument, {
|
|
59
|
+
mappingId: options?.mappingId ?? null,
|
|
60
|
+
startDate: options?.startDate ?? null,
|
|
61
|
+
endDate: options?.endDate ?? null,
|
|
62
|
+
}, 'Get account rollups', (data) => data.accountRollups);
|
|
65
63
|
}
|
|
66
64
|
// ── Transactions ────────────────────────────────────────────────────
|
|
67
|
-
/**
|
|
68
|
-
* List transactions with optional date filters.
|
|
69
|
-
*/
|
|
65
|
+
/** List transactions with optional type + date filters and pagination. */
|
|
70
66
|
async listTransactions(graphId, options) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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
|
-
*/
|
|
67
|
+
return this.gqlQuery(graphId, graphql_1.ListLedgerTransactionsDocument, {
|
|
68
|
+
type: options?.type ?? null,
|
|
69
|
+
startDate: options?.startDate ?? null,
|
|
70
|
+
endDate: options?.endDate ?? null,
|
|
71
|
+
limit: options?.limit ?? 100,
|
|
72
|
+
offset: options?.offset ?? 0,
|
|
73
|
+
}, 'List transactions', (data) => data.transactions);
|
|
74
|
+
}
|
|
75
|
+
/** Get transaction detail with entries + line items. */
|
|
88
76
|
async getTransaction(graphId, transactionId) {
|
|
89
|
-
|
|
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;
|
|
77
|
+
return this.gqlQuery(graphId, graphql_1.GetLedgerTransactionDocument, { transactionId }, 'Get transaction', (data) => data.transaction);
|
|
96
78
|
}
|
|
97
79
|
// ── Trial Balance ──────────────────────────────────────────────────
|
|
98
|
-
/**
|
|
99
|
-
* Get trial balance (CoA-level debits/credits).
|
|
100
|
-
*/
|
|
80
|
+
/** Trial balance by raw CoA account. */
|
|
101
81
|
async getTrialBalance(graphId, options) {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
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;
|
|
82
|
+
return this.gqlQuery(graphId, graphql_1.GetLedgerTrialBalanceDocument, {
|
|
83
|
+
startDate: options?.startDate ?? null,
|
|
84
|
+
endDate: options?.endDate ?? null,
|
|
85
|
+
}, 'Get trial balance', (data) => data.trialBalance);
|
|
86
|
+
}
|
|
87
|
+
/** Trial balance rolled up to GAAP reporting concepts via a mapping. */
|
|
88
|
+
async getMappedTrialBalance(graphId, mappingId, options) {
|
|
89
|
+
return this.gqlQuery(graphId, graphql_1.GetLedgerMappedTrialBalanceDocument, {
|
|
90
|
+
mappingId,
|
|
91
|
+
startDate: options?.startDate ?? null,
|
|
92
|
+
endDate: options?.endDate ?? null,
|
|
93
|
+
}, 'Get mapped trial balance', (data) => data.mappedTrialBalance);
|
|
143
94
|
}
|
|
144
95
|
// ── Taxonomy ────────────────────────────────────────────────────────
|
|
145
|
-
/**
|
|
146
|
-
* Get the reporting taxonomy (US GAAP seed).
|
|
147
|
-
*/
|
|
96
|
+
/** Get the locked US GAAP reporting taxonomy for this graph. */
|
|
148
97
|
async getReportingTaxonomy(graphId) {
|
|
149
|
-
|
|
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;
|
|
98
|
+
return this.gqlQuery(graphId, graphql_1.GetLedgerReportingTaxonomyDocument, undefined, 'Get reporting taxonomy', (data) => data.reportingTaxonomy);
|
|
156
99
|
}
|
|
157
|
-
/**
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
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
|
-
}));
|
|
100
|
+
/** List active taxonomies with optional type filter. */
|
|
101
|
+
async listTaxonomies(graphId, options) {
|
|
102
|
+
const list = await this.gqlQuery(graphId, graphql_1.ListLedgerTaxonomiesDocument, { taxonomyType: options?.taxonomyType ?? null }, 'List taxonomies', (data) => data.taxonomies);
|
|
103
|
+
return list?.taxonomies ?? [];
|
|
174
104
|
}
|
|
175
|
-
/**
|
|
176
|
-
|
|
177
|
-
|
|
105
|
+
/** Create a new taxonomy (used for CoA + mapping taxonomies). */
|
|
106
|
+
async createTaxonomy(graphId, body) {
|
|
107
|
+
const envelope = await this.callOperation('Create taxonomy', (0, sdk_gen_1.opCreateTaxonomy)({ path: { graph_id: graphId }, body }));
|
|
108
|
+
return (envelope.result ?? {});
|
|
109
|
+
}
|
|
110
|
+
/** List elements (CoA accounts, GAAP concepts, etc.) with filters. */
|
|
178
111
|
async listElements(graphId, options) {
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
112
|
+
return this.gqlQuery(graphId, graphql_1.ListLedgerElementsDocument, {
|
|
113
|
+
taxonomyId: options?.taxonomyId ?? null,
|
|
114
|
+
source: options?.source ?? null,
|
|
115
|
+
classification: options?.classification ?? null,
|
|
116
|
+
isAbstract: options?.isAbstract ?? null,
|
|
117
|
+
limit: options?.limit ?? 100,
|
|
118
|
+
offset: options?.offset ?? 0,
|
|
119
|
+
}, 'List elements', (data) => data.elements);
|
|
120
|
+
}
|
|
121
|
+
/** CoA elements not yet mapped to a reporting concept. */
|
|
122
|
+
async listUnmappedElements(graphId, options) {
|
|
123
|
+
return this.gqlQuery(graphId, graphql_1.ListLedgerUnmappedElementsDocument, { mappingId: options?.mappingId ?? null }, 'List unmapped elements', (data) => data.unmappedElements);
|
|
124
|
+
}
|
|
125
|
+
// ── Structures ──────────────────────────────────────────────────────
|
|
126
|
+
/** List reporting structures (IS, BS, CF, schedules) with optional filters. */
|
|
127
|
+
async listStructures(graphId, options) {
|
|
128
|
+
const list = await this.gqlQuery(graphId, graphql_1.ListLedgerStructuresDocument, {
|
|
129
|
+
taxonomyId: options?.taxonomyId ?? null,
|
|
130
|
+
structureType: options?.structureType ?? null,
|
|
131
|
+
}, 'List structures', (data) => data.structures);
|
|
132
|
+
return list?.structures ?? [];
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Create a new structure. Most common use is a CoA→reporting mapping
|
|
136
|
+
* structure; also used for custom statement + schedule structures.
|
|
137
|
+
*/
|
|
138
|
+
async createStructure(graphId, body) {
|
|
139
|
+
const envelope = await this.callOperation('Create structure', (0, sdk_gen_1.opCreateStructure)({ path: { graph_id: graphId }, body }));
|
|
140
|
+
return envelope.result;
|
|
194
141
|
}
|
|
195
142
|
// ── 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
|
-
*/
|
|
143
|
+
/** List active CoA→reporting mapping structures. */
|
|
226
144
|
async listMappings(graphId) {
|
|
227
|
-
const
|
|
228
|
-
|
|
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
|
-
}));
|
|
145
|
+
const list = await this.gqlQuery(graphId, graphql_1.ListLedgerMappingsDocument, undefined, 'List mappings', (data) => data.mappings);
|
|
146
|
+
return list?.structures ?? [];
|
|
242
147
|
}
|
|
243
|
-
/**
|
|
244
|
-
|
|
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;
|
|
148
|
+
/** Get a mapping structure with all its associations. */
|
|
149
|
+
async getMapping(graphId, mappingId) {
|
|
150
|
+
return this.gqlQuery(graphId, graphql_1.GetLedgerMappingDocument, { mappingId }, 'Get mapping', (data) => data.mapping);
|
|
254
151
|
}
|
|
255
|
-
/**
|
|
256
|
-
* Get mapping coverage — how many CoA elements are mapped.
|
|
257
|
-
*/
|
|
152
|
+
/** Mapping coverage stats — how many CoA elements are mapped. */
|
|
258
153
|
async getMappingCoverage(graphId, mappingId) {
|
|
259
|
-
|
|
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
|
-
};
|
|
154
|
+
return this.gqlQuery(graphId, graphql_1.GetLedgerMappingCoverageDocument, { mappingId }, 'Get mapping coverage', (data) => data.mappingCoverage);
|
|
275
155
|
}
|
|
276
|
-
/**
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
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
|
-
}
|
|
156
|
+
/** Create a manual mapping association between two elements. */
|
|
157
|
+
async createMappingAssociation(graphId, body) {
|
|
158
|
+
const envelope = await this.callOperation('Create mapping association', (0, sdk_gen_1.opCreateMappingAssociation)({ path: { graph_id: graphId }, body }));
|
|
159
|
+
return (envelope.result ?? {});
|
|
291
160
|
}
|
|
292
|
-
/**
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
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
|
-
}
|
|
161
|
+
/** Delete a mapping association. */
|
|
162
|
+
async deleteMappingAssociation(graphId, body) {
|
|
163
|
+
const envelope = await this.callOperation('Delete mapping association', (0, sdk_gen_1.opDeleteMappingAssociation)({ path: { graph_id: graphId }, body }));
|
|
164
|
+
return (envelope.result ?? { deleted: true });
|
|
302
165
|
}
|
|
303
166
|
/**
|
|
304
|
-
* Trigger AI
|
|
305
|
-
*
|
|
167
|
+
* Trigger the AI MappingAgent. Returns the operation id — async; the
|
|
168
|
+
* agent runs in the background. Consumers can subscribe to progress
|
|
169
|
+
* via `/v1/operations/{operationId}/stream`.
|
|
306
170
|
*/
|
|
307
|
-
async
|
|
308
|
-
const
|
|
309
|
-
|
|
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
|
-
};
|
|
171
|
+
async autoMapElements(graphId, body) {
|
|
172
|
+
const envelope = await this.callOperation('Auto-map elements', (0, sdk_gen_1.opAutoMapElements)({ path: { graph_id: graphId }, body }));
|
|
173
|
+
return { operationId: envelope.operationId, status: envelope.status };
|
|
318
174
|
}
|
|
319
175
|
// ── Schedules ──────────────────────────────────────────────────────
|
|
320
|
-
/**
|
|
321
|
-
|
|
322
|
-
|
|
176
|
+
/** List all schedule structures with metadata. */
|
|
177
|
+
async listSchedules(graphId) {
|
|
178
|
+
const list = await this.gqlQuery(graphId, graphql_1.ListLedgerSchedulesDocument, undefined, 'List schedules', (data) => data.schedules);
|
|
179
|
+
return list?.schedules ?? [];
|
|
180
|
+
}
|
|
181
|
+
/** Schedule facts optionally filtered by period window. */
|
|
182
|
+
async getScheduleFacts(graphId, structureId, options) {
|
|
183
|
+
const facts = await this.gqlQuery(graphId, graphql_1.GetLedgerScheduleFactsDocument, {
|
|
184
|
+
structureId,
|
|
185
|
+
periodStart: options?.periodStart ?? null,
|
|
186
|
+
periodEnd: options?.periodEnd ?? null,
|
|
187
|
+
}, 'Get schedule facts', (data) => data.scheduleFacts);
|
|
188
|
+
return facts?.facts ?? [];
|
|
189
|
+
}
|
|
190
|
+
/** Create a new schedule with pre-generated monthly facts. */
|
|
323
191
|
async createSchedule(graphId, options) {
|
|
324
192
|
const body = {
|
|
325
193
|
name: options.name,
|
|
@@ -344,159 +212,86 @@ class LedgerClient {
|
|
|
344
212
|
}
|
|
345
213
|
: undefined,
|
|
346
214
|
};
|
|
347
|
-
const
|
|
348
|
-
|
|
349
|
-
body,
|
|
350
|
-
});
|
|
351
|
-
if (response.error) {
|
|
352
|
-
throw new Error(`Create schedule failed: ${JSON.stringify(response.error)}`);
|
|
353
|
-
}
|
|
354
|
-
const data = response.data;
|
|
215
|
+
const envelope = await this.callOperation('Create schedule', (0, sdk_gen_1.opCreateSchedule)({ path: { graph_id: graphId }, body }));
|
|
216
|
+
const raw = envelope.result;
|
|
355
217
|
return {
|
|
356
|
-
structureId:
|
|
357
|
-
name:
|
|
358
|
-
taxonomyId:
|
|
359
|
-
totalPeriods:
|
|
360
|
-
totalFacts:
|
|
218
|
+
structureId: raw.structure_id,
|
|
219
|
+
name: raw.name,
|
|
220
|
+
taxonomyId: raw.taxonomy_id,
|
|
221
|
+
totalPeriods: raw.total_periods,
|
|
222
|
+
totalFacts: raw.total_facts,
|
|
361
223
|
};
|
|
362
224
|
}
|
|
363
|
-
/**
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
|
|
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;
|
|
225
|
+
/** Truncate a schedule — end it early at `newEndDate`. */
|
|
226
|
+
async truncateSchedule(graphId, structureId, options) {
|
|
227
|
+
const body = {
|
|
228
|
+
structure_id: structureId,
|
|
229
|
+
new_end_date: options.newEndDate,
|
|
230
|
+
reason: options.reason,
|
|
231
|
+
};
|
|
232
|
+
const envelope = await this.callOperation('Truncate schedule', (0, sdk_gen_1.opTruncateSchedule)({ path: { graph_id: graphId }, body }));
|
|
233
|
+
const raw = envelope.result;
|
|
419
234
|
return {
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
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,
|
|
235
|
+
structureId: raw.structure_id,
|
|
236
|
+
newEndDate: raw.new_end_date,
|
|
237
|
+
factsDeleted: raw.facts_deleted,
|
|
238
|
+
reason: raw.reason,
|
|
432
239
|
};
|
|
433
240
|
}
|
|
241
|
+
// ── Period close ────────────────────────────────────────────────────
|
|
242
|
+
/** Close status for all schedules in a fiscal period. */
|
|
243
|
+
async getPeriodCloseStatus(graphId, periodStart, periodEnd) {
|
|
244
|
+
return this.gqlQuery(graphId, graphql_1.GetLedgerPeriodCloseStatusDocument, { periodStart, periodEnd }, 'Get period close status', (data) => data.periodCloseStatus);
|
|
245
|
+
}
|
|
246
|
+
/** All draft entries in a period, fully expanded for review pre-close. */
|
|
247
|
+
async listPeriodDrafts(graphId, period) {
|
|
248
|
+
return this.gqlQuery(graphId, graphql_1.GetLedgerPeriodDraftsDocument, { period }, 'List period drafts', (data) => data.periodDrafts);
|
|
249
|
+
}
|
|
434
250
|
/**
|
|
435
|
-
* Idempotently create (or refresh) a draft closing entry from a
|
|
436
|
-
*
|
|
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
|
|
251
|
+
* Idempotently create (or refresh) a draft closing entry from a
|
|
252
|
+
* schedule for a period. See `ClosingEntryOutcome` for semantics.
|
|
443
253
|
*/
|
|
444
254
|
async createClosingEntry(graphId, structureId, postingDate, periodStart, periodEnd, memo) {
|
|
445
255
|
const body = {
|
|
256
|
+
structure_id: structureId,
|
|
446
257
|
posting_date: postingDate,
|
|
447
258
|
period_start: periodStart,
|
|
448
259
|
period_end: periodEnd,
|
|
449
260
|
memo: memo ?? undefined,
|
|
450
261
|
};
|
|
451
|
-
const
|
|
452
|
-
|
|
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);
|
|
262
|
+
const envelope = await this.callOperation('Create closing entry', (0, sdk_gen_1.opCreateClosingEntry)({ path: { graph_id: graphId }, body }));
|
|
263
|
+
return rawToClosingEntry(envelope.result);
|
|
460
264
|
}
|
|
461
|
-
// ── Closing Book ─────────────────────────────────────────────────────
|
|
462
265
|
/**
|
|
463
|
-
*
|
|
464
|
-
*
|
|
465
|
-
* and period close grouped into categories.
|
|
266
|
+
* Create a manual balanced closing entry (not tied to a schedule).
|
|
267
|
+
* Used for disposals, adjustments, and one-off closing events.
|
|
466
268
|
*/
|
|
269
|
+
async createManualClosingEntry(graphId, options) {
|
|
270
|
+
const body = {
|
|
271
|
+
posting_date: options.postingDate,
|
|
272
|
+
memo: options.memo,
|
|
273
|
+
entry_type: options.entryType,
|
|
274
|
+
line_items: options.lineItems.map((li) => ({
|
|
275
|
+
element_id: li.elementId,
|
|
276
|
+
debit_amount: li.debitAmount ?? 0,
|
|
277
|
+
credit_amount: li.creditAmount ?? 0,
|
|
278
|
+
description: li.description ?? null,
|
|
279
|
+
})),
|
|
280
|
+
};
|
|
281
|
+
const envelope = await this.callOperation('Create manual closing entry', (0, sdk_gen_1.opCreateManualClosingEntry)({ path: { graph_id: graphId }, body }));
|
|
282
|
+
return rawToClosingEntry(envelope.result);
|
|
283
|
+
}
|
|
284
|
+
// ── Closing book ───────────────────────────────────────────────────
|
|
285
|
+
/** Grouped closing book structures for the close-screen sidebar. */
|
|
467
286
|
async getClosingBookStructures(graphId) {
|
|
468
|
-
|
|
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;
|
|
287
|
+
return this.gqlQuery(graphId, graphql_1.GetLedgerClosingBookStructuresDocument, undefined, 'Get closing book structures', (data) => data.closingBookStructures);
|
|
475
288
|
}
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
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;
|
|
289
|
+
// ── Fiscal Calendar ────────────────────────────────────────────────
|
|
290
|
+
/** Current fiscal calendar state — pointers, gap, closeable status. */
|
|
291
|
+
async getFiscalCalendar(graphId) {
|
|
292
|
+
return this.gqlQuery(graphId, graphql_1.GetLedgerFiscalCalendarDocument, undefined, 'Get fiscal calendar', (data) => data.fiscalCalendar);
|
|
493
293
|
}
|
|
494
|
-
|
|
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
|
-
*/
|
|
294
|
+
/** One-time ledger initialization — seed fiscal calendar + periods. */
|
|
500
295
|
async initializeLedger(graphId, options) {
|
|
501
296
|
const body = {
|
|
502
297
|
closed_through: options?.closedThrough ?? null,
|
|
@@ -505,202 +300,88 @@ class LedgerClient {
|
|
|
505
300
|
auto_seed_schedules: options?.autoSeedSchedules,
|
|
506
301
|
note: options?.note ?? null,
|
|
507
302
|
};
|
|
508
|
-
const
|
|
509
|
-
|
|
510
|
-
body,
|
|
511
|
-
});
|
|
512
|
-
if (response.error) {
|
|
513
|
-
throw new Error(`Initialize ledger failed: ${JSON.stringify(response.error)}`);
|
|
514
|
-
}
|
|
515
|
-
const data = response.data;
|
|
303
|
+
const envelope = await this.callOperation('Initialize ledger', (0, sdk_gen_1.opInitializeLedger)({ path: { graph_id: graphId }, body }));
|
|
304
|
+
const raw = envelope.result;
|
|
516
305
|
return {
|
|
517
|
-
fiscalCalendar:
|
|
518
|
-
periodsCreated:
|
|
519
|
-
warnings:
|
|
306
|
+
fiscalCalendar: rawFiscalCalendarToCamel(raw.fiscal_calendar),
|
|
307
|
+
periodsCreated: raw.periods_created ?? 0,
|
|
308
|
+
warnings: raw.warnings ?? [],
|
|
520
309
|
};
|
|
521
310
|
}
|
|
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
|
-
*/
|
|
311
|
+
/** Set the user-controlled close target (YYYY-MM). */
|
|
538
312
|
async setCloseTarget(graphId, period, note) {
|
|
539
|
-
const body = {
|
|
540
|
-
|
|
541
|
-
|
|
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);
|
|
313
|
+
const body = { period, note: note ?? null };
|
|
314
|
+
const envelope = await this.callOperation('Set close target', (0, sdk_gen_1.opSetCloseTarget)({ path: { graph_id: graphId }, body }));
|
|
315
|
+
return rawFiscalCalendarToCamel(envelope.result);
|
|
551
316
|
}
|
|
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
|
-
*/
|
|
317
|
+
/** Close a fiscal period — the final commit action. */
|
|
559
318
|
async closePeriod(graphId, period, options) {
|
|
560
319
|
const body = {
|
|
320
|
+
period,
|
|
561
321
|
note: options?.note ?? null,
|
|
562
322
|
allow_stale_sync: options?.allowStaleSync,
|
|
563
323
|
};
|
|
564
|
-
const
|
|
565
|
-
|
|
566
|
-
body,
|
|
567
|
-
});
|
|
568
|
-
if (response.error) {
|
|
569
|
-
throw new Error(`Close period failed: ${JSON.stringify(response.error)}`);
|
|
570
|
-
}
|
|
571
|
-
const data = response.data;
|
|
324
|
+
const envelope = await this.callOperation('Close period', (0, sdk_gen_1.opClosePeriod)({ path: { graph_id: graphId }, body }));
|
|
325
|
+
const raw = envelope.result;
|
|
572
326
|
return {
|
|
573
|
-
period:
|
|
574
|
-
entriesPosted:
|
|
575
|
-
targetAutoAdvanced:
|
|
576
|
-
fiscalCalendar:
|
|
327
|
+
period: raw.period,
|
|
328
|
+
entriesPosted: raw.entries_posted ?? 0,
|
|
329
|
+
targetAutoAdvanced: raw.target_auto_advanced ?? false,
|
|
330
|
+
fiscalCalendar: rawFiscalCalendarToCamel(raw.fiscal_calendar),
|
|
577
331
|
};
|
|
578
332
|
}
|
|
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
|
-
*/
|
|
333
|
+
/** Reopen a closed fiscal period. Requires a reason for the audit log. */
|
|
584
334
|
async reopenPeriod(graphId, period, reason, note) {
|
|
585
335
|
const body = {
|
|
336
|
+
period,
|
|
586
337
|
reason,
|
|
587
338
|
note: note ?? null,
|
|
588
339
|
};
|
|
589
|
-
const
|
|
590
|
-
|
|
591
|
-
body,
|
|
592
|
-
});
|
|
593
|
-
if (response.error) {
|
|
594
|
-
throw new Error(`Reopen period failed: ${JSON.stringify(response.error)}`);
|
|
595
|
-
}
|
|
596
|
-
return toFiscalCalendarState(response.data);
|
|
340
|
+
const envelope = await this.callOperation('Reopen period', (0, sdk_gen_1.opReopenPeriod)({ path: { graph_id: graphId }, body }));
|
|
341
|
+
return rawFiscalCalendarToCamel(envelope.result);
|
|
597
342
|
}
|
|
343
|
+
// Reports, statements, and publish lists live on `ReportClient`.
|
|
344
|
+
// ── Internal helpers ────────────────────────────────────────────────
|
|
598
345
|
/**
|
|
599
|
-
*
|
|
600
|
-
*
|
|
601
|
-
*
|
|
602
|
-
* Pure read — call repeatedly without side effects.
|
|
346
|
+
* Run a typed GraphQL query against the per-graph endpoint and
|
|
347
|
+
* translate ClientError into a readable facade error.
|
|
603
348
|
*/
|
|
604
|
-
async
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
349
|
+
async gqlQuery(graphId, document, variables, label, pick) {
|
|
350
|
+
try {
|
|
351
|
+
const client = this.gql.get(graphId);
|
|
352
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
353
|
+
const raw = client.request;
|
|
354
|
+
// graphql-request's overloads don't cleanly resolve for generic
|
|
355
|
+
// helpers wrapping codegen's `Exact<>` var types, so we bypass
|
|
356
|
+
// the typed overload with a narrow cast of `request` itself.
|
|
357
|
+
const data = (await raw.call(client, document, variables));
|
|
358
|
+
return pick(data);
|
|
610
359
|
}
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
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)}`);
|
|
360
|
+
catch (err) {
|
|
361
|
+
if (err instanceof graphql_request_1.ClientError) {
|
|
362
|
+
throw new Error(`${label} failed: ${JSON.stringify(err.response.errors ?? err.message)}`);
|
|
363
|
+
}
|
|
364
|
+
throw err;
|
|
662
365
|
}
|
|
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
366
|
}
|
|
671
367
|
/**
|
|
672
|
-
*
|
|
673
|
-
*
|
|
674
|
-
* one-off closing events.
|
|
675
|
-
*
|
|
676
|
-
* Line items must sum to balanced debits/credits. Rejects entries
|
|
677
|
-
* targeting an already-closed period.
|
|
368
|
+
* Await an SDK-generated `opXxx(...)` call, throw a readable error on
|
|
369
|
+
* non-2xx, and return the `OperationEnvelope` on success.
|
|
678
370
|
*/
|
|
679
|
-
async
|
|
680
|
-
const
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
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)}`);
|
|
371
|
+
async callOperation(label, call) {
|
|
372
|
+
const response = await call;
|
|
373
|
+
if (response.error !== undefined) {
|
|
374
|
+
throw new Error(`${label} failed: ${JSON.stringify(response.error)}`);
|
|
375
|
+
}
|
|
376
|
+
if (response.data === undefined) {
|
|
377
|
+
throw new Error(`${label} failed: empty response`);
|
|
697
378
|
}
|
|
698
|
-
return
|
|
379
|
+
return response.data;
|
|
699
380
|
}
|
|
700
381
|
}
|
|
701
382
|
exports.LedgerClient = LedgerClient;
|
|
702
|
-
// ──
|
|
703
|
-
function
|
|
383
|
+
// ── Module-private conversion helpers ─────────────────────────────────
|
|
384
|
+
function rawToClosingEntry(data) {
|
|
704
385
|
return {
|
|
705
386
|
outcome: data.outcome,
|
|
706
387
|
entryId: data.entry_id ?? null,
|
|
@@ -713,20 +394,20 @@ function toClosingEntry(data) {
|
|
|
713
394
|
reason: data.reason ?? null,
|
|
714
395
|
};
|
|
715
396
|
}
|
|
716
|
-
function
|
|
397
|
+
function rawFiscalCalendarToCamel(raw) {
|
|
717
398
|
return {
|
|
718
|
-
graphId:
|
|
719
|
-
fiscalYearStartMonth:
|
|
720
|
-
closedThrough:
|
|
721
|
-
closeTarget:
|
|
722
|
-
gapPeriods:
|
|
723
|
-
catchUpSequence:
|
|
724
|
-
closeableNow:
|
|
725
|
-
blockers:
|
|
726
|
-
lastCloseAt:
|
|
727
|
-
initializedAt:
|
|
728
|
-
lastSyncAt:
|
|
729
|
-
periods: (
|
|
399
|
+
graphId: raw.graph_id,
|
|
400
|
+
fiscalYearStartMonth: raw.fiscal_year_start_month,
|
|
401
|
+
closedThrough: raw.closed_through ?? null,
|
|
402
|
+
closeTarget: raw.close_target ?? null,
|
|
403
|
+
gapPeriods: raw.gap_periods ?? 0,
|
|
404
|
+
catchUpSequence: raw.catch_up_sequence ?? [],
|
|
405
|
+
closeableNow: raw.closeable_now ?? false,
|
|
406
|
+
blockers: raw.blockers ?? [],
|
|
407
|
+
lastCloseAt: raw.last_close_at ?? null,
|
|
408
|
+
initializedAt: raw.initialized_at ?? null,
|
|
409
|
+
lastSyncAt: raw.last_sync_at ?? null,
|
|
410
|
+
periods: (raw.periods ?? []).map((p) => ({
|
|
730
411
|
name: p.name,
|
|
731
412
|
startDate: p.start_date,
|
|
732
413
|
endDate: p.end_date,
|