@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.
- package/{extensions → artifacts}/InvestorClient.d.ts +7 -0
- package/{extensions → artifacts}/InvestorClient.js +0 -1
- package/{extensions → artifacts}/InvestorClient.ts +8 -1
- package/{extensions → artifacts}/LedgerClient.d.ts +175 -2
- package/{extensions → artifacts}/LedgerClient.js +301 -2
- package/{extensions → artifacts}/LedgerClient.ts +652 -2
- package/{extensions → artifacts}/config.d.ts +29 -10
- package/{extensions → artifacts}/config.js +11 -11
- package/{extensions → artifacts}/config.ts +36 -16
- package/artifacts/graphql/client.d.ts +82 -0
- package/artifacts/graphql/client.js +148 -0
- package/artifacts/graphql/client.ts +189 -0
- package/{extensions → artifacts}/hooks.js +6 -6
- package/{extensions → artifacts}/hooks.ts +7 -7
- package/{extensions → artifacts}/index.d.ts +34 -18
- package/{extensions → artifacts}/index.js +47 -44
- package/{extensions → artifacts}/index.ts +72 -52
- package/index.d.ts +2 -2
- package/index.js +2 -2
- package/index.ts +2 -2
- package/package.json +38 -8
- package/sdk/index.d.ts +2 -2
- package/sdk/index.js +27 -9
- package/sdk/index.ts +2 -2
- package/sdk/sdk.gen.d.ts +275 -274
- package/sdk/sdk.gen.js +469 -314
- package/sdk/sdk.gen.ts +465 -311
- package/sdk/types.gen.d.ts +2940 -466
- package/sdk/types.gen.ts +3053 -474
- package/sdk.gen.d.ts +275 -274
- package/sdk.gen.js +469 -314
- package/sdk.gen.ts +465 -311
- package/types.gen.d.ts +2940 -466
- package/types.gen.ts +3053 -474
- package/extensions/ReportClient.d.ts +0 -113
- package/extensions/ReportClient.js +0 -191
- package/extensions/ReportClient.ts +0 -426
- package/extensions/graphql/client.d.ts +0 -46
- package/extensions/graphql/client.js +0 -75
- package/extensions/graphql/client.ts +0 -82
- /package/{extensions → artifacts}/AgentClient.d.ts +0 -0
- /package/{extensions → artifacts}/AgentClient.js +0 -0
- /package/{extensions → artifacts}/AgentClient.ts +0 -0
- /package/{extensions → artifacts}/OperationClient.d.ts +0 -0
- /package/{extensions → artifacts}/OperationClient.js +0 -0
- /package/{extensions → artifacts}/OperationClient.ts +0 -0
- /package/{extensions → artifacts}/QueryClient.d.ts +0 -0
- /package/{extensions → artifacts}/QueryClient.js +0 -0
- /package/{extensions → artifacts}/QueryClient.ts +0 -0
- /package/{extensions → artifacts}/SSEClient.d.ts +0 -0
- /package/{extensions → artifacts}/SSEClient.js +0 -0
- /package/{extensions → artifacts}/SSEClient.ts +0 -0
- /package/{extensions → artifacts}/graphql/generated/graphql.d.ts +0 -0
- /package/{extensions → artifacts}/graphql/generated/graphql.js +0 -0
- /package/{extensions → artifacts}/graphql/generated/graphql.ts +0 -0
- /package/{extensions → artifacts}/graphql/queries/investor/holdings.d.ts +0 -0
- /package/{extensions → artifacts}/graphql/queries/investor/holdings.js +0 -0
- /package/{extensions → artifacts}/graphql/queries/investor/holdings.ts +0 -0
- /package/{extensions → artifacts}/graphql/queries/investor/portfolio.d.ts +0 -0
- /package/{extensions → artifacts}/graphql/queries/investor/portfolio.js +0 -0
- /package/{extensions → artifacts}/graphql/queries/investor/portfolio.ts +0 -0
- /package/{extensions → artifacts}/graphql/queries/investor/portfolios.d.ts +0 -0
- /package/{extensions → artifacts}/graphql/queries/investor/portfolios.js +0 -0
- /package/{extensions → artifacts}/graphql/queries/investor/portfolios.ts +0 -0
- /package/{extensions → artifacts}/graphql/queries/investor/position.d.ts +0 -0
- /package/{extensions → artifacts}/graphql/queries/investor/position.js +0 -0
- /package/{extensions → artifacts}/graphql/queries/investor/position.ts +0 -0
- /package/{extensions → artifacts}/graphql/queries/investor/positions.d.ts +0 -0
- /package/{extensions → artifacts}/graphql/queries/investor/positions.js +0 -0
- /package/{extensions → artifacts}/graphql/queries/investor/positions.ts +0 -0
- /package/{extensions → artifacts}/graphql/queries/investor/securities.d.ts +0 -0
- /package/{extensions → artifacts}/graphql/queries/investor/securities.js +0 -0
- /package/{extensions → artifacts}/graphql/queries/investor/securities.ts +0 -0
- /package/{extensions → artifacts}/graphql/queries/investor/security.d.ts +0 -0
- /package/{extensions → artifacts}/graphql/queries/investor/security.js +0 -0
- /package/{extensions → artifacts}/graphql/queries/investor/security.ts +0 -0
- /package/{extensions → artifacts}/graphql/queries/ledger/accountRollups.d.ts +0 -0
- /package/{extensions → artifacts}/graphql/queries/ledger/accountRollups.js +0 -0
- /package/{extensions → artifacts}/graphql/queries/ledger/accountRollups.ts +0 -0
- /package/{extensions → artifacts}/graphql/queries/ledger/accountTree.d.ts +0 -0
- /package/{extensions → artifacts}/graphql/queries/ledger/accountTree.js +0 -0
- /package/{extensions → artifacts}/graphql/queries/ledger/accountTree.ts +0 -0
- /package/{extensions → artifacts}/graphql/queries/ledger/accounts.d.ts +0 -0
- /package/{extensions → artifacts}/graphql/queries/ledger/accounts.js +0 -0
- /package/{extensions → artifacts}/graphql/queries/ledger/accounts.ts +0 -0
- /package/{extensions → artifacts}/graphql/queries/ledger/closingBookStructures.d.ts +0 -0
- /package/{extensions → artifacts}/graphql/queries/ledger/closingBookStructures.js +0 -0
- /package/{extensions → artifacts}/graphql/queries/ledger/closingBookStructures.ts +0 -0
- /package/{extensions → artifacts}/graphql/queries/ledger/elements.d.ts +0 -0
- /package/{extensions → artifacts}/graphql/queries/ledger/elements.js +0 -0
- /package/{extensions → artifacts}/graphql/queries/ledger/elements.ts +0 -0
- /package/{extensions → artifacts}/graphql/queries/ledger/entities.d.ts +0 -0
- /package/{extensions → artifacts}/graphql/queries/ledger/entities.js +0 -0
- /package/{extensions → artifacts}/graphql/queries/ledger/entities.ts +0 -0
- /package/{extensions → artifacts}/graphql/queries/ledger/entity.d.ts +0 -0
- /package/{extensions → artifacts}/graphql/queries/ledger/entity.js +0 -0
- /package/{extensions → artifacts}/graphql/queries/ledger/entity.ts +0 -0
- /package/{extensions → artifacts}/graphql/queries/ledger/fiscalCalendar.d.ts +0 -0
- /package/{extensions → artifacts}/graphql/queries/ledger/fiscalCalendar.js +0 -0
- /package/{extensions → artifacts}/graphql/queries/ledger/fiscalCalendar.ts +0 -0
- /package/{extensions → artifacts}/graphql/queries/ledger/mappedTrialBalance.d.ts +0 -0
- /package/{extensions → artifacts}/graphql/queries/ledger/mappedTrialBalance.js +0 -0
- /package/{extensions → artifacts}/graphql/queries/ledger/mappedTrialBalance.ts +0 -0
- /package/{extensions → artifacts}/graphql/queries/ledger/mapping.d.ts +0 -0
- /package/{extensions → artifacts}/graphql/queries/ledger/mapping.js +0 -0
- /package/{extensions → artifacts}/graphql/queries/ledger/mapping.ts +0 -0
- /package/{extensions → artifacts}/graphql/queries/ledger/mappingCoverage.d.ts +0 -0
- /package/{extensions → artifacts}/graphql/queries/ledger/mappingCoverage.js +0 -0
- /package/{extensions → artifacts}/graphql/queries/ledger/mappingCoverage.ts +0 -0
- /package/{extensions → artifacts}/graphql/queries/ledger/mappings.d.ts +0 -0
- /package/{extensions → artifacts}/graphql/queries/ledger/mappings.js +0 -0
- /package/{extensions → artifacts}/graphql/queries/ledger/mappings.ts +0 -0
- /package/{extensions → artifacts}/graphql/queries/ledger/periodCloseStatus.d.ts +0 -0
- /package/{extensions → artifacts}/graphql/queries/ledger/periodCloseStatus.js +0 -0
- /package/{extensions → artifacts}/graphql/queries/ledger/periodCloseStatus.ts +0 -0
- /package/{extensions → artifacts}/graphql/queries/ledger/periodDrafts.d.ts +0 -0
- /package/{extensions → artifacts}/graphql/queries/ledger/periodDrafts.js +0 -0
- /package/{extensions → artifacts}/graphql/queries/ledger/periodDrafts.ts +0 -0
- /package/{extensions → artifacts}/graphql/queries/ledger/publishList.d.ts +0 -0
- /package/{extensions → artifacts}/graphql/queries/ledger/publishList.js +0 -0
- /package/{extensions → artifacts}/graphql/queries/ledger/publishList.ts +0 -0
- /package/{extensions → artifacts}/graphql/queries/ledger/publishLists.d.ts +0 -0
- /package/{extensions → artifacts}/graphql/queries/ledger/publishLists.js +0 -0
- /package/{extensions → artifacts}/graphql/queries/ledger/publishLists.ts +0 -0
- /package/{extensions → artifacts}/graphql/queries/ledger/report.d.ts +0 -0
- /package/{extensions → artifacts}/graphql/queries/ledger/report.js +0 -0
- /package/{extensions → artifacts}/graphql/queries/ledger/report.ts +0 -0
- /package/{extensions → artifacts}/graphql/queries/ledger/reportingTaxonomy.d.ts +0 -0
- /package/{extensions → artifacts}/graphql/queries/ledger/reportingTaxonomy.js +0 -0
- /package/{extensions → artifacts}/graphql/queries/ledger/reportingTaxonomy.ts +0 -0
- /package/{extensions → artifacts}/graphql/queries/ledger/reports.d.ts +0 -0
- /package/{extensions → artifacts}/graphql/queries/ledger/reports.js +0 -0
- /package/{extensions → artifacts}/graphql/queries/ledger/reports.ts +0 -0
- /package/{extensions → artifacts}/graphql/queries/ledger/scheduleFacts.d.ts +0 -0
- /package/{extensions → artifacts}/graphql/queries/ledger/scheduleFacts.js +0 -0
- /package/{extensions → artifacts}/graphql/queries/ledger/scheduleFacts.ts +0 -0
- /package/{extensions → artifacts}/graphql/queries/ledger/schedules.d.ts +0 -0
- /package/{extensions → artifacts}/graphql/queries/ledger/schedules.js +0 -0
- /package/{extensions → artifacts}/graphql/queries/ledger/schedules.ts +0 -0
- /package/{extensions → artifacts}/graphql/queries/ledger/statement.d.ts +0 -0
- /package/{extensions → artifacts}/graphql/queries/ledger/statement.js +0 -0
- /package/{extensions → artifacts}/graphql/queries/ledger/statement.ts +0 -0
- /package/{extensions → artifacts}/graphql/queries/ledger/structures.d.ts +0 -0
- /package/{extensions → artifacts}/graphql/queries/ledger/structures.js +0 -0
- /package/{extensions → artifacts}/graphql/queries/ledger/structures.ts +0 -0
- /package/{extensions → artifacts}/graphql/queries/ledger/summary.d.ts +0 -0
- /package/{extensions → artifacts}/graphql/queries/ledger/summary.js +0 -0
- /package/{extensions → artifacts}/graphql/queries/ledger/summary.ts +0 -0
- /package/{extensions → artifacts}/graphql/queries/ledger/taxonomies.d.ts +0 -0
- /package/{extensions → artifacts}/graphql/queries/ledger/taxonomies.js +0 -0
- /package/{extensions → artifacts}/graphql/queries/ledger/taxonomies.ts +0 -0
- /package/{extensions → artifacts}/graphql/queries/ledger/transaction.d.ts +0 -0
- /package/{extensions → artifacts}/graphql/queries/ledger/transaction.js +0 -0
- /package/{extensions → artifacts}/graphql/queries/ledger/transaction.ts +0 -0
- /package/{extensions → artifacts}/graphql/queries/ledger/transactions.d.ts +0 -0
- /package/{extensions → artifacts}/graphql/queries/ledger/transactions.js +0 -0
- /package/{extensions → artifacts}/graphql/queries/ledger/transactions.ts +0 -0
- /package/{extensions → artifacts}/graphql/queries/ledger/trialBalance.d.ts +0 -0
- /package/{extensions → artifacts}/graphql/queries/ledger/trialBalance.js +0 -0
- /package/{extensions → artifacts}/graphql/queries/ledger/trialBalance.ts +0 -0
- /package/{extensions → artifacts}/graphql/queries/ledger/unmappedElements.d.ts +0 -0
- /package/{extensions → artifacts}/graphql/queries/ledger/unmappedElements.js +0 -0
- /package/{extensions → artifacts}/graphql/queries/ledger/unmappedElements.ts +0 -0
- /package/{extensions → artifacts}/hooks.d.ts +0 -0
|
@@ -0,0 +1,189 @@
|
|
|
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 clients/graphql/queries/.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
import { GraphQLClient } from 'graphql-request'
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Callback that returns the current auth credential on demand.
|
|
28
|
+
*
|
|
29
|
+
* Use this instead of the static `token` field when the credential
|
|
30
|
+
* can rotate during the lifetime of the client — the primary case
|
|
31
|
+
* is short-lived JWTs that auto-refresh from browser token storage.
|
|
32
|
+
* The provider is invoked on **every** GraphQL request, so the
|
|
33
|
+
* returned value should be cheap to obtain (a localStorage read or
|
|
34
|
+
* an in-memory lookup, not a network call if avoidable).
|
|
35
|
+
*
|
|
36
|
+
* May return `null`/`undefined` to indicate "no credential available
|
|
37
|
+
* right now" — the request will be sent unauthenticated in that
|
|
38
|
+
* case, which lets the caller distinguish auth-expired errors from
|
|
39
|
+
* never-authed errors at the transport layer.
|
|
40
|
+
*/
|
|
41
|
+
export type TokenProvider = () => string | null | undefined | Promise<string | null | undefined>
|
|
42
|
+
|
|
43
|
+
export interface GraphQLClientConfig {
|
|
44
|
+
baseUrl: string
|
|
45
|
+
/**
|
|
46
|
+
* Static credential captured at construction time. Use this when
|
|
47
|
+
* the token won't rotate (e.g. CLI/server flows using a long-lived
|
|
48
|
+
* API key). For JWT flows prefer `tokenProvider` so refreshes are
|
|
49
|
+
* picked up without rebuilding the client.
|
|
50
|
+
*/
|
|
51
|
+
token?: string
|
|
52
|
+
/**
|
|
53
|
+
* Dynamic credential callback, read on every request. Wins over
|
|
54
|
+
* `token` when both are set. See `TokenProvider` for semantics.
|
|
55
|
+
*/
|
|
56
|
+
tokenProvider?: TokenProvider
|
|
57
|
+
headers?: Record<string, string>
|
|
58
|
+
credentials?: 'include' | 'same-origin' | 'omit'
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Apply a credential to an in-progress request's headers, choosing
|
|
63
|
+
* the right header based on token shape:
|
|
64
|
+
*
|
|
65
|
+
* - `rfs…` prefix → `X-API-Key` (long-lived API key, validated
|
|
66
|
+
* against the database's api_keys table).
|
|
67
|
+
* - anything else → `Authorization: Bearer …` (short-lived JWT,
|
|
68
|
+
* validated by JWT middleware).
|
|
69
|
+
*
|
|
70
|
+
* The two credential types are NOT interchangeable at the backend —
|
|
71
|
+
* sending a JWT as `X-API-Key` or an API key as Bearer both 401.
|
|
72
|
+
*/
|
|
73
|
+
function applyAuthHeader(headers: Headers, token: string): void {
|
|
74
|
+
if (token.startsWith('rfs')) {
|
|
75
|
+
headers.set('X-API-Key', token)
|
|
76
|
+
} else {
|
|
77
|
+
headers.set('Authorization', `Bearer ${token}`)
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Build a new GraphQL client for the given graph. Prefer
|
|
83
|
+
* `GraphQLClientCache.get(graphId)` in facade code — this is the raw
|
|
84
|
+
* factory and bypasses the cache.
|
|
85
|
+
*/
|
|
86
|
+
export function createGraphQLClient(config: GraphQLClientConfig, graphId: string): GraphQLClient {
|
|
87
|
+
if (!graphId) {
|
|
88
|
+
throw new Error('createGraphQLClient requires a non-empty graphId')
|
|
89
|
+
}
|
|
90
|
+
const url = `${config.baseUrl.replace(/\/$/, '')}/extensions/${graphId}/graphql`
|
|
91
|
+
const staticHeaders: Record<string, string> = {
|
|
92
|
+
...(config.headers ?? {}),
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// Dynamic-token path: defer credential injection to a per-request
|
|
96
|
+
// middleware so JWT refreshes are picked up without rebuilding or
|
|
97
|
+
// clearing the client. This is the recommended path for browser
|
|
98
|
+
// flows where the token in localStorage rotates every ~30 minutes.
|
|
99
|
+
if (config.tokenProvider) {
|
|
100
|
+
const providerFn = config.tokenProvider
|
|
101
|
+
return new GraphQLClient(url, {
|
|
102
|
+
headers: staticHeaders,
|
|
103
|
+
credentials: config.credentials,
|
|
104
|
+
requestMiddleware: async (request) => {
|
|
105
|
+
let token: string | null | undefined
|
|
106
|
+
try {
|
|
107
|
+
token = await providerFn()
|
|
108
|
+
} catch (err) {
|
|
109
|
+
// A provider failure shouldn't crash the request — fall
|
|
110
|
+
// through unauthenticated so the backend returns a clean
|
|
111
|
+
// 401, which is easier to diagnose than a thrown middleware.
|
|
112
|
+
// We still log a breadcrumb so the failure is visible in
|
|
113
|
+
// devtools/log aggregators instead of silently disappearing;
|
|
114
|
+
// silently swallowing provider bugs in production is worse
|
|
115
|
+
// than the noise.
|
|
116
|
+
|
|
117
|
+
console.warn(
|
|
118
|
+
'[RoboSystems SDK] tokenProvider threw — sending unauthenticated request:',
|
|
119
|
+
err
|
|
120
|
+
)
|
|
121
|
+
token = undefined
|
|
122
|
+
}
|
|
123
|
+
if (!token) {
|
|
124
|
+
return request
|
|
125
|
+
}
|
|
126
|
+
// `request.headers` is a HeadersInit (Headers | string[][] |
|
|
127
|
+
// Record<string, string>), so normalize via Headers before
|
|
128
|
+
// mutating. Spreading it directly loses keys when it's a
|
|
129
|
+
// Headers instance.
|
|
130
|
+
const merged = new Headers(request.headers as HeadersInit | undefined)
|
|
131
|
+
applyAuthHeader(merged, token)
|
|
132
|
+
return { ...request, headers: merged }
|
|
133
|
+
},
|
|
134
|
+
})
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// Static-token path: pick the right header at construction time.
|
|
138
|
+
// Suitable for long-lived API keys that never rotate.
|
|
139
|
+
if (config.token) {
|
|
140
|
+
const headers = new Headers(staticHeaders)
|
|
141
|
+
applyAuthHeader(headers, config.token)
|
|
142
|
+
return new GraphQLClient(url, {
|
|
143
|
+
headers,
|
|
144
|
+
credentials: config.credentials,
|
|
145
|
+
})
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// No credentials at all — used by unauthenticated introspection
|
|
149
|
+
// queries against public dev endpoints.
|
|
150
|
+
return new GraphQLClient(url, {
|
|
151
|
+
headers: staticHeaders,
|
|
152
|
+
credentials: config.credentials,
|
|
153
|
+
})
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Per-graph cache of GraphQL clients. Facade clients own one instance of
|
|
158
|
+
* this and call `.get(graphId)` on every GraphQL method — cheap after the
|
|
159
|
+
* first call per graph.
|
|
160
|
+
*/
|
|
161
|
+
export class GraphQLClientCache {
|
|
162
|
+
private clients = new Map<string, GraphQLClient>()
|
|
163
|
+
|
|
164
|
+
constructor(private config: GraphQLClientConfig) {}
|
|
165
|
+
|
|
166
|
+
get(graphId: string): GraphQLClient {
|
|
167
|
+
const existing = this.clients.get(graphId)
|
|
168
|
+
if (existing !== undefined) {
|
|
169
|
+
return existing
|
|
170
|
+
}
|
|
171
|
+
const client = createGraphQLClient(this.config, graphId)
|
|
172
|
+
this.clients.set(graphId, client)
|
|
173
|
+
return client
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Drop all cached clients. Only needed when swapping **static**
|
|
178
|
+
* credentials — e.g. replacing the `token` field on a long-lived
|
|
179
|
+
* facade between tenants, or resetting a CLI session. When the
|
|
180
|
+
* cache was built from a `tokenProvider`, rotation is handled
|
|
181
|
+
* per-request inside `requestMiddleware` and `clear()` is a no-op
|
|
182
|
+
* for auth purposes (the cached `GraphQLClient` instances keep
|
|
183
|
+
* using the same provider reference and will pick up the next
|
|
184
|
+
* token automatically).
|
|
185
|
+
*/
|
|
186
|
+
clear(): void {
|
|
187
|
+
this.clients.clear()
|
|
188
|
+
}
|
|
189
|
+
}
|
|
@@ -7,7 +7,7 @@ exports.useOperation = useOperation;
|
|
|
7
7
|
exports.useMultipleOperations = useMultipleOperations;
|
|
8
8
|
exports.useSDKClients = useSDKClients;
|
|
9
9
|
/**
|
|
10
|
-
* React hooks for SDK
|
|
10
|
+
* React hooks for SDK clients
|
|
11
11
|
* Provides easy-to-use hooks for Next.js/React applications
|
|
12
12
|
*/
|
|
13
13
|
const react_1 = require("react");
|
|
@@ -36,7 +36,7 @@ function useQuery(graphId) {
|
|
|
36
36
|
const clientRef = (0, react_1.useRef)(null);
|
|
37
37
|
// Initialize client
|
|
38
38
|
(0, react_1.useEffect)(() => {
|
|
39
|
-
const sdkConfig = (0, config_1.
|
|
39
|
+
const sdkConfig = (0, config_1.getSDKClientConfig)();
|
|
40
40
|
const clientConfig = client_gen_1.client.getConfig();
|
|
41
41
|
// Extract JWT token (uses centralized logic)
|
|
42
42
|
const token = (0, config_1.extractTokenFromSDKClient)();
|
|
@@ -115,7 +115,7 @@ function useStreamingQuery(graphId) {
|
|
|
115
115
|
const [rowsReceived, setRowsReceived] = (0, react_1.useState)(0);
|
|
116
116
|
const clientRef = (0, react_1.useRef)(null);
|
|
117
117
|
(0, react_1.useEffect)(() => {
|
|
118
|
-
const sdkConfig = (0, config_1.
|
|
118
|
+
const sdkConfig = (0, config_1.getSDKClientConfig)();
|
|
119
119
|
const clientConfig = client_gen_1.client.getConfig();
|
|
120
120
|
clientRef.current = new QueryClient_1.QueryClient({
|
|
121
121
|
baseUrl: sdkConfig.baseUrl || clientConfig.baseUrl || 'http://localhost:8000',
|
|
@@ -193,7 +193,7 @@ function useOperation(operationId) {
|
|
|
193
193
|
const [result, setResult] = (0, react_1.useState)(null);
|
|
194
194
|
const clientRef = (0, react_1.useRef)(null);
|
|
195
195
|
(0, react_1.useEffect)(() => {
|
|
196
|
-
const sdkConfig = (0, config_1.
|
|
196
|
+
const sdkConfig = (0, config_1.getSDKClientConfig)();
|
|
197
197
|
const clientConfig = client_gen_1.client.getConfig();
|
|
198
198
|
// Extract JWT token (uses centralized logic)
|
|
199
199
|
const token = (0, config_1.extractTokenFromSDKClient)();
|
|
@@ -292,7 +292,7 @@ function useMultipleOperations() {
|
|
|
292
292
|
const [errors, setErrors] = (0, react_1.useState)(new Map());
|
|
293
293
|
const clientRef = (0, react_1.useRef)(null);
|
|
294
294
|
(0, react_1.useEffect)(() => {
|
|
295
|
-
const sdkConfig = (0, config_1.
|
|
295
|
+
const sdkConfig = (0, config_1.getSDKClientConfig)();
|
|
296
296
|
const clientConfig = client_gen_1.client.getConfig();
|
|
297
297
|
// Extract JWT token (uses centralized logic)
|
|
298
298
|
const token = (0, config_1.extractTokenFromSDKClient)();
|
|
@@ -359,7 +359,7 @@ function useSDKClients() {
|
|
|
359
359
|
operations: null,
|
|
360
360
|
});
|
|
361
361
|
(0, react_1.useEffect)(() => {
|
|
362
|
-
const sdkConfig = (0, config_1.
|
|
362
|
+
const sdkConfig = (0, config_1.getSDKClientConfig)();
|
|
363
363
|
const clientConfig = client_gen_1.client.getConfig();
|
|
364
364
|
// Extract JWT token (uses centralized logic)
|
|
365
365
|
const token = (0, config_1.extractTokenFromSDKClient)();
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* React hooks for SDK
|
|
4
|
+
* React hooks for SDK clients
|
|
5
5
|
* Provides easy-to-use hooks for Next.js/React applications
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import { useCallback, useEffect, useRef, useState } from 'react'
|
|
9
9
|
import { client } from '../client.gen'
|
|
10
|
-
import { extractTokenFromSDKClient,
|
|
10
|
+
import { extractTokenFromSDKClient, getSDKClientConfig } from './config'
|
|
11
11
|
import type { OperationProgress, OperationResult } from './OperationClient'
|
|
12
12
|
import { OperationClient } from './OperationClient'
|
|
13
13
|
import type { QueryOptions, QueryResult } from './QueryClient'
|
|
@@ -35,7 +35,7 @@ export function useQuery(graphId: string) {
|
|
|
35
35
|
|
|
36
36
|
// Initialize client
|
|
37
37
|
useEffect(() => {
|
|
38
|
-
const sdkConfig =
|
|
38
|
+
const sdkConfig = getSDKClientConfig()
|
|
39
39
|
const clientConfig = client.getConfig()
|
|
40
40
|
|
|
41
41
|
// Extract JWT token (uses centralized logic)
|
|
@@ -136,7 +136,7 @@ export function useStreamingQuery(graphId: string) {
|
|
|
136
136
|
const clientRef = useRef<QueryClient>(null)
|
|
137
137
|
|
|
138
138
|
useEffect(() => {
|
|
139
|
-
const sdkConfig =
|
|
139
|
+
const sdkConfig = getSDKClientConfig()
|
|
140
140
|
const clientConfig = client.getConfig()
|
|
141
141
|
clientRef.current = new QueryClient({
|
|
142
142
|
baseUrl: sdkConfig.baseUrl || clientConfig.baseUrl || 'http://localhost:8000',
|
|
@@ -230,7 +230,7 @@ export function useOperation<T = any>(operationId?: string) {
|
|
|
230
230
|
const clientRef = useRef<OperationClient>(null)
|
|
231
231
|
|
|
232
232
|
useEffect(() => {
|
|
233
|
-
const sdkConfig =
|
|
233
|
+
const sdkConfig = getSDKClientConfig()
|
|
234
234
|
const clientConfig = client.getConfig()
|
|
235
235
|
|
|
236
236
|
// Extract JWT token (uses centralized logic)
|
|
@@ -343,7 +343,7 @@ export function useMultipleOperations<T = any>() {
|
|
|
343
343
|
const clientRef = useRef<OperationClient>(null)
|
|
344
344
|
|
|
345
345
|
useEffect(() => {
|
|
346
|
-
const sdkConfig =
|
|
346
|
+
const sdkConfig = getSDKClientConfig()
|
|
347
347
|
const clientConfig = client.getConfig()
|
|
348
348
|
|
|
349
349
|
// Extract JWT token (uses centralized logic)
|
|
@@ -428,7 +428,7 @@ export function useSDKClients() {
|
|
|
428
428
|
})
|
|
429
429
|
|
|
430
430
|
useEffect(() => {
|
|
431
|
-
const sdkConfig =
|
|
431
|
+
const sdkConfig = getSDKClientConfig()
|
|
432
432
|
const clientConfig = client.getConfig()
|
|
433
433
|
|
|
434
434
|
// Extract JWT token (uses centralized logic)
|
|
@@ -1,31 +1,47 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* RoboSystems SDK
|
|
3
|
-
*
|
|
2
|
+
* RoboSystems SDK Clients
|
|
3
|
+
* High-level clients with SSE support for the RoboSystems API
|
|
4
4
|
*/
|
|
5
|
-
import { OperationClient } from './OperationClient';
|
|
6
|
-
import { QueryClient } from './QueryClient';
|
|
7
5
|
import { AgentClient } from './AgentClient';
|
|
8
|
-
import {
|
|
6
|
+
import type { TokenProvider } from './graphql/client';
|
|
9
7
|
import { InvestorClient } from './InvestorClient';
|
|
10
8
|
import { LedgerClient } from './LedgerClient';
|
|
11
|
-
import {
|
|
12
|
-
|
|
9
|
+
import { OperationClient } from './OperationClient';
|
|
10
|
+
import { QueryClient } from './QueryClient';
|
|
11
|
+
import { SSEClient } from './SSEClient';
|
|
12
|
+
export type { TokenProvider } from './graphql/client';
|
|
13
|
+
export interface RoboSystemsClientConfig {
|
|
13
14
|
baseUrl?: string;
|
|
14
15
|
credentials?: 'include' | 'same-origin' | 'omit';
|
|
16
|
+
/**
|
|
17
|
+
* Static credential captured at construction time. Fine for
|
|
18
|
+
* long-lived API keys; use `tokenProvider` instead when the JWT
|
|
19
|
+
* can rotate (browser login flows).
|
|
20
|
+
*/
|
|
15
21
|
token?: string;
|
|
22
|
+
/**
|
|
23
|
+
* Dynamic credential callback invoked on every GraphQL request.
|
|
24
|
+
* When set, JWT refreshes are picked up automatically — no need
|
|
25
|
+
* to rebuild or clear cached clients after a refresh.
|
|
26
|
+
*/
|
|
27
|
+
tokenProvider?: TokenProvider;
|
|
16
28
|
headers?: Record<string, string>;
|
|
17
29
|
maxRetries?: number;
|
|
18
30
|
retryDelay?: number;
|
|
19
31
|
}
|
|
20
|
-
export declare class
|
|
32
|
+
export declare class RoboSystemsClients {
|
|
21
33
|
readonly query: QueryClient;
|
|
22
34
|
readonly agent: AgentClient;
|
|
23
35
|
readonly operations: OperationClient;
|
|
24
36
|
readonly ledger: LedgerClient;
|
|
25
37
|
readonly investor: InvestorClient;
|
|
26
|
-
|
|
38
|
+
/**
|
|
39
|
+
* @deprecated Use `ledger` instead — reports and publish lists are
|
|
40
|
+
* now part of the LedgerClient.
|
|
41
|
+
*/
|
|
42
|
+
readonly reports: LedgerClient;
|
|
27
43
|
private config;
|
|
28
|
-
constructor(config?:
|
|
44
|
+
constructor(config?: RoboSystemsClientConfig);
|
|
29
45
|
/**
|
|
30
46
|
* Convenience method to monitor any operation
|
|
31
47
|
*/
|
|
@@ -39,23 +55,23 @@ export declare class RoboSystemsExtensions {
|
|
|
39
55
|
*/
|
|
40
56
|
close(): void;
|
|
41
57
|
}
|
|
58
|
+
export * from './AgentClient';
|
|
59
|
+
export * from './config';
|
|
60
|
+
export * from './InvestorClient';
|
|
61
|
+
export * from './LedgerClient';
|
|
42
62
|
export * from './OperationClient';
|
|
43
63
|
export * from './QueryClient';
|
|
44
|
-
export * from './AgentClient';
|
|
45
64
|
export * from './SSEClient';
|
|
46
|
-
export
|
|
47
|
-
export * from './InvestorClient';
|
|
48
|
-
export * from './ReportClient';
|
|
49
|
-
export * from './config';
|
|
50
|
-
export { OperationClient, QueryClient, AgentClient, SSEClient, LedgerClient, InvestorClient, ReportClient, };
|
|
65
|
+
export { AgentClient, InvestorClient, LedgerClient, OperationClient, QueryClient, SSEClient };
|
|
51
66
|
export { useMultipleOperations, useOperation, useQuery, useSDKClients, useStreamingQuery, } from './hooks';
|
|
52
|
-
export declare const
|
|
67
|
+
export declare const clients: {
|
|
53
68
|
readonly query: QueryClient;
|
|
54
69
|
readonly agent: AgentClient;
|
|
55
70
|
readonly operations: OperationClient;
|
|
56
71
|
readonly ledger: LedgerClient;
|
|
57
72
|
readonly investor: InvestorClient;
|
|
58
|
-
|
|
73
|
+
/** @deprecated Use `ledger` instead */
|
|
74
|
+
readonly reports: LedgerClient;
|
|
59
75
|
monitorOperation: (operationId: string, onProgress?: (progress: any) => void) => Promise<any>;
|
|
60
76
|
createSSEClient: () => SSEClient;
|
|
61
77
|
close: () => void;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
* RoboSystems SDK
|
|
4
|
-
*
|
|
3
|
+
* RoboSystems SDK Clients
|
|
4
|
+
* High-level clients with SSE support for the RoboSystems API
|
|
5
5
|
*/
|
|
6
6
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
7
|
if (k2 === undefined) k2 = k;
|
|
@@ -18,33 +18,36 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
18
18
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
19
19
|
};
|
|
20
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
-
exports.analyzeFinancials = exports.agentQuery = exports.streamQuery = exports.executeQuery = exports.monitorOperation = exports.
|
|
21
|
+
exports.analyzeFinancials = exports.agentQuery = exports.streamQuery = exports.executeQuery = exports.monitorOperation = exports.clients = exports.useStreamingQuery = exports.useSDKClients = exports.useQuery = exports.useOperation = exports.useMultipleOperations = exports.SSEClient = exports.QueryClient = exports.OperationClient = exports.LedgerClient = exports.InvestorClient = exports.AgentClient = exports.RoboSystemsClients = void 0;
|
|
22
22
|
const client_gen_1 = require("../client.gen");
|
|
23
|
+
const AgentClient_1 = require("./AgentClient");
|
|
24
|
+
Object.defineProperty(exports, "AgentClient", { enumerable: true, get: function () { return AgentClient_1.AgentClient; } });
|
|
23
25
|
const config_1 = require("./config");
|
|
26
|
+
const InvestorClient_1 = require("./InvestorClient");
|
|
27
|
+
Object.defineProperty(exports, "InvestorClient", { enumerable: true, get: function () { return InvestorClient_1.InvestorClient; } });
|
|
28
|
+
const LedgerClient_1 = require("./LedgerClient");
|
|
29
|
+
Object.defineProperty(exports, "LedgerClient", { enumerable: true, get: function () { return LedgerClient_1.LedgerClient; } });
|
|
24
30
|
const OperationClient_1 = require("./OperationClient");
|
|
25
31
|
Object.defineProperty(exports, "OperationClient", { enumerable: true, get: function () { return OperationClient_1.OperationClient; } });
|
|
26
32
|
const QueryClient_1 = require("./QueryClient");
|
|
27
33
|
Object.defineProperty(exports, "QueryClient", { enumerable: true, get: function () { return QueryClient_1.QueryClient; } });
|
|
28
|
-
const AgentClient_1 = require("./AgentClient");
|
|
29
|
-
Object.defineProperty(exports, "AgentClient", { enumerable: true, get: function () { return AgentClient_1.AgentClient; } });
|
|
30
34
|
const SSEClient_1 = require("./SSEClient");
|
|
31
35
|
Object.defineProperty(exports, "SSEClient", { enumerable: true, get: function () { return SSEClient_1.SSEClient; } });
|
|
32
|
-
|
|
33
|
-
Object.defineProperty(exports, "InvestorClient", { enumerable: true, get: function () { return InvestorClient_1.InvestorClient; } });
|
|
34
|
-
const LedgerClient_1 = require("./LedgerClient");
|
|
35
|
-
Object.defineProperty(exports, "LedgerClient", { enumerable: true, get: function () { return LedgerClient_1.LedgerClient; } });
|
|
36
|
-
const ReportClient_1 = require("./ReportClient");
|
|
37
|
-
Object.defineProperty(exports, "ReportClient", { enumerable: true, get: function () { return ReportClient_1.ReportClient; } });
|
|
38
|
-
class RoboSystemsExtensions {
|
|
36
|
+
class RoboSystemsClients {
|
|
39
37
|
constructor(config = {}) {
|
|
40
38
|
// Get base URL from SDK client config or use provided/default
|
|
41
39
|
const sdkConfig = client_gen_1.client.getConfig();
|
|
42
40
|
// Extract JWT token using centralized logic
|
|
43
41
|
const token = config.token || (0, config_1.extractTokenFromSDKClient)();
|
|
42
|
+
// `tokenProvider` falls back to the global SDK clients config so
|
|
43
|
+
// apps can wire refresh once via `setSDKClientConfig({ tokenProvider })`
|
|
44
|
+
// and have the lazy default singleton pick it up automatically.
|
|
45
|
+
const tokenProvider = config.tokenProvider || (0, config_1.getSDKClientConfig)().tokenProvider;
|
|
44
46
|
this.config = {
|
|
45
47
|
baseUrl: config.baseUrl || sdkConfig.baseUrl || 'http://localhost:8000',
|
|
46
48
|
credentials: config.credentials || 'include',
|
|
47
49
|
token,
|
|
50
|
+
tokenProvider,
|
|
48
51
|
headers: config.headers,
|
|
49
52
|
maxRetries: config.maxRetries || 5,
|
|
50
53
|
retryDelay: config.retryDelay || 1000,
|
|
@@ -68,24 +71,24 @@ class RoboSystemsExtensions {
|
|
|
68
71
|
maxRetries: this.config.maxRetries,
|
|
69
72
|
retryDelay: this.config.retryDelay,
|
|
70
73
|
});
|
|
74
|
+
// LedgerClient / InvestorClient use GraphQL internally, so they
|
|
75
|
+
// get the tokenProvider — REST-only clients do not.
|
|
71
76
|
this.ledger = new LedgerClient_1.LedgerClient({
|
|
72
77
|
baseUrl: this.config.baseUrl,
|
|
73
78
|
credentials: this.config.credentials,
|
|
74
79
|
token: this.config.token,
|
|
80
|
+
tokenProvider: this.config.tokenProvider,
|
|
75
81
|
headers: this.config.headers,
|
|
76
82
|
});
|
|
77
83
|
this.investor = new InvestorClient_1.InvestorClient({
|
|
78
84
|
baseUrl: this.config.baseUrl,
|
|
79
85
|
credentials: this.config.credentials,
|
|
80
86
|
token: this.config.token,
|
|
87
|
+
tokenProvider: this.config.tokenProvider,
|
|
81
88
|
headers: this.config.headers,
|
|
82
89
|
});
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
credentials: this.config.credentials,
|
|
86
|
-
token: this.config.token,
|
|
87
|
-
headers: this.config.headers,
|
|
88
|
-
});
|
|
90
|
+
// Reports consolidated into LedgerClient — alias for backward compat
|
|
91
|
+
this.reports = this.ledger;
|
|
89
92
|
}
|
|
90
93
|
/**
|
|
91
94
|
* Convenience method to monitor any operation
|
|
@@ -115,16 +118,15 @@ class RoboSystemsExtensions {
|
|
|
115
118
|
this.operations.closeAll();
|
|
116
119
|
}
|
|
117
120
|
}
|
|
118
|
-
exports.
|
|
121
|
+
exports.RoboSystemsClients = RoboSystemsClients;
|
|
119
122
|
// Export all types and classes
|
|
123
|
+
__exportStar(require("./AgentClient"), exports);
|
|
124
|
+
__exportStar(require("./config"), exports);
|
|
125
|
+
__exportStar(require("./InvestorClient"), exports);
|
|
126
|
+
__exportStar(require("./LedgerClient"), exports);
|
|
120
127
|
__exportStar(require("./OperationClient"), exports);
|
|
121
128
|
__exportStar(require("./QueryClient"), exports);
|
|
122
|
-
__exportStar(require("./AgentClient"), exports);
|
|
123
129
|
__exportStar(require("./SSEClient"), exports);
|
|
124
|
-
__exportStar(require("./LedgerClient"), exports);
|
|
125
|
-
__exportStar(require("./InvestorClient"), exports);
|
|
126
|
-
__exportStar(require("./ReportClient"), exports);
|
|
127
|
-
__exportStar(require("./config"), exports);
|
|
128
130
|
// Export React hooks
|
|
129
131
|
var hooks_1 = require("./hooks");
|
|
130
132
|
Object.defineProperty(exports, "useMultipleOperations", { enumerable: true, get: function () { return hooks_1.useMultipleOperations; } });
|
|
@@ -133,44 +135,45 @@ Object.defineProperty(exports, "useQuery", { enumerable: true, get: function ()
|
|
|
133
135
|
Object.defineProperty(exports, "useSDKClients", { enumerable: true, get: function () { return hooks_1.useSDKClients; } });
|
|
134
136
|
Object.defineProperty(exports, "useStreamingQuery", { enumerable: true, get: function () { return hooks_1.useStreamingQuery; } });
|
|
135
137
|
// Lazy initialization of default instance
|
|
136
|
-
let
|
|
137
|
-
function
|
|
138
|
-
if (!
|
|
139
|
-
|
|
138
|
+
let _clients = null;
|
|
139
|
+
function getClients() {
|
|
140
|
+
if (!_clients) {
|
|
141
|
+
_clients = new RoboSystemsClients();
|
|
140
142
|
}
|
|
141
|
-
return
|
|
143
|
+
return _clients;
|
|
142
144
|
}
|
|
143
|
-
exports.
|
|
145
|
+
exports.clients = {
|
|
144
146
|
get query() {
|
|
145
|
-
return
|
|
147
|
+
return getClients().query;
|
|
146
148
|
},
|
|
147
149
|
get agent() {
|
|
148
|
-
return
|
|
150
|
+
return getClients().agent;
|
|
149
151
|
},
|
|
150
152
|
get operations() {
|
|
151
|
-
return
|
|
153
|
+
return getClients().operations;
|
|
152
154
|
},
|
|
153
155
|
get ledger() {
|
|
154
|
-
return
|
|
156
|
+
return getClients().ledger;
|
|
155
157
|
},
|
|
156
158
|
get investor() {
|
|
157
|
-
return
|
|
159
|
+
return getClients().investor;
|
|
158
160
|
},
|
|
161
|
+
/** @deprecated Use `ledger` instead */
|
|
159
162
|
get reports() {
|
|
160
|
-
return
|
|
163
|
+
return getClients().ledger;
|
|
161
164
|
},
|
|
162
|
-
monitorOperation: (operationId, onProgress) =>
|
|
163
|
-
createSSEClient: () =>
|
|
164
|
-
close: () =>
|
|
165
|
+
monitorOperation: (operationId, onProgress) => getClients().monitorOperation(operationId, onProgress),
|
|
166
|
+
createSSEClient: () => getClients().createSSEClient(),
|
|
167
|
+
close: () => getClients().close(),
|
|
165
168
|
};
|
|
166
169
|
// Export convenience functions that use the default instance
|
|
167
|
-
const monitorOperation = (operationId, onProgress) =>
|
|
170
|
+
const monitorOperation = (operationId, onProgress) => getClients().monitorOperation(operationId, onProgress);
|
|
168
171
|
exports.monitorOperation = monitorOperation;
|
|
169
|
-
const executeQuery = (graphId, query, parameters) =>
|
|
172
|
+
const executeQuery = (graphId, query, parameters) => getClients().query.query(graphId, query, parameters);
|
|
170
173
|
exports.executeQuery = executeQuery;
|
|
171
|
-
const streamQuery = (graphId, query, parameters, chunkSize) =>
|
|
174
|
+
const streamQuery = (graphId, query, parameters, chunkSize) => getClients().query.streamQuery(graphId, query, parameters, chunkSize);
|
|
172
175
|
exports.streamQuery = streamQuery;
|
|
173
|
-
const agentQuery = (graphId, message, context) =>
|
|
176
|
+
const agentQuery = (graphId, message, context) => getClients().agent.query(graphId, message, context);
|
|
174
177
|
exports.agentQuery = agentQuery;
|
|
175
|
-
const analyzeFinancials = (graphId, message) =>
|
|
178
|
+
const analyzeFinancials = (graphId, message) => getClients().agent.analyzeFinancials(graphId, message);
|
|
176
179
|
exports.analyzeFinancials = analyzeFinancials;
|