@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,84 +1,13 @@
1
- export interface Report {
2
- id: string;
3
- name: string;
4
- taxonomyId: string;
5
- generationStatus: string;
6
- periodType: string;
7
- periodStart: string | null;
8
- periodEnd: string | null;
9
- comparative: boolean;
10
- mappingId: string | null;
11
- aiGenerated: boolean;
12
- createdAt: string;
13
- lastGenerated: string | null;
14
- structures: Structure[];
15
- /** Entity name (source company for shared reports, own entity for native) */
16
- entityName: string | null;
17
- /** Non-null when this report was shared from another graph */
18
- sourceGraphId: string | null;
19
- sourceReportId: string | null;
20
- sharedAt: string | null;
21
- }
22
- import type { Structure } from './LedgerClient';
23
- export type { Structure } from './LedgerClient';
24
- export interface StatementPeriod {
25
- start: string;
26
- end: string;
27
- label: string;
28
- }
29
- export interface StatementRow {
30
- elementId: string;
31
- elementQname: string;
32
- elementName: string;
33
- classification: string;
34
- values: (number | null)[];
35
- isSubtotal: boolean;
36
- depth: number;
37
- }
38
- export interface StatementData {
39
- reportId: string;
40
- structureId: string;
41
- structureName: string;
42
- structureType: string;
43
- periods: StatementPeriod[];
44
- rows: StatementRow[];
45
- validation: {
46
- passed: boolean;
47
- checks: string[];
48
- failures: string[];
49
- warnings: string[];
50
- } | null;
51
- unmappedCount: number;
52
- }
53
- export interface ShareResult {
54
- reportId: string;
55
- results: Array<{
56
- targetGraphId: string;
57
- status: 'shared' | 'error';
58
- error: string | null;
59
- factCount: number;
60
- }>;
61
- }
62
- export interface PublishList {
63
- id: string;
64
- name: string;
65
- description: string | null;
66
- memberCount: number;
67
- createdBy: string;
68
- createdAt: string;
69
- updatedAt: string;
70
- }
71
- export interface PublishListDetail extends PublishList {
72
- members: PublishListMember[];
73
- }
74
- export interface PublishListMember {
75
- id: string;
76
- targetGraphId: string;
77
- targetGraphName: string | null;
78
- targetOrgName: string | null;
79
- addedBy: string;
80
- addedAt: string;
81
- }
1
+ import type { OperationEnvelope } from '../types.gen';
2
+ import { type GetLedgerPublishListQuery, type GetLedgerReportQuery, type GetLedgerStatementQuery, type ListLedgerPublishListsQuery, type ListLedgerReportsQuery } from './graphql/generated/graphql';
3
+ export type Report = NonNullable<GetLedgerReportQuery['report']>;
4
+ export type ReportListItem = NonNullable<ListLedgerReportsQuery['reports']>['reports'][number];
5
+ export type StatementData = NonNullable<GetLedgerStatementQuery['statement']>;
6
+ export type StatementPeriod = StatementData['periods'][number];
7
+ export type StatementRow = StatementData['rows'][number];
8
+ export type PublishList = NonNullable<ListLedgerPublishListsQuery['publishLists']>['publishLists'][number];
9
+ export type PublishListDetail = NonNullable<GetLedgerPublishListQuery['publishList']>;
10
+ export type PublishListMember = PublishListDetail['members'][number];
82
11
  export interface PeriodSpecInput {
83
12
  start: string;
84
13
  end: string;
@@ -95,57 +24,90 @@ export interface CreateReportOptions {
95
24
  /** When set, overrides periodStart/periodEnd/comparative with N explicit periods. */
96
25
  periods?: PeriodSpecInput[];
97
26
  }
98
- export declare class ReportClient {
99
- private config;
100
- constructor(config: {
101
- baseUrl: string;
102
- credentials?: 'include' | 'same-origin' | 'omit';
103
- headers?: Record<string, string>;
104
- token?: string;
105
- });
27
+ /**
28
+ * Envelope around a report operation. `status === "completed"` means the
29
+ * backend produced the report synchronously — `result` contains the
30
+ * freshly-created report shape (same fields as `ReportListItem`), so
31
+ * consumers can read `result?.id` immediately. For pending/failed
32
+ * dispatches, `result` is null and consumers should subscribe to
33
+ * `/v1/operations/{operationId}/stream` for progress.
34
+ *
35
+ * The loose `{ id; name; ... }` shape here intentionally mirrors the
36
+ * GraphQL `report` field without pulling in every nullable child relation
37
+ * — `create_report` and `regenerate_report` return a freshly-generated
38
+ * row, not a fully-resolved GraphQL projection.
39
+ */
40
+ export interface ReportOperationAck {
41
+ operationId: string;
42
+ status: OperationEnvelope['status'];
106
43
  /**
107
- * Create a report generates facts for all structures in the taxonomy.
44
+ * Synchronous command result. Populated for `status === "completed"`
45
+ * dispatches where the backend produced the report inline.
108
46
  */
109
- create(graphId: string, options: CreateReportOptions): Promise<Report>;
110
- /**
111
- * List all reports for a graph (includes received shared reports).
112
- */
113
- list(graphId: string): Promise<Report[]>;
47
+ result: Record<string, unknown> | null;
48
+ }
49
+ interface ReportClientConfig {
50
+ baseUrl: string;
51
+ credentials?: 'include' | 'same-origin' | 'omit';
52
+ headers?: Record<string, string>;
53
+ token?: string;
54
+ }
55
+ export declare class ReportClient {
56
+ private config;
57
+ private gql;
58
+ constructor(config: ReportClientConfig);
114
59
  /**
115
- * Get a report with its available structures.
60
+ * Kick off report creation (async). Use the returned `operationId` to
61
+ * subscribe to progress via SSE, then call `get()` once finished.
116
62
  */
117
- get(graphId: string, reportId: string): Promise<Report>;
63
+ create(graphId: string, options: CreateReportOptions): Promise<ReportOperationAck>;
64
+ /** List all reports for a graph (includes received shared reports). */
65
+ list(graphId: string): Promise<ReportListItem[]>;
66
+ /** Get a single report with its period list + available structures. */
67
+ get(graphId: string, reportId: string): Promise<Report | null>;
118
68
  /**
119
69
  * Render a financial statement — facts viewed through a structure.
120
70
  *
121
71
  * @param structureType - income_statement, balance_sheet, cash_flow_statement
122
72
  */
123
- statement(graphId: string, reportId: string, structureType: string): Promise<StatementData>;
73
+ statement(graphId: string, reportId: string, structureType: string): Promise<StatementData | null>;
124
74
  /**
125
- * Regenerate a report with new period dates.
126
- */
127
- regenerate(graphId: string, reportId: string, periodStart: string, periodEnd: string): Promise<Report>;
128
- /**
129
- * Delete a report and its generated facts.
75
+ * Regenerate an existing report (async). Returns an operation id;
76
+ * subscribe via SSE for progress.
130
77
  */
78
+ regenerate(graphId: string, reportId: string, periodStart?: string, periodEnd?: string): Promise<ReportOperationAck>;
79
+ /** Delete a report and its generated facts. */
131
80
  delete(graphId: string, reportId: string): Promise<void>;
132
81
  /**
133
- * Share a published report to all members of a publish list (snapshot copy).
82
+ * Share a published report to every member of a publish list (async).
83
+ * Each target graph receives a snapshot copy of the report's facts.
134
84
  */
135
- share(graphId: string, reportId: string, publishListId: string): Promise<ShareResult>;
85
+ share(graphId: string, reportId: string, publishListId: string): Promise<ReportOperationAck>;
136
86
  /** Check if a report was received via sharing (vs locally created). */
137
87
  isSharedReport(report: Report): boolean;
138
- listPublishLists(graphId: string): Promise<PublishList[]>;
139
- createPublishList(graphId: string, name: string, description?: string): Promise<PublishList>;
140
- getPublishList(graphId: string, listId: string): Promise<PublishListDetail>;
88
+ /** List publish lists with pagination. */
89
+ listPublishLists(graphId: string, options?: {
90
+ limit?: number;
91
+ offset?: number;
92
+ }): Promise<PublishList[]>;
93
+ /** Create a new publish list. */
94
+ createPublishList(graphId: string, name: string, description?: string): Promise<Record<string, unknown>>;
95
+ /** Get a single publish list with its full member list. */
96
+ getPublishList(graphId: string, listId: string): Promise<PublishListDetail | null>;
97
+ /** Update a publish list's name or description. */
141
98
  updatePublishList(graphId: string, listId: string, updates: {
142
99
  name?: string;
143
- description?: string;
144
- }): Promise<PublishList>;
100
+ description?: string | null;
101
+ }): Promise<Record<string, unknown>>;
102
+ /** Delete a publish list. */
145
103
  deletePublishList(graphId: string, listId: string): Promise<void>;
146
- addMembers(graphId: string, listId: string, targetGraphIds: string[]): Promise<PublishListMember[]>;
147
- removeMember(graphId: string, listId: string, memberId: string): Promise<void>;
148
- private _toPublishList;
149
- private _toMember;
150
- private _toReport;
104
+ /** Add target graphs as members of a publish list. */
105
+ addMembers(graphId: string, listId: string, targetGraphIds: string[]): Promise<Record<string, unknown>>;
106
+ /** Remove a single member from a publish list. */
107
+ removeMember(graphId: string, listId: string, memberId: string): Promise<{
108
+ deleted: boolean;
109
+ }>;
110
+ private gqlQuery;
111
+ private callOperation;
151
112
  }
