@robosystems/client 0.3.0 → 0.3.2

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 (164) hide show
  1. package/{extensions → artifacts}/InvestorClient.d.ts +7 -0
  2. package/{extensions → artifacts}/InvestorClient.js +0 -1
  3. package/{extensions → artifacts}/InvestorClient.ts +8 -1
  4. package/{extensions → artifacts}/LedgerClient.d.ts +175 -2
  5. package/{extensions → artifacts}/LedgerClient.js +301 -2
  6. package/{extensions → artifacts}/LedgerClient.ts +652 -2
  7. package/{extensions → artifacts}/config.d.ts +29 -10
  8. package/{extensions → artifacts}/config.js +11 -11
  9. package/{extensions → artifacts}/config.ts +36 -16
  10. package/artifacts/graphql/client.d.ts +82 -0
  11. package/artifacts/graphql/client.js +148 -0
  12. package/artifacts/graphql/client.ts +189 -0
  13. package/{extensions → artifacts}/hooks.js +6 -6
  14. package/{extensions → artifacts}/hooks.ts +7 -7
  15. package/{extensions → artifacts}/index.d.ts +34 -18
  16. package/{extensions → artifacts}/index.js +47 -44
  17. package/{extensions → artifacts}/index.ts +72 -52
  18. package/index.d.ts +2 -2
  19. package/index.js +2 -2
  20. package/index.ts +2 -2
  21. package/package.json +38 -8
  22. package/sdk/index.d.ts +2 -2
  23. package/sdk/index.js +27 -9
  24. package/sdk/index.ts +2 -2
  25. package/sdk/sdk.gen.d.ts +275 -274
  26. package/sdk/sdk.gen.js +469 -314
  27. package/sdk/sdk.gen.ts +465 -311
  28. package/sdk/types.gen.d.ts +2940 -466
  29. package/sdk/types.gen.ts +3053 -474
  30. package/sdk.gen.d.ts +275 -274
  31. package/sdk.gen.js +469 -314
  32. package/sdk.gen.ts +465 -311
  33. package/types.gen.d.ts +2940 -466
  34. package/types.gen.ts +3053 -474
  35. package/extensions/ReportClient.d.ts +0 -113
  36. package/extensions/ReportClient.js +0 -191
  37. package/extensions/ReportClient.ts +0 -426
  38. package/extensions/graphql/client.d.ts +0 -46
  39. package/extensions/graphql/client.js +0 -75
  40. package/extensions/graphql/client.ts +0 -82
  41. /package/{extensions → artifacts}/AgentClient.d.ts +0 -0
  42. /package/{extensions → artifacts}/AgentClient.js +0 -0
  43. /package/{extensions → artifacts}/AgentClient.ts +0 -0
  44. /package/{extensions → artifacts}/OperationClient.d.ts +0 -0
  45. /package/{extensions → artifacts}/OperationClient.js +0 -0
  46. /package/{extensions → artifacts}/OperationClient.ts +0 -0
  47. /package/{extensions → artifacts}/QueryClient.d.ts +0 -0
  48. /package/{extensions → artifacts}/QueryClient.js +0 -0
  49. /package/{extensions → artifacts}/QueryClient.ts +0 -0
  50. /package/{extensions → artifacts}/SSEClient.d.ts +0 -0
  51. /package/{extensions → artifacts}/SSEClient.js +0 -0
  52. /package/{extensions → artifacts}/SSEClient.ts +0 -0
  53. /package/{extensions → artifacts}/graphql/generated/graphql.d.ts +0 -0
  54. /package/{extensions → artifacts}/graphql/generated/graphql.js +0 -0
  55. /package/{extensions → artifacts}/graphql/generated/graphql.ts +0 -0
  56. /package/{extensions → artifacts}/graphql/queries/investor/holdings.d.ts +0 -0
  57. /package/{extensions → artifacts}/graphql/queries/investor/holdings.js +0 -0
  58. /package/{extensions → artifacts}/graphql/queries/investor/holdings.ts +0 -0
  59. /package/{extensions → artifacts}/graphql/queries/investor/portfolio.d.ts +0 -0
  60. /package/{extensions → artifacts}/graphql/queries/investor/portfolio.js +0 -0
  61. /package/{extensions → artifacts}/graphql/queries/investor/portfolio.ts +0 -0
  62. /package/{extensions → artifacts}/graphql/queries/investor/portfolios.d.ts +0 -0
  63. /package/{extensions → artifacts}/graphql/queries/investor/portfolios.js +0 -0
  64. /package/{extensions → artifacts}/graphql/queries/investor/portfolios.ts +0 -0
  65. /package/{extensions → artifacts}/graphql/queries/investor/position.d.ts +0 -0
  66. /package/{extensions → artifacts}/graphql/queries/investor/position.js +0 -0
  67. /package/{extensions → artifacts}/graphql/queries/investor/position.ts +0 -0
  68. /package/{extensions → artifacts}/graphql/queries/investor/positions.d.ts +0 -0
  69. /package/{extensions → artifacts}/graphql/queries/investor/positions.js +0 -0
  70. /package/{extensions → artifacts}/graphql/queries/investor/positions.ts +0 -0
  71. /package/{extensions → artifacts}/graphql/queries/investor/securities.d.ts +0 -0
  72. /package/{extensions → artifacts}/graphql/queries/investor/securities.js +0 -0
  73. /package/{extensions → artifacts}/graphql/queries/investor/securities.ts +0 -0
  74. /package/{extensions → artifacts}/graphql/queries/investor/security.d.ts +0 -0
  75. /package/{extensions → artifacts}/graphql/queries/investor/security.js +0 -0
  76. /package/{extensions → artifacts}/graphql/queries/investor/security.ts +0 -0
  77. /package/{extensions → artifacts}/graphql/queries/ledger/accountRollups.d.ts +0 -0
  78. /package/{extensions → artifacts}/graphql/queries/ledger/accountRollups.js +0 -0
  79. /package/{extensions → artifacts}/graphql/queries/ledger/accountRollups.ts +0 -0
  80. /package/{extensions → artifacts}/graphql/queries/ledger/accountTree.d.ts +0 -0
  81. /package/{extensions → artifacts}/graphql/queries/ledger/accountTree.js +0 -0
  82. /package/{extensions → artifacts}/graphql/queries/ledger/accountTree.ts +0 -0
  83. /package/{extensions → artifacts}/graphql/queries/ledger/accounts.d.ts +0 -0
  84. /package/{extensions → artifacts}/graphql/queries/ledger/accounts.js +0 -0
  85. /package/{extensions → artifacts}/graphql/queries/ledger/accounts.ts +0 -0
  86. /package/{extensions → artifacts}/graphql/queries/ledger/closingBookStructures.d.ts +0 -0
  87. /package/{extensions → artifacts}/graphql/queries/ledger/closingBookStructures.js +0 -0
  88. /package/{extensions → artifacts}/graphql/queries/ledger/closingBookStructures.ts +0 -0
  89. /package/{extensions → artifacts}/graphql/queries/ledger/elements.d.ts +0 -0
  90. /package/{extensions → artifacts}/graphql/queries/ledger/elements.js +0 -0
  91. /package/{extensions → artifacts}/graphql/queries/ledger/elements.ts +0 -0
  92. /package/{extensions → artifacts}/graphql/queries/ledger/entities.d.ts +0 -0
  93. /package/{extensions → artifacts}/graphql/queries/ledger/entities.js +0 -0
  94. /package/{extensions → artifacts}/graphql/queries/ledger/entities.ts +0 -0
  95. /package/{extensions → artifacts}/graphql/queries/ledger/entity.d.ts +0 -0
  96. /package/{extensions → artifacts}/graphql/queries/ledger/entity.js +0 -0
  97. /package/{extensions → artifacts}/graphql/queries/ledger/entity.ts +0 -0
  98. /package/{extensions → artifacts}/graphql/queries/ledger/fiscalCalendar.d.ts +0 -0
  99. /package/{extensions → artifacts}/graphql/queries/ledger/fiscalCalendar.js +0 -0
  100. /package/{extensions → artifacts}/graphql/queries/ledger/fiscalCalendar.ts +0 -0
  101. /package/{extensions → artifacts}/graphql/queries/ledger/mappedTrialBalance.d.ts +0 -0
  102. /package/{extensions → artifacts}/graphql/queries/ledger/mappedTrialBalance.js +0 -0
  103. /package/{extensions → artifacts}/graphql/queries/ledger/mappedTrialBalance.ts +0 -0
  104. /package/{extensions → artifacts}/graphql/queries/ledger/mapping.d.ts +0 -0
  105. /package/{extensions → artifacts}/graphql/queries/ledger/mapping.js +0 -0
  106. /package/{extensions → artifacts}/graphql/queries/ledger/mapping.ts +0 -0
  107. /package/{extensions → artifacts}/graphql/queries/ledger/mappingCoverage.d.ts +0 -0
  108. /package/{extensions → artifacts}/graphql/queries/ledger/mappingCoverage.js +0 -0
  109. /package/{extensions → artifacts}/graphql/queries/ledger/mappingCoverage.ts +0 -0
  110. /package/{extensions → artifacts}/graphql/queries/ledger/mappings.d.ts +0 -0
  111. /package/{extensions → artifacts}/graphql/queries/ledger/mappings.js +0 -0
  112. /package/{extensions → artifacts}/graphql/queries/ledger/mappings.ts +0 -0
  113. /package/{extensions → artifacts}/graphql/queries/ledger/periodCloseStatus.d.ts +0 -0
  114. /package/{extensions → artifacts}/graphql/queries/ledger/periodCloseStatus.js +0 -0
  115. /package/{extensions → artifacts}/graphql/queries/ledger/periodCloseStatus.ts +0 -0
  116. /package/{extensions → artifacts}/graphql/queries/ledger/periodDrafts.d.ts +0 -0
  117. /package/{extensions → artifacts}/graphql/queries/ledger/periodDrafts.js +0 -0
  118. /package/{extensions → artifacts}/graphql/queries/ledger/periodDrafts.ts +0 -0
  119. /package/{extensions → artifacts}/graphql/queries/ledger/publishList.d.ts +0 -0
  120. /package/{extensions → artifacts}/graphql/queries/ledger/publishList.js +0 -0
  121. /package/{extensions → artifacts}/graphql/queries/ledger/publishList.ts +0 -0
  122. /package/{extensions → artifacts}/graphql/queries/ledger/publishLists.d.ts +0 -0
  123. /package/{extensions → artifacts}/graphql/queries/ledger/publishLists.js +0 -0
  124. /package/{extensions → artifacts}/graphql/queries/ledger/publishLists.ts +0 -0
  125. /package/{extensions → artifacts}/graphql/queries/ledger/report.d.ts +0 -0
  126. /package/{extensions → artifacts}/graphql/queries/ledger/report.js +0 -0
  127. /package/{extensions → artifacts}/graphql/queries/ledger/report.ts +0 -0
  128. /package/{extensions → artifacts}/graphql/queries/ledger/reportingTaxonomy.d.ts +0 -0
  129. /package/{extensions → artifacts}/graphql/queries/ledger/reportingTaxonomy.js +0 -0
  130. /package/{extensions → artifacts}/graphql/queries/ledger/reportingTaxonomy.ts +0 -0
  131. /package/{extensions → artifacts}/graphql/queries/ledger/reports.d.ts +0 -0
  132. /package/{extensions → artifacts}/graphql/queries/ledger/reports.js +0 -0
  133. /package/{extensions → artifacts}/graphql/queries/ledger/reports.ts +0 -0
  134. /package/{extensions → artifacts}/graphql/queries/ledger/scheduleFacts.d.ts +0 -0
  135. /package/{extensions → artifacts}/graphql/queries/ledger/scheduleFacts.js +0 -0
  136. /package/{extensions → artifacts}/graphql/queries/ledger/scheduleFacts.ts +0 -0
  137. /package/{extensions → artifacts}/graphql/queries/ledger/schedules.d.ts +0 -0
  138. /package/{extensions → artifacts}/graphql/queries/ledger/schedules.js +0 -0
  139. /package/{extensions → artifacts}/graphql/queries/ledger/schedules.ts +0 -0
  140. /package/{extensions → artifacts}/graphql/queries/ledger/statement.d.ts +0 -0
  141. /package/{extensions → artifacts}/graphql/queries/ledger/statement.js +0 -0
  142. /package/{extensions → artifacts}/graphql/queries/ledger/statement.ts +0 -0
  143. /package/{extensions → artifacts}/graphql/queries/ledger/structures.d.ts +0 -0
  144. /package/{extensions → artifacts}/graphql/queries/ledger/structures.js +0 -0
  145. /package/{extensions → artifacts}/graphql/queries/ledger/structures.ts +0 -0
  146. /package/{extensions → artifacts}/graphql/queries/ledger/summary.d.ts +0 -0
  147. /package/{extensions → artifacts}/graphql/queries/ledger/summary.js +0 -0
  148. /package/{extensions → artifacts}/graphql/queries/ledger/summary.ts +0 -0
  149. /package/{extensions → artifacts}/graphql/queries/ledger/taxonomies.d.ts +0 -0
  150. /package/{extensions → artifacts}/graphql/queries/ledger/taxonomies.js +0 -0
  151. /package/{extensions → artifacts}/graphql/queries/ledger/taxonomies.ts +0 -0
  152. /package/{extensions → artifacts}/graphql/queries/ledger/transaction.d.ts +0 -0
  153. /package/{extensions → artifacts}/graphql/queries/ledger/transaction.js +0 -0
  154. /package/{extensions → artifacts}/graphql/queries/ledger/transaction.ts +0 -0
  155. /package/{extensions → artifacts}/graphql/queries/ledger/transactions.d.ts +0 -0
  156. /package/{extensions → artifacts}/graphql/queries/ledger/transactions.js +0 -0
  157. /package/{extensions → artifacts}/graphql/queries/ledger/transactions.ts +0 -0
  158. /package/{extensions → artifacts}/graphql/queries/ledger/trialBalance.d.ts +0 -0
  159. /package/{extensions → artifacts}/graphql/queries/ledger/trialBalance.js +0 -0
  160. /package/{extensions → artifacts}/graphql/queries/ledger/trialBalance.ts +0 -0
  161. /package/{extensions → artifacts}/graphql/queries/ledger/unmappedElements.d.ts +0 -0
  162. /package/{extensions → artifacts}/graphql/queries/ledger/unmappedElements.js +0 -0
  163. /package/{extensions → artifacts}/graphql/queries/ledger/unmappedElements.ts +0 -0
  164. /package/{extensions → artifacts}/hooks.d.ts +0 -0
