@robosystems/client 2.5.3 → 2.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -165,10 +165,43 @@ function createTimeoutFetch(timeoutMs: number): typeof fetch {
165
165
  * sending a JWT as `X-API-Key` or an API key as Bearer both 401.
166
166
  */
167
167
  function applyAuthHeader(headers: Headers, token: string): void {
168
- if (token.startsWith('rfs')) {
169
- headers.set('X-API-Key', token)
170
- } else {
171
- headers.set('Authorization', `Bearer ${token}`)
168
+ // The resolved credential replaces any the static headers carry, so
169
+ // exactly one is sent.
170
+ headers.delete('X-API-Key')
171
+ headers.delete('Authorization')
172
+ for (const [name, value] of Object.entries(authHeaderFor(token))) {
173
+ headers.set(name, value)
174
+ }
175
+ }
176
+
177
+ /** The auth header for a credential — see {@link applyAuthHeader} for the rule. */
178
+ export function authHeaderFor(token: string): Record<string, string> {
179
+ return token.startsWith('rfs') ? { 'X-API-Key': token } : { Authorization: `Bearer ${token}` }
180
+ }
181
+
182
+ /**
183
+ * The credential for one request: the `tokenProvider` result when one is
184
+ * configured (`null` means send unauthenticated), otherwise the static
185
+ * `token`. A throwing provider fails the request fast — the caller meant
186
+ * to authenticate, and an unauthenticated request would surface as a
187
+ * confusing 401 far from the real failure (matches the Python client).
188
+ */
189
+ export async function resolveCredential(
190
+ config: Pick<GraphQLClientConfig, 'token' | 'tokenProvider'>
191
+ ): Promise<string | null> {
192
+ if (!config.tokenProvider) {
193
+ return config.token ?? null
194
+ }
195
+ try {
196
+ return (await config.tokenProvider()) ?? null
197
+ } catch (err) {
198
+ const detail = err instanceof Error ? err.message : String(err)
199
+ throw new Error(
200
+ `RoboSystems SDK: tokenProvider threw while resolving the request credential (${detail}). ` +
201
+ 'Fix the tokenProvider passed in the client config (or via setSDKClientConfig) so it ' +
202
+ 'returns the current token, or null to send an unauthenticated (cookie-based) request.',
203
+ { cause: err }
204
+ )
172
205
  }
173
206
  }
174
207
 
@@ -204,25 +237,7 @@ export function createGraphQLClient(config: GraphQLClientConfig, graphId: string
204
237
  credentials: config.credentials,
205
238
  fetch: timeoutFetch,
206
239
  requestMiddleware: async (request) => {
207
- let token: string | null | undefined
208
- try {
209
- token = await providerFn()
210
- } catch (err) {
211
- // Fail fast — a throwing provider means the caller *intended*
212
- // to authenticate but couldn't produce a credential. Sending
213
- // the request unauthenticated would surface as a confusing
214
- // 401 far from the real failure. (Matches the Python client,
215
- // which raises when its credential is missing.) A provider
216
- // that deliberately has no credential should return `null`
217
- // instead — that still sends an unauthenticated request.
218
- const detail = err instanceof Error ? err.message : String(err)
219
- throw new Error(
220
- `RoboSystems SDK: tokenProvider threw while resolving the request credential (${detail}). ` +
221
- 'Fix the tokenProvider passed in the client config (or via setSDKClientConfig) so it ' +
222
- 'returns the current token, or null to send an unauthenticated (cookie-based) request.',
223
- { cause: err }
224
- )
225
- }
240
+ const token = await resolveCredential({ tokenProvider: providerFn })
226
241
  if (!token) {
227
242
  return request
228
243
  }
@@ -23,8 +23,8 @@ export interface RoboSystemsClientConfig {
23
23
  */
24
24
  token?: string;
25
25
  /**
26
- * Dynamic credential callback invoked on every GraphQL request and
27
- * every SSE connect. When set, JWT refreshes are picked up
26
+ * Dynamic credential callback invoked on every GraphQL request, every
27
+ * facade REST write, and every SSE connect. When set, JWT refreshes are picked up
28
28
  * automatically — no need to rebuild or clear cached clients after a
29
29
  * refresh. Browser sessions need this: the backend revokes the previous
30
30
  * JWT on each refresh, so a static `token` captured at construction
@@ -54,10 +54,10 @@ class RoboSystemsClients {
54
54
  constructor(config = {}) {
55
55
  // Get base URL from SDK client config or use provided/default
56
56
  const sdkConfig = client_gen_1.client.getConfig();
57
- // Facade REST calls run through the generated ops, which share this
58
- // module-level client — its `fetch` is the only interception point,
59
- // since the ops take no per-call transport. A caller that already
60
- // supplied one keeps it; we never override an explicit choice.
57
+ // Facade REST calls run through the generated ops on this module-level
58
+ // client. They pass their own baseUrl, credential and headers per call,
59
+ // but the transport is still this client's `fetch`. A caller that
60
+ // already supplied one keeps it; we never override an explicit choice.
61
61
  if (!sdkConfig.fetch) {
62
62
  client_gen_1.client.setConfig({
63
63
  fetch: (0, retry_1.createRetryingFetch)({
@@ -78,8 +78,8 @@ class RoboSystemsClients {
78
78
  token,
79
79
  tokenProvider,
80
80
  headers: config.headers,
81
- maxRetries: config.maxRetries || 5,
82
- retryDelay: config.retryDelay || 1000,
81
+ maxRetries: config.maxRetries ?? 5,
82
+ retryDelay: config.retryDelay ?? 1000,
83
83
  timeout: config.timeout,
84
84
  };
85
85
  // Every client that opens an SSE stream gets the tokenProvider too:
@@ -47,8 +47,8 @@ export interface RoboSystemsClientConfig {
47
47
  */
48
48
  token?: string
49
49
  /**
50
- * Dynamic credential callback invoked on every GraphQL request and
51
- * every SSE connect. When set, JWT refreshes are picked up
50
+ * Dynamic credential callback invoked on every GraphQL request, every
51
+ * facade REST write, and every SSE connect. When set, JWT refreshes are picked up
52
52
  * automatically — no need to rebuild or clear cached clients after a
53
53
  * refresh. Browser sessions need this: the backend revokes the previous
54
54
  * JWT on each refresh, so a static `token` captured at construction
@@ -95,10 +95,10 @@ export class RoboSystemsClients {
95
95
  // Get base URL from SDK client config or use provided/default
96
96
  const sdkConfig = client.getConfig()
97
97
 
98
- // Facade REST calls run through the generated ops, which share this
99
- // module-level client — its `fetch` is the only interception point,
100
- // since the ops take no per-call transport. A caller that already
101
- // supplied one keeps it; we never override an explicit choice.
98
+ // Facade REST calls run through the generated ops on this module-level
99
+ // client. They pass their own baseUrl, credential and headers per call,
100
+ // but the transport is still this client's `fetch`. A caller that
101
+ // already supplied one keeps it; we never override an explicit choice.
102
102
  if (!sdkConfig.fetch) {
103
103
  client.setConfig({
104
104
  fetch: createRetryingFetch({
@@ -122,8 +122,8 @@ export class RoboSystemsClients {
122
122
  token,
123
123
  tokenProvider,
124
124
  headers: config.headers,
125
- maxRetries: config.maxRetries || 5,
126
- retryDelay: config.retryDelay || 1000,
125
+ maxRetries: config.maxRetries ?? 5,
126
+ retryDelay: config.retryDelay ?? 1000,
127
127
  timeout: config.timeout,
128
128
  }
129
129
 
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Per-call transport options for the facades' REST calls.
3
+ *
4
+ * The generated ops default to the module-level `client` from
5
+ * `../sdk/client.gen`, which knows nothing of a facade's own `baseUrl` or
6
+ * credential. Facade REST calls (writes, Cypher queries, operator runs,
7
+ * operation status) pass these options per call instead, so they reach
8
+ * the same server, with the same credential, as the facade's GraphQL
9
+ * reads. They still run through the shared client, so
10
+ * its `fetch` (the retrying one `RoboSystemsClients` installs),
11
+ * interceptors and default headers keep applying underneath.
12
+ */
13
+ import type { GraphQLClientConfig } from './graphql/client';
14
+ export interface RestCallOptions {
15
+ baseUrl: string;
16
+ headers: Record<string, string>;
17
+ credentials?: 'include' | 'same-origin' | 'omit';
18
+ }
19
+ export type RestCallConfig = Pick<GraphQLClientConfig, 'baseUrl' | 'headers' | 'credentials' | 'token' | 'tokenProvider'>;
20
+ export declare function restCallOptions(config: RestCallConfig): Promise<RestCallOptions>;
21
+ /** Per-call options plus an `Idempotency-Key` header when one is given. */
22
+ export declare function withIdempotencyKey(options: RestCallOptions, idempotencyKey?: string | null): RestCallOptions;
@@ -0,0 +1,35 @@
1
+ 'use client';
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.restCallOptions = restCallOptions;
5
+ exports.withIdempotencyKey = withIdempotencyKey;
6
+ const client_1 = require("./graphql/client");
7
+ const CREDENTIAL_HEADERS = new Set(['x-api-key', 'authorization']);
8
+ async function restCallOptions(config) {
9
+ const headers = { ...(config.headers ?? {}) };
10
+ const token = await (0, client_1.resolveCredential)(config);
11
+ if (token) {
12
+ // The resolved credential replaces any the static headers carry, so
13
+ // exactly one is sent.
14
+ for (const name of Object.keys(headers)) {
15
+ if (CREDENTIAL_HEADERS.has(name.toLowerCase())) {
16
+ delete headers[name];
17
+ }
18
+ }
19
+ Object.assign(headers, (0, client_1.authHeaderFor)(token));
20
+ }
21
+ const options = { baseUrl: config.baseUrl.replace(/\/$/, ''), headers };
22
+ // Set only when configured: an explicit `undefined` would override the
23
+ // shared client's own `credentials`.
24
+ if (config.credentials) {
25
+ options.credentials = config.credentials;
26
+ }
27
+ return options;
28
+ }
29
+ /** Per-call options plus an `Idempotency-Key` header when one is given. */
30
+ function withIdempotencyKey(options, idempotencyKey) {
31
+ if (!idempotencyKey) {
32
+ return options;
33
+ }
34
+ return { ...options, headers: { ...options.headers, 'Idempotency-Key': idempotencyKey } };
35
+ }
@@ -0,0 +1,63 @@
1
+ 'use client'
2
+
3
+ /**
4
+ * Per-call transport options for the facades' REST calls.
5
+ *
6
+ * The generated ops default to the module-level `client` from
7
+ * `../sdk/client.gen`, which knows nothing of a facade's own `baseUrl` or
8
+ * credential. Facade REST calls (writes, Cypher queries, operator runs,
9
+ * operation status) pass these options per call instead, so they reach
10
+ * the same server, with the same credential, as the facade's GraphQL
11
+ * reads. They still run through the shared client, so
12
+ * its `fetch` (the retrying one `RoboSystemsClients` installs),
13
+ * interceptors and default headers keep applying underneath.
14
+ */
15
+
16
+ import type { GraphQLClientConfig } from './graphql/client'
17
+ import { authHeaderFor, resolveCredential } from './graphql/client'
18
+
19
+ export interface RestCallOptions {
20
+ baseUrl: string
21
+ headers: Record<string, string>
22
+ credentials?: 'include' | 'same-origin' | 'omit'
23
+ }
24
+
25
+ export type RestCallConfig = Pick<
26
+ GraphQLClientConfig,
27
+ 'baseUrl' | 'headers' | 'credentials' | 'token' | 'tokenProvider'
28
+ >
29
+
30
+ const CREDENTIAL_HEADERS = new Set(['x-api-key', 'authorization'])
31
+
32
+ export async function restCallOptions(config: RestCallConfig): Promise<RestCallOptions> {
33
+ const headers: Record<string, string> = { ...(config.headers ?? {}) }
34
+ const token = await resolveCredential(config)
35
+ if (token) {
36
+ // The resolved credential replaces any the static headers carry, so
37
+ // exactly one is sent.
38
+ for (const name of Object.keys(headers)) {
39
+ if (CREDENTIAL_HEADERS.has(name.toLowerCase())) {
40
+ delete headers[name]
41
+ }
42
+ }
43
+ Object.assign(headers, authHeaderFor(token))
44
+ }
45
+ const options: RestCallOptions = { baseUrl: config.baseUrl.replace(/\/$/, ''), headers }
46
+ // Set only when configured: an explicit `undefined` would override the
47
+ // shared client's own `credentials`.
48
+ if (config.credentials) {
49
+ options.credentials = config.credentials
50
+ }
51
+ return options
52
+ }
53
+
54
+ /** Per-call options plus an `Idempotency-Key` header when one is given. */
55
+ export function withIdempotencyKey(
56
+ options: RestCallOptions,
57
+ idempotencyKey?: string | null
58
+ ): RestCallOptions {
59
+ if (!idempotencyKey) {
60
+ return options
61
+ }
62
+ return { ...options, headers: { ...options.headers, 'Idempotency-Key': idempotencyKey } }
63
+ }
@@ -100,20 +100,25 @@ function createRetryingFetch(options = {}) {
100
100
  const retryDelay = Math.max(1, options.retryDelay ?? exports.DEFAULT_RETRY_DELAY_MS);
101
101
  const inner = options.fetch;
102
102
  return async (input, init) => {
103
- const send = () => (inner ?? fetch)(input, init);
103
+ // The generated SDK passes a `Request`, whose body a send consumes.
104
+ // Each attempt sends a clone, so the original stays readable for the
105
+ // next one.
106
+ const template = typeof Request !== 'undefined' && input instanceof Request ? input : null;
107
+ const signal = init?.signal ?? template?.signal;
108
+ const send = () => (inner ?? fetch)(template && maxRetries > 0 ? template.clone() : input, init);
104
109
  let response = await send();
105
110
  for (let attempt = 0; attempt < maxRetries; attempt++) {
106
111
  if (!exports.RETRY_STATUS_CODES.has(response.status) || !isReplayable(init)) {
107
112
  return response;
108
113
  }
109
- if (init?.signal?.aborted) {
114
+ if (signal?.aborted) {
110
115
  return response;
111
116
  }
112
117
  const delay = backoffMs(attempt, retryDelay, retryAfterMs(response));
113
118
  // The rejection body goes unused, but leaving it undrained keeps
114
119
  // the connection pinned in some runtimes.
115
120
  await response.body?.cancel().catch(() => { });
116
- await sleep(delay, init?.signal);
121
+ await sleep(delay, signal);
117
122
  response = await send();
118
123
  }
119
124
  return response;
@@ -111,21 +111,26 @@ export function createRetryingFetch(options: RetryOptions = {}): typeof fetch {
111
111
  const inner = options.fetch
112
112
 
113
113
  return async (input, init) => {
114
- const send = () => (inner ?? fetch)(input, init)
114
+ // The generated SDK passes a `Request`, whose body a send consumes.
115
+ // Each attempt sends a clone, so the original stays readable for the
116
+ // next one.
117
+ const template = typeof Request !== 'undefined' && input instanceof Request ? input : null
118
+ const signal = init?.signal ?? template?.signal
119
+ const send = () => (inner ?? fetch)(template && maxRetries > 0 ? template.clone() : input, init)
115
120
  let response = await send()
116
121
 
117
122
  for (let attempt = 0; attempt < maxRetries; attempt++) {
118
123
  if (!RETRY_STATUS_CODES.has(response.status) || !isReplayable(init)) {
119
124
  return response
120
125
  }
121
- if (init?.signal?.aborted) {
126
+ if (signal?.aborted) {
122
127
  return response
123
128
  }
124
129
  const delay = backoffMs(attempt, retryDelay, retryAfterMs(response))
125
130
  // The rejection body goes unused, but leaving it undrained keeps
126
131
  // the connection pinned in some runtimes.
127
132
  await response.body?.cancel().catch(() => {})
128
- await sleep(delay, init?.signal)
133
+ await sleep(delay, signal)
129
134
  response = await send()
130
135
  }
131
136
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@robosystems/client",
3
- "version": "2.5.3",
3
+ "version": "2.6.1",
4
4
  "description": "TypeScript client library for the RoboSystems financial intelligence platform",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -169,5 +169,13 @@
169
169
  "@graphql-typed-document-node/core": "^3.2.0",
170
170
  "graphql": "^16.13.2",
171
171
  "graphql-request": "^7.4.0"
172
+ },
173
+ "peerDependencies": {
174
+ "react": ">=16.8.0"
175
+ },
176
+ "peerDependenciesMeta": {
177
+ "react": {
178
+ "optional": true
179
+ }
172
180
  }
173
181
  }
@@ -158,6 +158,12 @@ export type AnalyticalStatementFactRow = {
158
158
  * Value
159
159
  */
160
160
  value?: number | null;
161
+ /**
162
+ * Unit
163
+ *
164
+ * The fact's unit, e.g. `USD` or `USD/shares`. A line a filer reports in two units (its own currency and a US-dollar translation) comes back once per unit.
165
+ */
166
+ unit?: string | null;
161
167
  /**
162
168
  * Start Date
163
169
  */
@@ -3350,7 +3356,7 @@ export type CreateViewRequest = {
3350
3356
  /**
3351
3357
  * Include Summary
3352
3358
  *
3353
- * Include summary statistics per element
3359
+ * Include summary statistics per element. An element reported in more than one unit has none.
3354
3360
  */
3355
3361
  include_summary?: boolean;
3356
3362
  /**
@@ -15435,6 +15441,12 @@ export type ResolveReconcilingItemRequest = {
15435
15441
  * Event id (evt_ prefixed) to resolve
15436
15442
  */
15437
15443
  event_id: string;
15444
+ /**
15445
+ * Expected Drift Detected At
15446
+ *
15447
+ * The `drift_detected_at` of the preview this resolution was decided on. Pass it: the resolution is refused when the item has been flagged again since, with a newer payload nobody has seen, and must be previewed again.
15448
+ */
15449
+ expected_drift_detected_at?: string | null;
15438
15450
  /**
15439
15451
  * Disposition
15440
15452
  *
package/sdk/types.gen.ts CHANGED
@@ -166,6 +166,12 @@ export type AnalyticalStatementFactRow = {
166
166
  * Value
167
167
  */
168
168
  value?: number | null;
169
+ /**
170
+ * Unit
171
+ *
172
+ * The fact's unit, e.g. `USD` or `USD/shares`. A line a filer reports in two units (its own currency and a US-dollar translation) comes back once per unit.
173
+ */
174
+ unit?: string | null;
169
175
  /**
170
176
  * Start Date
171
177
  */
@@ -3431,7 +3437,7 @@ export type CreateViewRequest = {
3431
3437
  /**
3432
3438
  * Include Summary
3433
3439
  *
3434
- * Include summary statistics per element
3440
+ * Include summary statistics per element. An element reported in more than one unit has none.
3435
3441
  */
3436
3442
  include_summary?: boolean;
3437
3443
  /**
@@ -15806,6 +15812,12 @@ export type ResolveReconcilingItemRequest = {
15806
15812
  * Event id (evt_ prefixed) to resolve
15807
15813
  */
15808
15814
  event_id: string;
15815
+ /**
15816
+ * Expected Drift Detected At
15817
+ *
15818
+ * The `drift_detected_at` of the preview this resolution was decided on. Pass it: the resolution is refused when the item has been flagged again since, with a newer payload nobody has seen, and must be previewed again.
15819
+ */
15820
+ expected_drift_detected_at?: string | null;
15809
15821
  /**
15810
15822
  * Disposition
15811
15823
  *
package/types.gen.d.ts CHANGED
@@ -158,6 +158,12 @@ export type AnalyticalStatementFactRow = {
158
158
  * Value
159
159
  */
160
160
  value?: number | null;
161
+ /**
162
+ * Unit
163
+ *
164
+ * The fact's unit, e.g. `USD` or `USD/shares`. A line a filer reports in two units (its own currency and a US-dollar translation) comes back once per unit.
165
+ */
166
+ unit?: string | null;
161
167
  /**
162
168
  * Start Date
163
169
  */
@@ -3350,7 +3356,7 @@ export type CreateViewRequest = {
3350
3356
  /**
3351
3357
  * Include Summary
3352
3358
  *
3353
- * Include summary statistics per element
3359
+ * Include summary statistics per element. An element reported in more than one unit has none.
3354
3360
  */
3355
3361
  include_summary?: boolean;
3356
3362
  /**
@@ -15435,6 +15441,12 @@ export type ResolveReconcilingItemRequest = {
15435
15441
  * Event id (evt_ prefixed) to resolve
15436
15442
  */
15437
15443
  event_id: string;
15444
+ /**
15445
+ * Expected Drift Detected At
15446
+ *
15447
+ * The `drift_detected_at` of the preview this resolution was decided on. Pass it: the resolution is refused when the item has been flagged again since, with a newer payload nobody has seen, and must be previewed again.
15448
+ */
15449
+ expected_drift_detected_at?: string | null;
15438
15450
  /**
15439
15451
  * Disposition
15440
15452
  *
package/types.gen.ts CHANGED
@@ -166,6 +166,12 @@ export type AnalyticalStatementFactRow = {
166
166
  * Value
167
167
  */
168
168
  value?: number | null;
169
+ /**
170
+ * Unit
171
+ *
172
+ * The fact's unit, e.g. `USD` or `USD/shares`. A line a filer reports in two units (its own currency and a US-dollar translation) comes back once per unit.
173
+ */
174
+ unit?: string | null;
169
175
  /**
170
176
  * Start Date
171
177
  */
@@ -3431,7 +3437,7 @@ export type CreateViewRequest = {
3431
3437
  /**
3432
3438
  * Include Summary
3433
3439
  *
3434
- * Include summary statistics per element
3440
+ * Include summary statistics per element. An element reported in more than one unit has none.
3435
3441
  */
3436
3442
  include_summary?: boolean;
3437
3443
  /**
@@ -15806,6 +15812,12 @@ export type ResolveReconcilingItemRequest = {
15806
15812
  * Event id (evt_ prefixed) to resolve
15807
15813
  */
15808
15814
  event_id: string;
15815
+ /**
15816
+ * Expected Drift Detected At
15817
+ *
15818
+ * The `drift_detected_at` of the preview this resolution was decided on. Pass it: the resolution is refused when the item has been flagged again since, with a newer payload nobody has seen, and must be previewed again.
15819
+ */
15820
+ expected_drift_detected_at?: string | null;
15809
15821
  /**
15810
15822
  * Disposition
15811
15823
  *