113
+ export {};
@@ -2,21 +2,19 @@
2
2
  "use strict";
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.ReportClient = void 0;
5
- /**
6
- * Report Client for RoboSystems API
7
- *
8
- * High-level client for report lifecycle: create, list, view statements,
9
- * regenerate, share, and delete. Reports consume ledger data (mappings,
10
- * trial balance) as inputs — use LedgerClient for those concerns.
11
- */
5
+ const graphql_request_1 = require("graphql-request");
12
6
  const sdk_gen_1 = require("../sdk.gen");
13
- // ── Client ──────────────────────────────────────────────────────────────
7
+ const client_1 = require("./graphql/client");
8
+ const graphql_1 = require("./graphql/generated/graphql");
14
9
  class ReportClient {
15
10
  constructor(config) {
16
11
  this.config = config;
12
+ this.gql = new client_1.GraphQLClientCache(config);
17
13
  }
14
+ // ── Reports ─────────────────────────────────────────────────────────
18
15
  /**
19
- * Create a report generates facts for all structures in the taxonomy.
16
+ * Kick off report creation (async). Use the returned `operationId` to
17
+ * subscribe to progress via SSE, then call `get()` once finished.
20
18
  */
21
19
  async create(graphId, options) {
22
20
  const body = {
@@ -31,39 +29,21 @@ class ReportClient {
31
29
  if (options.periods && options.periods.length > 0) {
32
30
  body.periods = options.periods;
33
31
  }
34
- const response = await (0, sdk_gen_1.createReport)({
35
- path: { graph_id: graphId },
36
- body,
37
- });
38
- if (response.error) {
39
- throw new Error(`Create report failed: ${JSON.stringify(response.error)}`);
40
- }
41
- return this._toReport(response.data);
32
+ const envelope = await this.callOperation('Create report', (0, sdk_gen_1.opCreateReport)({ path: { graph_id: graphId }, body }));
33
+ return {
34
+ operationId: envelope.operationId,
35
+ status: envelope.status,
36
+ result: envelope.result ?? null,
37
+ };
42
38
  }
43
- /**
44
- * List all reports for a graph (includes received shared reports).
45
- */
39
+ /** List all reports for a graph (includes received shared reports). */
46
40
  async list(graphId) {
47
- const response = await (0, sdk_gen_1.listReports)({
48
- path: { graph_id: graphId },
49
- });
50
- if (response.error) {
51
- throw new Error(`List reports failed: ${JSON.stringify(response.error)}`);
52
- }
53
- const data = response.data;
54
- return (data.reports ?? []).map((r) => this._toReport(r));
41
+ const list = await this.gqlQuery(graphId, graphql_1.ListLedgerReportsDocument, undefined, 'List reports', (data) => data.reports);
42
+ return list?.reports ?? [];
55
43
  }
56
- /**
57
- * Get a report with its available structures.
58
- */
44
+ /** Get a single report with its period list + available structures. */
59
45
  async get(graphId, reportId) {
60
- const response = await (0, sdk_gen_1.getReport)({
61
- path: { graph_id: graphId, report_id: reportId },
62
- });
63
- if (response.error) {
64
- throw new Error(`Get report failed: ${JSON.stringify(response.error)}`);
65
- }
66
- return this._toReport(response.data);
46
+ return this.gqlQuery(graphId, graphql_1.GetLedgerReportDocument, { reportId }, 'Get report', (data) => data.report);
67
47
  }
68
48
  /**
69
49
  * Render a financial statement — facts viewed through a structure.
@@ -71,87 +51,50 @@ class ReportClient {
71
51
  * @param structureType - income_statement, balance_sheet, cash_flow_statement
72
52
  */
73
53
  async statement(graphId, reportId, structureType) {
74
- const response = await (0, sdk_gen_1.getStatement)({
75
- path: { graph_id: graphId, report_id: reportId, structure_type: structureType },
76
- });
77
- if (response.error) {
78
- throw new Error(`Get statement failed: ${JSON.stringify(response.error)}`);
79
- }
80
- const data = response.data;
81
- return {
82
- reportId: data.report_id,
83
- structureId: data.structure_id,
84
- structureName: data.structure_name,
85
- structureType: data.structure_type,
86
- periods: (data.periods ?? []).map((p) => ({
87
- start: p.start,
88
- end: p.end,
89
- label: p.label,
90
- })),
91
- rows: (data.rows ?? []).map((r) => ({
92
- elementId: r.element_id,
93
- elementQname: r.element_qname,
94
- elementName: r.element_name,
95
- classification: r.classification,
96
- values: r.values ?? [],
97
- isSubtotal: r.is_subtotal ?? false,
98
- depth: r.depth ?? 0,
99
- })),
100
- validation: data.validation
101
- ? {
102
- passed: data.validation.passed,
103
- checks: data.validation.checks,
104
- failures: data.validation.failures,
105
- warnings: data.validation.warnings,
106
- }
107
- : null,
108
- unmappedCount: data.unmapped_count ?? 0,
109
- };
54
+ return this.gqlQuery(graphId, graphql_1.GetLedgerStatementDocument, { reportId, structureType }, 'Get statement', (data) => data.statement);
110
55
  }
111
56
  /**
112
- * Regenerate a report with new period dates.
57
+ * Regenerate an existing report (async). Returns an operation id;
58
+ * subscribe via SSE for progress.
113
59
  */
114
60
  async regenerate(graphId, reportId, periodStart, periodEnd) {
115
- const response = await (0, sdk_gen_1.regenerateReport)({
116
- path: { graph_id: graphId, report_id: reportId },
117
- body: { period_start: periodStart, period_end: periodEnd },
118
- });
119
- if (response.error) {
120
- throw new Error(`Regenerate report failed: ${JSON.stringify(response.error)}`);
121
- }
122
- return this._toReport(response.data);
61
+ const envelope = await this.callOperation('Regenerate report', (0, sdk_gen_1.opRegenerateReport)({
62
+ path: { graph_id: graphId },
63
+ body: {
64
+ report_id: reportId,
65
+ period_start: periodStart,
66
+ period_end: periodEnd,
67
+ },
68
+ }));
69
+ return {
70
+ operationId: envelope.operationId,
71
+ status: envelope.status,
72
+ result: envelope.result ?? null,
73
+ };
123
74
  }
124
- /**
125
- * Delete a report and its generated facts.
126
- */
75
+ /** Delete a report and its generated facts. */
127
76
  async delete(graphId, reportId) {
128
- const response = await (0, sdk_gen_1.deleteReport)({
129
- path: { graph_id: graphId, report_id: reportId },
130
- });
131
- if (response.error) {
132
- throw new Error(`Delete report failed: ${JSON.stringify(response.error)}`);
133
- }
77
+ await this.callOperation('Delete report', (0, sdk_gen_1.opDeleteReport)({
78
+ path: { graph_id: graphId },
79
+ body: { report_id: reportId },
80
+ }));
134
81
  }
135
82
  /**
136
- * Share a published report to all members of a publish list (snapshot copy).
83
+ * Share a published report to every member of a publish list (async).
84
+ * Each target graph receives a snapshot copy of the report's facts.
137
85
  */
138
86
  async share(graphId, reportId, publishListId) {
139
- const response = await (0, sdk_gen_1.shareReport)({
140
- path: { graph_id: graphId, report_id: reportId },
141
- body: { publish_list_id: publishListId },
142
- });
143
- if (response.error) {
144
- throw new Error(`Share report failed: ${JSON.stringify(response.error)}`);
145
- }
146
- const data = response.data;
87
+ const envelope = await this.callOperation('Share report', (0, sdk_gen_1.opShareReport)({
88
+ path: { graph_id: graphId },
89
+ body: {
90
+ report_id: reportId,
91
+ publish_list_id: publishListId,
92
+ },
93
+ }));
147
94
  return {
148
- reportId: data.report_id,
149
- results: (data.results ?? []).map((r) => ({
150
- targetGraphId: r.target_graph_id,
151
- status: r.status,
152
- error: r.error ?? null,
153
- factCount: r.fact_count ?? 0,
154
- })),
95
+ operationId: envelope.operationId,
96
+ status: envelope.status,
97
+ result: envelope.result ?? null,
155
98
  };
156
99
  }
157
100
  /** Check if a report was received via sharing (vs locally created). */
@@ -159,120 +102,90 @@ class ReportClient {
159
102
  return report.sourceGraphId !== null;
160
103
  }
161
104
  // ── Publish Lists ────────────────────────────────────────────────────
162
- async listPublishLists(graphId) {
163
- const response = await (0, sdk_gen_1.listPublishLists)({
164
- path: { graph_id: graphId },
165
- });
166
- if (response.error) {
167
- throw new Error(`List publish lists failed: ${JSON.stringify(response.error)}`);
168
- }
169
- const data = response.data;
170
- return (data.publish_lists ?? []).map((pl) => this._toPublishList(pl));
171
- }
105
+ /** List publish lists with pagination. */
106
+ async listPublishLists(graphId, options) {
107
+ const list = await this.gqlQuery(graphId, graphql_1.ListLedgerPublishListsDocument, {
108
+ limit: options?.limit ?? 100,
109
+ offset: options?.offset ?? 0,
110
+ }, 'List publish lists', (data) => data.publishLists);
111
+ return list?.publishLists ?? [];
112
+ }
113
+ /** Create a new publish list. */
172
114
  async createPublishList(graphId, name, description) {
173
- const response = await (0, sdk_gen_1.createPublishList)({
174
- path: { graph_id: graphId },
175
- body: { name, description: description ?? null },
176
- });
177
- if (response.error) {
178
- throw new Error(`Create publish list failed: ${JSON.stringify(response.error)}`);
179
- }
180
- return this._toPublishList(response.data);
115
+ const body = {
116
+ name,
117
+ description: description ?? null,
118
+ };
119
+ const envelope = await this.callOperation('Create publish list', (0, sdk_gen_1.opCreatePublishList)({ path: { graph_id: graphId }, body }));
120
+ return (envelope.result ?? {});
181
121
  }
122
+ /** Get a single publish list with its full member list. */
182
123
  async getPublishList(graphId, listId) {
183
- const response = await (0, sdk_gen_1.getPublishList)({
184
- path: { graph_id: graphId, list_id: listId },
185
- });
186
- if (response.error) {
187
- throw new Error(`Get publish list failed: ${JSON.stringify(response.error)}`);
188
- }
189
- const data = response.data;
190
- return {
191
- ...this._toPublishList(data),
192
- members: (data.members ?? []).map((m) => this._toMember(m)),
193
- };
124
+ return this.gqlQuery(graphId, graphql_1.GetLedgerPublishListDocument, { listId }, 'Get publish list', (data) => data.publishList);
194
125
  }
126
+ /** Update a publish list's name or description. */
195
127
  async updatePublishList(graphId, listId, updates) {
196
- const response = await (0, sdk_gen_1.updatePublishList)({
197
- path: { graph_id: graphId, list_id: listId },
198
- body: updates,
199
- });
200
- if (response.error) {
201
- throw new Error(`Update publish list failed: ${JSON.stringify(response.error)}`);
202
- }
203
- return this._toPublishList(response.data);
204
- }
128
+ const envelope = await this.callOperation('Update publish list', (0, sdk_gen_1.opUpdatePublishList)({
129
+ path: { graph_id: graphId },
130
+ body: {
131
+ list_id: listId,
132
+ name: updates.name,
133
+ description: updates.description ?? null,
134
+ },
135
+ }));
136
+ return (envelope.result ?? {});
137
+ }
138
+ /** Delete a publish list. */
205
139
  async deletePublishList(graphId, listId) {
206
- const response = await (0, sdk_gen_1.deletePublishList)({
207
- path: { graph_id: graphId, list_id: listId },
208
- });
209
- if (response.error) {
210
- throw new Error(`Delete publish list failed: ${JSON.stringify(response.error)}`);
211
- }
140
+ await this.callOperation('Delete publish list', (0, sdk_gen_1.opDeletePublishList)({
141
+ path: { graph_id: graphId },
142
+ body: { list_id: listId },
143
+ }));
212
144
  }
145
+ /** Add target graphs as members of a publish list. */
213
146
  async addMembers(graphId, listId, targetGraphIds) {
214
- const response = await (0, sdk_gen_1.addPublishListMembers)({
215
- path: { graph_id: graphId, list_id: listId },
216
- body: { target_graph_ids: targetGraphIds },
217
- });
218
- if (response.error) {
219
- throw new Error(`Add members failed: ${JSON.stringify(response.error)}`);
220
- }
221
- return (response.data ?? []).map((m) => this._toMember(m));
222
- }
147
+ const envelope = await this.callOperation('Add publish list members', (0, sdk_gen_1.opAddPublishListMembers)({
148
+ path: { graph_id: graphId },
149
+ body: {
150
+ list_id: listId,
151
+ target_graph_ids: targetGraphIds,
152
+ },
153
+ }));
154
+ return (envelope.result ?? {});
155
+ }
156
+ /** Remove a single member from a publish list. */
223
157
  async removeMember(graphId, listId, memberId) {
224
- const response = await (0, sdk_gen_1.removePublishListMember)({
225
- path: { graph_id: graphId, list_id: listId, member_id: memberId },
226
- });
227
- if (response.error) {
228
- throw new Error(`Remove member failed: ${JSON.stringify(response.error)}`);
158
+ const envelope = await this.callOperation('Remove publish list member', (0, sdk_gen_1.opRemovePublishListMember)({
159
+ path: { graph_id: graphId },
160
+ body: { list_id: listId, member_id: memberId },
161
+ }));
162
+ return (envelope.result ?? { deleted: true });
163
+ }
164
+ // ── Internal helpers ────────────────────────────────────────────────
165
+ async gqlQuery(graphId, document, variables, label, pick) {
166
+ try {
167
+ const client = this.gql.get(graphId);
168
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
169
+ const raw = client.request;
170
+ const data = (await raw.call(client, document, variables));
171
+ return pick(data);
172
+ }
173
+ catch (err) {
174
+ if (err instanceof graphql_request_1.ClientError) {
175
+ throw new Error(`${label} failed: ${JSON.stringify(err.response.errors ?? err.message)}`);
176
+ }
177
+ throw err;
229
178
  }
230
179
  }
231
- _toPublishList(pl) {
232
- return {
233
- id: pl.id,
234
- name: pl.name,
235
- description: pl.description ?? null,
236
- memberCount: pl.member_count ?? 0,
237
- createdBy: pl.created_by,
238
- createdAt: pl.created_at,
239
- updatedAt: pl.updated_at,
240
- };
241
- }
242
- _toMember(m) {
243
- return {
244
- id: m.id,
245
- targetGraphId: m.target_graph_id,
246
- targetGraphName: m.target_graph_name ?? null,
247
- targetOrgName: m.target_org_name ?? null,
248
- addedBy: m.added_by,
249
- addedAt: m.added_at,
250
- };
251
- }
252
- _toReport(r) {
253
- return {
254
- id: r.id,
255
- name: r.name,
256
- taxonomyId: r.taxonomy_id,
257
- generationStatus: r.generation_status,
258
- periodType: r.period_type,
259
- periodStart: r.period_start ?? null,
260
- periodEnd: r.period_end ?? null,
261
- comparative: r.comparative,
262
- mappingId: r.mapping_id ?? null,
263
- aiGenerated: r.ai_generated ?? false,
264
- createdAt: r.created_at,
265
- lastGenerated: r.last_generated ?? null,
266
- structures: (r.structures ?? []).map((s) => ({
267
- id: s.id,
268
- name: s.name,
269
- structureType: s.structure_type,
270
- })),
271
- entityName: r.entity_name ?? null,
272
- sourceGraphId: r.source_graph_id ?? null,
273
- sourceReportId: r.source_report_id ?? null,
274
- sharedAt: r.shared_at ?? null,
275
- };
180
+ async callOperation(label, call) {
181
+ const response = await call;
182
+ if (response.error !== undefined) {
183
+ throw new Error(`${label} failed: ${JSON.stringify(response.error)}`);
184
+ }
185
+ if (response.data === undefined) {
186
+ throw new Error(`${label} failed: empty response`);
187
+ }
188
+ return response.data;
276
189
  }
277
190
  }
278
191
  exports.ReportClient = ReportClient;