@@ -1,426 +0,0 @@
1
- 'use client'
2
-
3
- /**
4
- * Report Client for RoboSystems API
5
- *
6
- * High-level facade for the report + publish-list surface:
7
- * create/list/view/regenerate/share/delete reports, render financial
8
- * statements, and manage publish lists (distribution lists for shared
9
- * reports). Reports consume ledger data (mappings, trial balance) as
10
- * inputs — use `LedgerClient` for those concerns.
11
- *
12
- * **Transport split:**
13
- * - **Reads** (listReports, getReport, getStatement, listPublishLists,
14
- * getPublishList) go through GraphQL at
15
- * `/extensions/{graph_id}/graphql`.
16
- * - **Writes** (createReport, regenerateReport, deleteReport, shareReport,
17
- * and the publish-list CRUD) go through named operations at
18
- * `/extensions/roboledger/{graph_id}/operations/{operation_name}`.
19
- *
20
- * Every write returns an `OperationEnvelope`; this facade unwraps
21
- * `envelope.result` for sync commands, or returns `{ operationId, status }`
22
- * for async dispatches (createReport, regenerateReport, shareReport).
23
- */
24
-
25
- import type { TypedDocumentNode } from '@graphql-typed-document-node/core'
26
- import { ClientError } from 'graphql-request'
27
- import {
28
- opAddPublishListMembers,
29
- opCreatePublishList,
30
- opCreateReport,
31
- opDeletePublishList,
32
- opDeleteReport,
33
- opRegenerateReport,
34
- opRemovePublishListMember,
35
- opShareReport,
36
- opUpdatePublishList,
37
- } from '../sdk.gen'
38
- import type {
39
- AddPublishListMembersOperation,
40
- CreatePublishListRequest,
41
- CreateReportRequest,
42
- OperationEnvelope,
43
- UpdatePublishListOperation,
44
- } from '../types.gen'
45
- import { GraphQLClientCache } from './graphql/client'
46
- import {
47
- GetLedgerPublishListDocument,
48
- GetLedgerReportDocument,
49
- GetLedgerStatementDocument,
50
- ListLedgerPublishListsDocument,
51
- ListLedgerReportsDocument,
52
- type GetLedgerPublishListQuery,
53
- type GetLedgerReportQuery,
54
- type GetLedgerStatementQuery,
55
- type ListLedgerPublishListsQuery,
56
- type ListLedgerReportsQuery,
57
- } from './graphql/generated/graphql'
58
-
59
- // ── Types derived from GraphQL codegen ──────────────────────────────────
60
-
61
- export type Report = NonNullable<GetLedgerReportQuery['report']>
62
- export type ReportListItem = NonNullable<ListLedgerReportsQuery['reports']>['reports'][number]
63
- export type StatementData = NonNullable<GetLedgerStatementQuery['statement']>
64
- export type StatementPeriod = StatementData['periods'][number]
65
- export type StatementRow = StatementData['rows'][number]
66
-
67
- export type PublishList = NonNullable<
68
- ListLedgerPublishListsQuery['publishLists']
69
- >['publishLists'][number]
70
- export type PublishListDetail = NonNullable<GetLedgerPublishListQuery['publishList']>
71
- export type PublishListMember = PublishListDetail['members'][number]
72
-
73
- // ── Caller-facing option interfaces ─────────────────────────────────────
74
-
75
- export interface PeriodSpecInput {
76
- start: string
77
- end: string
78
- label: string
79
- }
80
-
81
- export interface CreateReportOptions {
82
- name: string
83
- mappingId: string
84
- periodStart: string
85
- periodEnd: string
86
- taxonomyId?: string
87
- periodType?: string
88
- comparative?: boolean
89
- /** When set, overrides periodStart/periodEnd/comparative with N explicit periods. */
90
- periods?: PeriodSpecInput[]
91
- }
92
-
93
- /**
94
- * Envelope around a report operation. `status === "completed"` means the
95
- * backend produced the report synchronously — `result` contains the
96
- * freshly-created report shape (same fields as `ReportListItem`), so
97
- * consumers can read `result?.id` immediately. For pending/failed
98
- * dispatches, `result` is null and consumers should subscribe to
99
- * `/v1/operations/{operationId}/stream` for progress.
100
- *
101
- * The loose `{ id; name; ... }` shape here intentionally mirrors the
102
- * GraphQL `report` field without pulling in every nullable child relation
103
- * — `create_report` and `regenerate_report` return a freshly-generated
104
- * row, not a fully-resolved GraphQL projection.
105
- */
106
- export interface ReportOperationAck {
107
- operationId: string
108
- status: OperationEnvelope['status']
109
- /**
110
- * Synchronous command result. Populated for `status === "completed"`
111
- * dispatches where the backend produced the report inline.
112
- */
113
- result: Record<string, unknown> | null
114
- }
115
-
116
- // ── Client ──────────────────────────────────────────────────────────────
117
-
118
- interface ReportClientConfig {
119
- baseUrl: string
120
- credentials?: 'include' | 'same-origin' | 'omit'
121
- headers?: Record<string, string>
122
- token?: string
123
- }
124
-
125
- export class ReportClient {
126
- private config: ReportClientConfig
127
- private gql: GraphQLClientCache
128
-
129
- constructor(config: ReportClientConfig) {
130
- this.config = config
131
- this.gql = new GraphQLClientCache(config)
132
- }
133
-
134
- // ── Reports ─────────────────────────────────────────────────────────
135
-
136
- /**
137
- * Kick off report creation (async). Use the returned `operationId` to
138
- * subscribe to progress via SSE, then call `get()` once finished.
139
- */
140
- async create(graphId: string, options: CreateReportOptions): Promise<ReportOperationAck> {
141
- const body: CreateReportRequest = {
142
- name: options.name,
143
- mapping_id: options.mappingId,
144
- period_start: options.periodStart,
145
- period_end: options.periodEnd,
146
- taxonomy_id: options.taxonomyId ?? 'tax_usgaap_reporting',
147
- period_type: options.periodType ?? 'quarterly',
148
- comparative: options.comparative ?? true,
149
- }
150
- if (options.periods && options.periods.length > 0) {
151
- body.periods = options.periods
152
- }
153
- const envelope = await this.callOperation(
154
- 'Create report',
155
- opCreateReport({ path: { graph_id: graphId }, body })
156
- )
157
- return {
158
- operationId: envelope.operationId,
159
- status: envelope.status,
160
- result: (envelope.result as Record<string, unknown> | null) ?? null,
161
- }
162
- }
163
-
164
- /** List all reports for a graph (includes received shared reports). */
165
- async list(graphId: string): Promise<ReportListItem[]> {
166
- const list = await this.gqlQuery(
167
- graphId,
168
- ListLedgerReportsDocument,
169
- undefined,
170
- 'List reports',
171
- (data) => data.reports
172
- )
173
- return list?.reports ?? []
174
- }
175
-
176
- /** Get a single report with its period list + available structures. */
177
- async get(graphId: string, reportId: string): Promise<Report | null> {
178
- return this.gqlQuery(
179
- graphId,
180
- GetLedgerReportDocument,
181
- { reportId },
182
- 'Get report',
183
- (data) => data.report
184
- )
185
- }
186
-
187
- /**
188
- * Render a financial statement — facts viewed through a structure.
189
- *
190
- * @param structureType - income_statement, balance_sheet, cash_flow_statement
191
- */
192
- async statement(
193
- graphId: string,
194
- reportId: string,
195
- structureType: string
196
- ): Promise<StatementData | null> {
197
- return this.gqlQuery(
198
- graphId,
199
- GetLedgerStatementDocument,
200
- { reportId, structureType },
201
- 'Get statement',
202
- (data) => data.statement
203
- )
204
- }
205
-
206
- /**
207
- * Regenerate an existing report (async). Returns an operation id;
208
- * subscribe via SSE for progress.
209
- */
210
- async regenerate(
211
- graphId: string,
212
- reportId: string,
213
- periodStart?: string,
214
- periodEnd?: string
215
- ): Promise<ReportOperationAck> {
216
- const envelope = await this.callOperation(
217
- 'Regenerate report',
218
- opRegenerateReport({
219
- path: { graph_id: graphId },
220
- body: {
221
- report_id: reportId,
222
- period_start: periodStart,
223
- period_end: periodEnd,
224
- } as Parameters<typeof opRegenerateReport>[0]['body'],
225
- })
226
- )
227
- return {
228
- operationId: envelope.operationId,
229
- status: envelope.status,
230
- result: (envelope.result as Record<string, unknown> | null) ?? null,
231
- }
232
- }
233
-
234
- /** Delete a report and its generated facts. */
235
- async delete(graphId: string, reportId: string): Promise<void> {
236
- await this.callOperation(
237
- 'Delete report',
238
- opDeleteReport({
239
- path: { graph_id: graphId },
240
- body: { report_id: reportId },
241
- })
242
- )
243
- }
244
-
245
- /**
246
- * Share a published report to every member of a publish list (async).
247
- * Each target graph receives a snapshot copy of the report's facts.
248
- */
249
- async share(
250
- graphId: string,
251
- reportId: string,
252
- publishListId: string
253
- ): Promise<ReportOperationAck> {
254
- const envelope = await this.callOperation(
255
- 'Share report',
256
- opShareReport({
257
- path: { graph_id: graphId },
258
- body: {
259
- report_id: reportId,
260
- publish_list_id: publishListId,
261
- } as Parameters<typeof opShareReport>[0]['body'],
262
- })
263
- )
264
- return {
265
- operationId: envelope.operationId,
266
- status: envelope.status,
267
- result: (envelope.result as Record<string, unknown> | null) ?? null,
268
- }
269
- }
270
-
271
- /** Check if a report was received via sharing (vs locally created). */
272
- isSharedReport(report: Report): boolean {
273
- return report.sourceGraphId !== null
274
- }
275
-
276
- // ── Publish Lists ────────────────────────────────────────────────────
277
-
278
- /** List publish lists with pagination. */
279
- async listPublishLists(
280
- graphId: string,
281
- options?: { limit?: number; offset?: number }
282
- ): Promise<PublishList[]> {
283
- const list = await this.gqlQuery(
284
- graphId,
285
- ListLedgerPublishListsDocument,
286
- {
287
- limit: options?.limit ?? 100,
288
- offset: options?.offset ?? 0,
289
- },
290
- 'List publish lists',
291
- (data) => data.publishLists
292
- )
293
- return list?.publishLists ?? []
294
- }
295
-
296
- /** Create a new publish list. */
297
- async createPublishList(
298
- graphId: string,
299
- name: string,
300
- description?: string
301
- ): Promise<Record<string, unknown>> {
302
- const body: CreatePublishListRequest = {
303
- name,
304
- description: description ?? null,
305
- }
306
- const envelope = await this.callOperation(
307
- 'Create publish list',
308
- opCreatePublishList({ path: { graph_id: graphId }, body })
309
- )
310
- return (envelope.result ?? {}) as Record<string, unknown>
311
- }
312
-
313
- /** Get a single publish list with its full member list. */
314
- async getPublishList(graphId: string, listId: string): Promise<PublishListDetail | null> {
315
- return this.gqlQuery(
316
- graphId,
317
- GetLedgerPublishListDocument,
318
- { listId },
319
- 'Get publish list',
320
- (data) => data.publishList
321
- )
322
- }
323
-
324
- /** Update a publish list's name or description. */
325
- async updatePublishList(
326
- graphId: string,
327
- listId: string,
328
- updates: { name?: string; description?: string | null }
329
- ): Promise<Record<string, unknown>> {
330
- const envelope = await this.callOperation(
331
- 'Update publish list',
332
- opUpdatePublishList({
333
- path: { graph_id: graphId },
334
- body: {
335
- list_id: listId,
336
- name: updates.name,
337
- description: updates.description ?? null,
338
- } as UpdatePublishListOperation,
339
- })
340
- )
341
- return (envelope.result ?? {}) as Record<string, unknown>
342
- }
343
-
344
- /** Delete a publish list. */
345
- async deletePublishList(graphId: string, listId: string): Promise<void> {
346
- await this.callOperation(
347
- 'Delete publish list',
348
- opDeletePublishList({
349
- path: { graph_id: graphId },
350
- body: { list_id: listId },
351
- })
352
- )
353
- }
354
-
355
- /** Add target graphs as members of a publish list. */
356
- async addMembers(
357
- graphId: string,
358
- listId: string,
359
- targetGraphIds: string[]
360
- ): Promise<Record<string, unknown>> {
361
- const envelope = await this.callOperation(
362
- 'Add publish list members',
363
- opAddPublishListMembers({
364
- path: { graph_id: graphId },
365
- body: {
366
- list_id: listId,
367
- target_graph_ids: targetGraphIds,
368
- } as AddPublishListMembersOperation,
369
- })
370
- )
371
- return (envelope.result ?? {}) as Record<string, unknown>
372
- }
373
-
374
- /** Remove a single member from a publish list. */
375
- async removeMember(
376
- graphId: string,
377
- listId: string,
378
- memberId: string
379
- ): Promise<{ deleted: boolean }> {
380
- const envelope = await this.callOperation(
381
- 'Remove publish list member',
382
- opRemovePublishListMember({
383
- path: { graph_id: graphId },
384
- body: { list_id: listId, member_id: memberId },
385
- })
386
- )
387
- return (envelope.result ?? { deleted: true }) as { deleted: boolean }
388
- }
389
-
390
- // ── Internal helpers ────────────────────────────────────────────────
391
-
392
- private async gqlQuery<TData, TVars extends object, TResult>(
393
- graphId: string,
394
- document: TypedDocumentNode<TData, TVars>,
395
- variables: TVars | undefined,
396
- label: string,
397
- pick: (data: TData) => TResult
398
- ): Promise<TResult> {
399
- try {
400
- const client = this.gql.get(graphId)
401
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
402
- const raw = client.request as (doc: unknown, vars?: unknown) => Promise<any>
403
- const data = (await raw.call(client, document, variables)) as TData
404
- return pick(data)
405
- } catch (err) {
406
- if (err instanceof ClientError) {
407
- throw new Error(`${label} failed: ${JSON.stringify(err.response.errors ?? err.message)}`)
408
- }
409
- throw err
410
- }
411
- }
412
-
413
- private async callOperation(
414
- label: string,
415
- call: Promise<{ data?: OperationEnvelope; error?: unknown }>
416
- ): Promise<OperationEnvelope> {
417
- const response = await call
418
- if (response.error !== undefined) {
419
- throw new Error(`${label} failed: ${JSON.stringify(response.error)}`)
420
- }
421
- if (response.data === undefined) {
422
- throw new Error(`${label} failed: empty response`)
423
- }
424
- return response.data
425
- }
426
- }
@@ -1,46 +0,0 @@
1
- /**
2
- * GraphQL client factory used internally by the facade clients.
3
- *
4
- * This is an implementation detail — consumers never interact with it
5
- * directly. They call methods on LedgerClient / InvestorClient / etc.,
6
- * which use this to execute GraphQL queries against
7
- * `/extensions/{graph_id}/graphql`.
8
- *
9
- * **Graph scoping.** The GraphQL endpoint is mounted per-graph at
10
- * `/extensions/{graph_id}/graphql`. Resolvers read the graph from the URL
11
- * path parameter — never from GraphQL variables. Every facade method
12
- * takes a `graphId` and resolves the correct per-graph client via
13
- * `getGraphQLClient(graphId)`, which caches one `GraphQLClient` instance
14
- * per graph to avoid rebuilding headers + URLs on every call.
15
- *
16
- * We pick graphql-request (tiny, no React, no caching) because the facade
17
- * doesn't need the hook ergonomics that urql/Apollo provide. Type safety
18
- * comes from GraphQL Code Generator, which produces typed DocumentNodes
19
- * from the query files in sdk-extensions/graphql/queries/.
20
- */
21
- import { GraphQLClient } from 'graphql-request';
22
- export interface GraphQLClientConfig {
23
- baseUrl: string;
24
- token?: string;
25
- headers?: Record<string, string>;
26
- credentials?: 'include' | 'same-origin' | 'omit';
27
- }
28
- /**
29
- * Build a new GraphQL client for the given graph. Prefer
30
- * `GraphQLClientCache.get(graphId)` in facade code — this is the raw
31
- * factory and bypasses the cache.
32
- */
33
- export declare function createGraphQLClient(config: GraphQLClientConfig, graphId: string): GraphQLClient;
34
- /**
35
- * Per-graph cache of GraphQL clients. Facade clients own one instance of
36
- * this and call `.get(graphId)` on every GraphQL method — cheap after the
37
- * first call per graph.
38
- */
39
- export declare class GraphQLClientCache {
40
- private config;
41
- private clients;
42
- constructor(config: GraphQLClientConfig);
43
- get(graphId: string): GraphQLClient;
44
- /** Drop all cached clients. Useful after a token rotation. */
45
- clear(): void;
46
- }
@@ -1,75 +0,0 @@
1
- 'use client';
2
- "use strict";
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.GraphQLClientCache = void 0;
5
- exports.createGraphQLClient = createGraphQLClient;
6
- /**
7
- * GraphQL client factory used internally by the facade clients.
8
- *
9
- * This is an implementation detail — consumers never interact with it
10
- * directly. They call methods on LedgerClient / InvestorClient / etc.,
11
- * which use this to execute GraphQL queries against
12
- * `/extensions/{graph_id}/graphql`.
13
- *
14
- * **Graph scoping.** The GraphQL endpoint is mounted per-graph at
15
- * `/extensions/{graph_id}/graphql`. Resolvers read the graph from the URL
16
- * path parameter — never from GraphQL variables. Every facade method
17
- * takes a `graphId` and resolves the correct per-graph client via
18
- * `getGraphQLClient(graphId)`, which caches one `GraphQLClient` instance
19
- * per graph to avoid rebuilding headers + URLs on every call.
20
- *
21
- * We pick graphql-request (tiny, no React, no caching) because the facade
22
- * doesn't need the hook ergonomics that urql/Apollo provide. Type safety
23
- * comes from GraphQL Code Generator, which produces typed DocumentNodes
24
- * from the query files in sdk-extensions/graphql/queries/.
25
- */
26
- const graphql_request_1 = require("graphql-request");
27
- /**
28
- * Build a new GraphQL client for the given graph. Prefer
29
- * `GraphQLClientCache.get(graphId)` in facade code — this is the raw
30
- * factory and bypasses the cache.
31
- */
32
- function createGraphQLClient(config, graphId) {
33
- if (!graphId) {
34
- throw new Error('createGraphQLClient requires a non-empty graphId');
35
- }
36
- const url = `${config.baseUrl.replace(/\/$/, '')}/extensions/${graphId}/graphql`;
37
- const headers = {
38
- ...(config.headers ?? {}),
39
- };
40
- if (config.token) {
41
- // The backend accepts both Authorization: Bearer and X-API-Key. Match
42
- // the existing facade convention of sending the token as X-API-Key,
43
- // which is what the local dev workflow uses.
44
- headers['X-API-Key'] = config.token;
45
- }
46
- return new graphql_request_1.GraphQLClient(url, {
47
- headers,
48
- credentials: config.credentials,
49
- });
50
- }
51
- /**
52
- * Per-graph cache of GraphQL clients. Facade clients own one instance of
53
- * this and call `.get(graphId)` on every GraphQL method — cheap after the
54
- * first call per graph.
55
- */
56
- class GraphQLClientCache {
57
- constructor(config) {
58
- this.config = config;
59
- this.clients = new Map();
60
- }
61
- get(graphId) {
62
- const existing = this.clients.get(graphId);
63
- if (existing !== undefined) {
64
- return existing;
65
- }
66
- const client = createGraphQLClient(this.config, graphId);
67
- this.clients.set(graphId, client);
68
- return client;
69
- }
70
- /** Drop all cached clients. Useful after a token rotation. */
71
- clear() {
72
- this.clients.clear();
73
- }
74
- }
75
- exports.GraphQLClientCache = GraphQLClientCache;
@@ -1,82 +0,0 @@
1
- 'use client'
2
-
3
- /**
4
- * GraphQL client factory used internally by the facade clients.
5
- *
6
- * This is an implementation detail — consumers never interact with it
7
- * directly. They call methods on LedgerClient / InvestorClient / etc.,
8
- * which use this to execute GraphQL queries against
9
- * `/extensions/{graph_id}/graphql`.
10
- *
11
- * **Graph scoping.** The GraphQL endpoint is mounted per-graph at
12
- * `/extensions/{graph_id}/graphql`. Resolvers read the graph from the URL
13
- * path parameter — never from GraphQL variables. Every facade method
14
- * takes a `graphId` and resolves the correct per-graph client via
15
- * `getGraphQLClient(graphId)`, which caches one `GraphQLClient` instance
16
- * per graph to avoid rebuilding headers + URLs on every call.
17
- *
18
- * We pick graphql-request (tiny, no React, no caching) because the facade
19
- * doesn't need the hook ergonomics that urql/Apollo provide. Type safety
20
- * comes from GraphQL Code Generator, which produces typed DocumentNodes
21
- * from the query files in sdk-extensions/graphql/queries/.
22
- */
23
-
24
- import { GraphQLClient } from 'graphql-request'
25
-
26
- export interface GraphQLClientConfig {
27
- baseUrl: string
28
- token?: string
29
- headers?: Record<string, string>
30
- credentials?: 'include' | 'same-origin' | 'omit'
31
- }
32
-
33
- /**
34
- * Build a new GraphQL client for the given graph. Prefer
35
- * `GraphQLClientCache.get(graphId)` in facade code — this is the raw
36
- * factory and bypasses the cache.
37
- */
38
- export function createGraphQLClient(config: GraphQLClientConfig, graphId: string): GraphQLClient {
39
- if (!graphId) {
40
- throw new Error('createGraphQLClient requires a non-empty graphId')
41
- }
42
- const url = `${config.baseUrl.replace(/\/$/, '')}/extensions/${graphId}/graphql`
43
- const headers: Record<string, string> = {
44
- ...(config.headers ?? {}),
45
- }
46
- if (config.token) {
47
- // The backend accepts both Authorization: Bearer and X-API-Key. Match
48
- // the existing facade convention of sending the token as X-API-Key,
49
- // which is what the local dev workflow uses.
50
- headers['X-API-Key'] = config.token
51
- }
52
- return new GraphQLClient(url, {
53
- headers,
54
- credentials: config.credentials,
55
- })
56
- }
57
-
58
- /**
59
- * Per-graph cache of GraphQL clients. Facade clients own one instance of
60
- * this and call `.get(graphId)` on every GraphQL method — cheap after the
61
- * first call per graph.
62
- */
63
- export class GraphQLClientCache {
64
- private clients = new Map<string, GraphQLClient>()
65
-
66
- constructor(private config: GraphQLClientConfig) {}
67
-
68
- get(graphId: string): GraphQLClient {
69
- const existing = this.clients.get(graphId)
70
- if (existing !== undefined) {
71
- return existing
72
- }
73
- const client = createGraphQLClient(this.config, graphId)
74
- this.clients.set(graphId, client)
75
- return client
76
- }
77
-
78
- /** Drop all cached clients. Useful after a token rotation. */
79
- clear(): void {
80
- this.clients.clear()
81
- }
82
- }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes