@robosystems/client 2.5.3 → 2.6.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.
- package/artifacts/InvestorClient.d.ts +7 -1
- package/artifacts/InvestorClient.js +24 -14
- package/artifacts/InvestorClient.ts +46 -27
- package/artifacts/LedgerClient.d.ts +23 -17
- package/artifacts/LedgerClient.js +116 -123
- package/artifacts/LedgerClient.ts +180 -242
- package/artifacts/OperationClient.js +24 -1
- package/artifacts/OperationClient.ts +24 -1
- package/artifacts/OperatorClient.d.ts +10 -0
- package/artifacts/OperatorClient.js +72 -17
- package/artifacts/OperatorClient.ts +79 -21
- package/artifacts/QueryClient.d.ts +2 -1
- package/artifacts/QueryClient.js +17 -58
- package/artifacts/QueryClient.ts +21 -68
- package/artifacts/SSEClient.d.ts +1 -0
- package/artifacts/SSEClient.js +56 -7
- package/artifacts/SSEClient.ts +57 -7
- package/artifacts/config.js +18 -4
- package/artifacts/config.ts +18 -4
- package/artifacts/graphql/client.d.ts +10 -0
- package/artifacts/graphql/client.js +29 -21
- package/artifacts/graphql/client.ts +34 -23
- package/artifacts/index.d.ts +2 -2
- package/artifacts/index.js +6 -6
- package/artifacts/index.ts +8 -8
- package/artifacts/rest.d.ts +22 -0
- package/artifacts/rest.js +27 -0
- package/artifacts/rest.ts +54 -0
- package/artifacts/retry.js +8 -3
- package/artifacts/retry.ts +8 -3
- package/package.json +9 -1
- package/sdk/types.gen.d.ts +7 -1
- package/sdk/types.gen.ts +7 -1
- package/types.gen.d.ts +7 -1
- package/types.gen.ts +7 -1
|
@@ -25,7 +25,7 @@ interface InvestorClientConfig {
|
|
|
25
25
|
token?: string;
|
|
26
26
|
/**
|
|
27
27
|
* Dynamic credential callback. When set, invoked on every GraphQL
|
|
28
|
-
* request so refreshes flow through automatically.
|
|
28
|
+
* request and REST write so refreshes flow through automatically.
|
|
29
29
|
*/
|
|
30
30
|
tokenProvider?: TokenProvider;
|
|
31
31
|
/** GraphQL request timeout in milliseconds (default 60s). */
|
|
@@ -119,4 +119,10 @@ export declare class InvestorClient {
|
|
|
119
119
|
getHoldings(graphId: string, portfolioId: string): Promise<InvestorHoldings | null>;
|
|
120
120
|
private gqlQuery;
|
|
121
121
|
private callOperation;
|
|
122
|
+
/**
|
|
123
|
+
* Unwrap the result from an OperationEnvelope. Throws when the server
|
|
124
|
+
* returned an envelope with no `result` — generally a sign that a
|
|
125
|
+
* synchronous operation failed silently.
|
|
126
|
+
*/
|
|
127
|
+
private requireResult;
|
|
122
128
|
}
|
|
@@ -6,6 +6,7 @@ const graphql_request_1 = require("graphql-request");
|
|
|
6
6
|
const sdk_gen_1 = require("../sdk.gen");
|
|
7
7
|
const client_1 = require("./graphql/client");
|
|
8
8
|
const graphql_1 = require("./graphql/generated/graphql");
|
|
9
|
+
const rest_1 = require("./rest");
|
|
9
10
|
// Re-export the structured GraphQL error type so consumers importing
|
|
10
11
|
// from the `@robosystems/client/investor` subpath can `instanceof` it.
|
|
11
12
|
var client_2 = require("./graphql/client");
|
|
@@ -38,8 +39,8 @@ class InvestorClient {
|
|
|
38
39
|
* securities — use `createSecurity` first.
|
|
39
40
|
*/
|
|
40
41
|
async createPortfolioBlock(graphId, body) {
|
|
41
|
-
const envelope = await this.callOperation('Create portfolio block', (0, sdk_gen_1.createPortfolioBlock)({ path: { graph_id: graphId }, body }));
|
|
42
|
-
return rawToPortfolioBlock(envelope.result);
|
|
42
|
+
const envelope = await this.callOperation('Create portfolio block', (o) => (0, sdk_gen_1.createPortfolioBlock)({ ...o, path: { graph_id: graphId }, body }));
|
|
43
|
+
return rawToPortfolioBlock(this.requireResult('Create portfolio block', envelope.result));
|
|
43
44
|
}
|
|
44
45
|
/**
|
|
45
46
|
* Patch portfolio fields and apply position deltas (`add`, `update`,
|
|
@@ -52,8 +53,8 @@ class InvestorClient {
|
|
|
52
53
|
portfolio_id: portfolioId,
|
|
53
54
|
...updates,
|
|
54
55
|
};
|
|
55
|
-
const envelope = await this.callOperation('Update portfolio block', (0, sdk_gen_1.updatePortfolioBlock)({ path: { graph_id: graphId }, body }));
|
|
56
|
-
return rawToPortfolioBlock(envelope.result);
|
|
56
|
+
const envelope = await this.callOperation('Update portfolio block', (o) => (0, sdk_gen_1.updatePortfolioBlock)({ ...o, path: { graph_id: graphId }, body }));
|
|
57
|
+
return rawToPortfolioBlock(this.requireResult('Update portfolio block', envelope.result));
|
|
57
58
|
}
|
|
58
59
|
/**
|
|
59
60
|
* Cascade-delete the portfolio plus all of its positions. When the
|
|
@@ -66,7 +67,7 @@ class InvestorClient {
|
|
|
66
67
|
portfolio_id: portfolioId,
|
|
67
68
|
confirm_active_positions: options?.confirmActivePositions ?? false,
|
|
68
69
|
};
|
|
69
|
-
const envelope = await this.callOperation('Delete portfolio block', (0, sdk_gen_1.deletePortfolioBlock)({ path: { graph_id: graphId }, body }));
|
|
70
|
+
const envelope = await this.callOperation('Delete portfolio block', (o) => (0, sdk_gen_1.deletePortfolioBlock)({ ...o, path: { graph_id: graphId }, body }));
|
|
70
71
|
return envelope.result ?? { deleted: true };
|
|
71
72
|
}
|
|
72
73
|
// ── Securities ──────────────────────────────────────────────────────
|
|
@@ -89,26 +90,24 @@ class InvestorClient {
|
|
|
89
90
|
* matching entity in the target graph.
|
|
90
91
|
*/
|
|
91
92
|
async createSecurity(graphId, body) {
|
|
92
|
-
const envelope = await this.callOperation('Create security', (0, sdk_gen_1.createSecurity)({ path: { graph_id: graphId }, body }));
|
|
93
|
-
return rawToInvestorSecurity(envelope.result);
|
|
93
|
+
const envelope = await this.callOperation('Create security', (o) => (0, sdk_gen_1.createSecurity)({ ...o, path: { graph_id: graphId }, body }));
|
|
94
|
+
return rawToInvestorSecurity(this.requireResult('Create security', envelope.result));
|
|
94
95
|
}
|
|
95
96
|
/** Update a security's metadata. Only provided fields are applied. */
|
|
96
97
|
async updateSecurity(graphId, securityId, updates) {
|
|
97
|
-
const envelope = await this.callOperation('Update security', (0, sdk_gen_1.updateSecurity)({
|
|
98
|
+
const envelope = await this.callOperation('Update security', (o) => (0, sdk_gen_1.updateSecurity)({
|
|
99
|
+
...o,
|
|
98
100
|
path: { graph_id: graphId },
|
|
99
101
|
body: {
|
|
100
102
|
...updates,
|
|
101
103
|
security_id: securityId,
|
|
102
104
|
},
|
|
103
105
|
}));
|
|
104
|
-
return rawToInvestorSecurity(envelope.result);
|
|
106
|
+
return rawToInvestorSecurity(this.requireResult('Update security', envelope.result));
|
|
105
107
|
}
|
|
106
108
|
/** Soft-delete a security (sets is_active=false). */
|
|
107
109
|
async deleteSecurity(graphId, securityId) {
|
|
108
|
-
const envelope = await this.callOperation('Delete security', (0, sdk_gen_1.deleteSecurity)({
|
|
109
|
-
path: { graph_id: graphId },
|
|
110
|
-
body: { security_id: securityId },
|
|
111
|
-
}));
|
|
110
|
+
const envelope = await this.callOperation('Delete security', (o) => (0, sdk_gen_1.deleteSecurity)({ ...o, path: { graph_id: graphId }, body: { security_id: securityId } }));
|
|
112
111
|
return envelope.result ?? { deleted: true };
|
|
113
112
|
}
|
|
114
113
|
// ── Positions (reads only — writes folded into Portfolio Block) ─────
|
|
@@ -156,7 +155,7 @@ class InvestorClient {
|
|
|
156
155
|
// `envelope.result` instead of being widened to `unknown`. Untyped ops
|
|
157
156
|
// continue to land as `OperationEnvelope` automatically.
|
|
158
157
|
async callOperation(label, call) {
|
|
159
|
-
const response = await call;
|
|
158
|
+
const response = await call(await (0, rest_1.restCallOptions)(this.config));
|
|
160
159
|
if (response.error !== undefined) {
|
|
161
160
|
throw new Error(`${label} failed: ${JSON.stringify(response.error)}`);
|
|
162
161
|
}
|
|
@@ -165,6 +164,17 @@ class InvestorClient {
|
|
|
165
164
|
}
|
|
166
165
|
return response.data;
|
|
167
166
|
}
|
|
167
|
+
/**
|
|
168
|
+
* Unwrap the result from an OperationEnvelope. Throws when the server
|
|
169
|
+
* returned an envelope with no `result` — generally a sign that a
|
|
170
|
+
* synchronous operation failed silently.
|
|
171
|
+
*/
|
|
172
|
+
requireResult(label, result) {
|
|
173
|
+
if (result === null || result === undefined) {
|
|
174
|
+
throw new Error(`${label}: operation envelope had no result`);
|
|
175
|
+
}
|
|
176
|
+
return result;
|
|
177
|
+
}
|
|
168
178
|
}
|
|
169
179
|
exports.InvestorClient = InvestorClient;
|
|
170
180
|
function rawToInvestorSecurity(raw) {
|
|
@@ -59,6 +59,7 @@ import {
|
|
|
59
59
|
type ListInvestorPositionsQuery,
|
|
60
60
|
type ListInvestorSecuritiesQuery,
|
|
61
61
|
} from './graphql/generated/graphql'
|
|
62
|
+
import { restCallOptions, type RestCallOptions } from './rest'
|
|
62
63
|
|
|
63
64
|
// Re-export the structured GraphQL error type so consumers importing
|
|
64
65
|
// from the `@robosystems/client/investor` subpath can `instanceof` it.
|
|
@@ -96,7 +97,7 @@ interface InvestorClientConfig {
|
|
|
96
97
|
token?: string
|
|
97
98
|
/**
|
|
98
99
|
* Dynamic credential callback. When set, invoked on every GraphQL
|
|
99
|
-
* request so refreshes flow through automatically.
|
|
100
|
+
* request and REST write so refreshes flow through automatically.
|
|
100
101
|
*/
|
|
101
102
|
tokenProvider?: TokenProvider
|
|
102
103
|
/** GraphQL request timeout in milliseconds (default 60s). */
|
|
@@ -167,11 +168,15 @@ export class InvestorClient {
|
|
|
167
168
|
graphId: string,
|
|
168
169
|
body: CreatePortfolioBlockRequest
|
|
169
170
|
): Promise<InvestorPortfolioBlock> {
|
|
170
|
-
const envelope = await this.callOperation(
|
|
171
|
-
|
|
172
|
-
|
|
171
|
+
const envelope = await this.callOperation('Create portfolio block', (o) =>
|
|
172
|
+
createPortfolioBlock({ ...o, path: { graph_id: graphId }, body })
|
|
173
|
+
)
|
|
174
|
+
return rawToPortfolioBlock(
|
|
175
|
+
this.requireResult(
|
|
176
|
+
'Create portfolio block',
|
|
177
|
+
envelope.result
|
|
178
|
+
) as unknown as RawPortfolioBlockResponse
|
|
173
179
|
)
|
|
174
|
-
return rawToPortfolioBlock(envelope.result as unknown as RawPortfolioBlockResponse)
|
|
175
180
|
}
|
|
176
181
|
|
|
177
182
|
/**
|
|
@@ -192,11 +197,15 @@ export class InvestorClient {
|
|
|
192
197
|
portfolio_id: portfolioId,
|
|
193
198
|
...updates,
|
|
194
199
|
}
|
|
195
|
-
const envelope = await this.callOperation(
|
|
196
|
-
|
|
197
|
-
|
|
200
|
+
const envelope = await this.callOperation('Update portfolio block', (o) =>
|
|
201
|
+
updatePortfolioBlock({ ...o, path: { graph_id: graphId }, body })
|
|
202
|
+
)
|
|
203
|
+
return rawToPortfolioBlock(
|
|
204
|
+
this.requireResult(
|
|
205
|
+
'Update portfolio block',
|
|
206
|
+
envelope.result
|
|
207
|
+
) as unknown as RawPortfolioBlockResponse
|
|
198
208
|
)
|
|
199
|
-
return rawToPortfolioBlock(envelope.result as unknown as RawPortfolioBlockResponse)
|
|
200
209
|
}
|
|
201
210
|
|
|
202
211
|
/**
|
|
@@ -214,9 +223,8 @@ export class InvestorClient {
|
|
|
214
223
|
portfolio_id: portfolioId,
|
|
215
224
|
confirm_active_positions: options?.confirmActivePositions ?? false,
|
|
216
225
|
}
|
|
217
|
-
const envelope = await this.callOperation(
|
|
218
|
-
|
|
219
|
-
deletePortfolioBlock({ path: { graph_id: graphId }, body })
|
|
226
|
+
const envelope = await this.callOperation('Delete portfolio block', (o) =>
|
|
227
|
+
deletePortfolioBlock({ ...o, path: { graph_id: graphId }, body })
|
|
220
228
|
)
|
|
221
229
|
return envelope.result ?? { deleted: true }
|
|
222
230
|
}
|
|
@@ -265,11 +273,12 @@ export class InvestorClient {
|
|
|
265
273
|
* matching entity in the target graph.
|
|
266
274
|
*/
|
|
267
275
|
async createSecurity(graphId: string, body: CreateSecurityRequest): Promise<InvestorSecurity> {
|
|
268
|
-
const envelope = await this.callOperation(
|
|
269
|
-
|
|
270
|
-
|
|
276
|
+
const envelope = await this.callOperation('Create security', (o) =>
|
|
277
|
+
createSecurity({ ...o, path: { graph_id: graphId }, body })
|
|
278
|
+
)
|
|
279
|
+
return rawToInvestorSecurity(
|
|
280
|
+
this.requireResult('Create security', envelope.result) as unknown as RawSecurityResponse
|
|
271
281
|
)
|
|
272
|
-
return rawToInvestorSecurity(envelope.result as unknown as RawSecurityResponse)
|
|
273
282
|
}
|
|
274
283
|
|
|
275
284
|
/** Update a security's metadata. Only provided fields are applied. */
|
|
@@ -278,9 +287,9 @@ export class InvestorClient {
|
|
|
278
287
|
securityId: string,
|
|
279
288
|
updates: Omit<UpdateSecurityOperation, 'security_id'>
|
|
280
289
|
): Promise<InvestorSecurity> {
|
|
281
|
-
const envelope = await this.callOperation(
|
|
282
|
-
'Update security',
|
|
290
|
+
const envelope = await this.callOperation('Update security', (o) =>
|
|
283
291
|
updateSecurity({
|
|
292
|
+
...o,
|
|
284
293
|
path: { graph_id: graphId },
|
|
285
294
|
body: {
|
|
286
295
|
...updates,
|
|
@@ -288,17 +297,15 @@ export class InvestorClient {
|
|
|
288
297
|
} as UpdateSecurityOperation,
|
|
289
298
|
})
|
|
290
299
|
)
|
|
291
|
-
return rawToInvestorSecurity(
|
|
300
|
+
return rawToInvestorSecurity(
|
|
301
|
+
this.requireResult('Update security', envelope.result) as unknown as RawSecurityResponse
|
|
302
|
+
)
|
|
292
303
|
}
|
|
293
304
|
|
|
294
305
|
/** Soft-delete a security (sets is_active=false). */
|
|
295
306
|
async deleteSecurity(graphId: string, securityId: string): Promise<{ deleted: boolean }> {
|
|
296
|
-
const envelope = await this.callOperation(
|
|
297
|
-
|
|
298
|
-
deleteSecurity({
|
|
299
|
-
path: { graph_id: graphId },
|
|
300
|
-
body: { security_id: securityId },
|
|
301
|
-
})
|
|
307
|
+
const envelope = await this.callOperation('Delete security', (o) =>
|
|
308
|
+
deleteSecurity({ ...o, path: { graph_id: graphId }, body: { security_id: securityId } })
|
|
302
309
|
)
|
|
303
310
|
return envelope.result ?? { deleted: true }
|
|
304
311
|
}
|
|
@@ -389,9 +396,9 @@ export class InvestorClient {
|
|
|
389
396
|
// continue to land as `OperationEnvelope` automatically.
|
|
390
397
|
private async callOperation<T>(
|
|
391
398
|
label: string,
|
|
392
|
-
call: Promise<{ data?: T; error?: unknown }>
|
|
399
|
+
call: (options: RestCallOptions) => Promise<{ data?: T; error?: unknown }>
|
|
393
400
|
): Promise<T> {
|
|
394
|
-
const response = await call
|
|
401
|
+
const response = await call(await restCallOptions(this.config))
|
|
395
402
|
if (response.error !== undefined) {
|
|
396
403
|
throw new Error(`${label} failed: ${JSON.stringify(response.error)}`)
|
|
397
404
|
}
|
|
@@ -400,6 +407,18 @@ export class InvestorClient {
|
|
|
400
407
|
}
|
|
401
408
|
return response.data
|
|
402
409
|
}
|
|
410
|
+
|
|
411
|
+
/**
|
|
412
|
+
* Unwrap the result from an OperationEnvelope. Throws when the server
|
|
413
|
+
* returned an envelope with no `result` — generally a sign that a
|
|
414
|
+
* synchronous operation failed silently.
|
|
415
|
+
*/
|
|
416
|
+
private requireResult<T>(label: string, result: T | null | undefined): T {
|
|
417
|
+
if (result === null || result === undefined) {
|
|
418
|
+
throw new Error(`${label}: operation envelope had no result`)
|
|
419
|
+
}
|
|
420
|
+
return result
|
|
421
|
+
}
|
|
403
422
|
}
|
|
404
423
|
|
|
405
424
|
// ── Module-private conversion helpers ─────────────────────────────────
|
|
@@ -339,7 +339,7 @@ interface LedgerClientConfig {
|
|
|
339
339
|
token?: string;
|
|
340
340
|
/**
|
|
341
341
|
* Dynamic credential callback. When set, invoked on every GraphQL
|
|
342
|
-
* request so refreshes flow through automatically.
|
|
342
|
+
* request and REST write so refreshes flow through automatically.
|
|
343
343
|
*/
|
|
344
344
|
tokenProvider?: TokenProvider;
|
|
345
345
|
/** GraphQL request timeout in milliseconds (default 60s). */
|
|
@@ -588,7 +588,6 @@ export declare class LedgerClient {
|
|
|
588
588
|
offset?: number;
|
|
589
589
|
scenarioId?: string;
|
|
590
590
|
}): Promise<InformationBlockList>;
|
|
591
|
-
/** Create a new schedule with pre-generated monthly facts. */
|
|
592
591
|
/**
|
|
593
592
|
* Create an Information Block of any registered block_type.
|
|
594
593
|
*
|
|
@@ -613,8 +612,12 @@ export declare class LedgerClient {
|
|
|
613
612
|
* associations tied to the block.
|
|
614
613
|
*/
|
|
615
614
|
deleteInformationBlock(graphId: string, body: DeleteInformationBlockRequest): Promise<DeleteInformationBlockResponse>;
|
|
615
|
+
/** Create a new schedule with pre-generated monthly facts. */
|
|
616
616
|
createSchedule(graphId: string, options: CreateScheduleOptions): Promise<ScheduleBlockCreated>;
|
|
617
|
-
/**
|
|
617
|
+
/**
|
|
618
|
+
* Rename a schedule. For other block fields use `updateInformationBlock`
|
|
619
|
+
* with a `schedule` payload.
|
|
620
|
+
*/
|
|
618
621
|
updateSchedule(graphId: string, structureId: string, options: {
|
|
619
622
|
name?: string;
|
|
620
623
|
}): Promise<InformationBlockEnvelope>;
|
|
@@ -631,7 +634,8 @@ export declare class LedgerClient {
|
|
|
631
634
|
* a rebuild re-scopes the schedule to today's close state. Use this to
|
|
632
635
|
* pick up a fixed generator without orphaning obligations.
|
|
633
636
|
*
|
|
634
|
-
* Returns the
|
|
637
|
+
* Returns the {@link ScheduleCreated} rebuild summary (periods, facts,
|
|
638
|
+
* rule results) — richer than `createSchedule`'s {@link ScheduleBlockCreated}.
|
|
635
639
|
*/
|
|
636
640
|
rebuildSchedule(graphId: string, structureId: string, options?: {
|
|
637
641
|
idempotencyKey?: string;
|
|
@@ -780,6 +784,18 @@ export declare class LedgerClient {
|
|
|
780
784
|
reason?: string | null;
|
|
781
785
|
source?: string;
|
|
782
786
|
}): Promise<EventBlockEnvelope>;
|
|
787
|
+
/**
|
|
788
|
+
* Create an event block directly. Use for support-class events
|
|
789
|
+
* (`event_class: 'support'`) with categories `approval`, `control`,
|
|
790
|
+
* `reconciliation`, or `inquiry`, which the specialized helpers don't
|
|
791
|
+
* cover. Economic events should generally go through
|
|
792
|
+
* `createJournalEntry`, `createClosingEntry`, etc., but this works for
|
|
793
|
+
* those too.
|
|
794
|
+
*
|
|
795
|
+
* Supply `idempotencyKey` to make the call safe to retry — replays
|
|
796
|
+
* within 24 hours return the same envelope.
|
|
797
|
+
*/
|
|
798
|
+
createEventBlock(graphId: string, body: CreateEventBlockRequest, idempotencyKey?: string): Promise<EventBlockEnvelope>;
|
|
783
799
|
/**
|
|
784
800
|
* Dry-run an event block — resolve the handler, evaluate metadata, and
|
|
785
801
|
* return the planned GL rows without writing anything. Companion to
|
|
@@ -1001,8 +1017,9 @@ export declare class LedgerClient {
|
|
|
1001
1017
|
/** Remove a single member from a publish list. */
|
|
1002
1018
|
removePublishListMember(graphId: string, listId: string, memberId: string): Promise<DeleteResult>;
|
|
1003
1019
|
/**
|
|
1004
|
-
*
|
|
1005
|
-
*
|
|
1020
|
+
* Run an SDK-generated command call with this facade's per-call
|
|
1021
|
+
* transport options (`baseUrl`, credential, headers), throw a readable
|
|
1022
|
+
* error on non-2xx, and return the parsed envelope on success.
|
|
1006
1023
|
*
|
|
1007
1024
|
* Generic over the SDK call's response shape so typed ops (e.g.
|
|
1008
1025
|
* `createEventBlock`, which returns
|
|
@@ -1017,15 +1034,4 @@ export declare class LedgerClient {
|
|
|
1017
1034
|
* sign that a synchronous operation failed silently.
|
|
1018
1035
|
*/
|
|
1019
1036
|
private requireResult;
|
|
1020
|
-
/**
|
|
1021
|
-
* Resolve the current bearer token / API key for non-GraphQL REST
|
|
1022
|
-
* calls. Mirrors the GraphQL client's behaviour — dynamic
|
|
1023
|
-
* ``tokenProvider`` is consulted first (so JWT rotation flows
|
|
1024
|
-
* naturally), then the static ``token`` config. Returns ``null``
|
|
1025
|
-
* when no credential is configured (cookie-based / anonymous flows).
|
|
1026
|
-
* A ``tokenProvider`` that **throws** fails the call fast instead of
|
|
1027
|
-
* silently proceeding unauthenticated — matching the Python client,
|
|
1028
|
-
* which raises when its configured credential cannot be resolved.
|
|
1029
|
-
*/
|
|
1030
|
-
private resolveToken;
|
|
1031
1037
|
}
|