@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,30 +1,49 @@
1
1
  /**
2
- * Configuration for SDK extensions
2
+ * Configuration for SDK clients
3
3
  * Provides centralized configuration for CORS, credentials, and other settings
4
4
  */
5
- export interface SDKExtensionsConfig {
5
+ import type { TokenProvider } from './graphql/client';
6
+ export interface SDKClientConfig {
6
7
  baseUrl?: string;
7
8
  credentials?: 'include' | 'same-origin' | 'omit';
8
9
  headers?: Record<string, string>;
10
+ /**
11
+ * Static credential captured at singleton construction. Fine for
12
+ * long-lived API keys — use `tokenProvider` instead when the
13
+ * JWT can rotate mid-session (browser login flows).
14
+ *
15
+ * When both `token` and `tokenProvider` are set, `tokenProvider`
16
+ * wins — the static value is effectively ignored. Pass
17
+ * `tokenProvider: undefined` to explicitly switch back to the
18
+ * static-token path.
19
+ */
9
20
  token?: string;
21
+ /**
22
+ * Dynamic credential callback, invoked on every GraphQL request.
23
+ * When set, JWT refresh flows through automatically: the lazy
24
+ * `clients` singleton picks it up at construction, and each
25
+ * request consults the callback for the current token instead of
26
+ * reusing a stale captured value.
27
+ */
28
+ tokenProvider?: TokenProvider;
10
29
  timeout?: number;
11
30
  maxRetries?: number;
12
31
  retryDelay?: number;
13
32
  }
14
33
  /**
15
- * Set global configuration for SDK extensions
34
+ * Set global configuration for SDK clients
16
35
  * @param config Partial configuration to merge with defaults
17
36
  */
18
- export declare function setSDKExtensionsConfig(config: Partial<SDKExtensionsConfig>): void;
37
+ export declare function setSDKClientConfig(config: Partial<SDKClientConfig>): void;
19
38
  /**
20
- * Get current SDK extensions configuration
39
+ * Get current SDK clients configuration
21
40
  * @returns Current configuration
22
41
  */
23
- export declare function getSDKExtensionsConfig(): SDKExtensionsConfig;
42
+ export declare function getSDKClientConfig(): SDKClientConfig;
24
43
  /**
25
44
  * Reset configuration to defaults
26
45
  */
27
- export declare function resetSDKExtensionsConfig(): void;
46
+ export declare function resetSDKClientConfig(): void;
28
47
  /**
29
48
  * Extract JWT token from Authorization header
30
49
  * @param authHeader Authorization header value
@@ -44,14 +63,14 @@ export declare function isValidJWT(token: string | undefined): boolean;
44
63
  */
45
64
  export declare function extractTokenFromSDKClient(): string | undefined;
46
65
  /**
47
- * Configure SDK extensions for JWT authentication
66
+ * Configure SDK clients for JWT authentication
48
67
  * @param token JWT token
49
68
  * @param config Additional configuration options
50
69
  */
51
- export declare function configureWithJWT(token: string, config?: Partial<SDKExtensionsConfig>): void;
70
+ export declare function configureWithJWT(token: string, config?: Partial<SDKClientConfig>): void;
52
71
  /**
53
72
  * Get configuration for a specific environment
54
73
  * @param env Environment name (production, staging, development)
55
74
  * @returns Environment-specific configuration
56
75
  */
57
- export declare function getEnvironmentConfig(env?: 'production' | 'staging' | 'development'): SDKExtensionsConfig;
76
+ export declare function getEnvironmentConfig(env?: 'production' | 'staging' | 'development'): SDKClientConfig;
@@ -1,9 +1,9 @@
1
1
  'use client';
2
2
  "use strict";
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.setSDKExtensionsConfig = setSDKExtensionsConfig;
5
- exports.getSDKExtensionsConfig = getSDKExtensionsConfig;
6
- exports.resetSDKExtensionsConfig = resetSDKExtensionsConfig;
4
+ exports.setSDKClientConfig = setSDKClientConfig;
5
+ exports.getSDKClientConfig = getSDKClientConfig;
6
+ exports.resetSDKClientConfig = resetSDKClientConfig;
7
7
  exports.extractJWTFromHeader = extractJWTFromHeader;
8
8
  exports.isValidJWT = isValidJWT;
9
9
  exports.extractTokenFromSDKClient = extractTokenFromSDKClient;
@@ -21,26 +21,26 @@ const defaultConfig = {
21
21
  // Global configuration singleton
22
22
  let globalConfig = { ...defaultConfig };
23
23
  /**
24
- * Set global configuration for SDK extensions
24
+ * Set global configuration for SDK clients
25
25
  * @param config Partial configuration to merge with defaults
26
26
  */
27
- function setSDKExtensionsConfig(config) {
27
+ function setSDKClientConfig(config) {
28
28
  globalConfig = {
29
29
  ...globalConfig,
30
30
  ...config,
31
31
  };
32
32
  }
33
33
  /**
34
- * Get current SDK extensions configuration
34
+ * Get current SDK clients configuration
35
35
  * @returns Current configuration
36
36
  */
37
- function getSDKExtensionsConfig() {
37
+ function getSDKClientConfig() {
38
38
  return { ...globalConfig };
39
39
  }
40
40
  /**
41
41
  * Reset configuration to defaults
42
42
  */
43
- function resetSDKExtensionsConfig() {
43
+ function resetSDKClientConfig() {
44
44
  globalConfig = { ...defaultConfig };
45
45
  }
46
46
  /**
@@ -82,7 +82,7 @@ function isValidJWT(token) {
82
82
  function extractTokenFromSDKClient() {
83
83
  // Import dynamically to avoid circular dependency
84
84
  const { client } = require('../client.gen');
85
- const sdkConfig = getSDKExtensionsConfig();
85
+ const sdkConfig = getSDKClientConfig();
86
86
  // Priority 1: Use explicitly configured token
87
87
  if (sdkConfig.token) {
88
88
  return sdkConfig.token;
@@ -101,7 +101,7 @@ function extractTokenFromSDKClient() {
101
101
  return undefined;
102
102
  }
103
103
  /**
104
- * Configure SDK extensions for JWT authentication
104
+ * Configure SDK clients for JWT authentication
105
105
  * @param token JWT token
106
106
  * @param config Additional configuration options
107
107
  */
@@ -109,7 +109,7 @@ function configureWithJWT(token, config) {
109
109
  if (!isValidJWT(token)) {
110
110
  console.warn('Warning: Provided JWT token does not appear to be valid');
111
111
  }
112
- setSDKExtensionsConfig({
112
+ setSDKClientConfig({
113
113
  ...config,
114
114
  token,
115
115
  // When using JWT, typically don't need cookies
@@ -1,22 +1,42 @@
1
1
  'use client'
2
2
 
3
3
  /**
4
- * Configuration for SDK extensions
4
+ * Configuration for SDK clients
5
5
  * Provides centralized configuration for CORS, credentials, and other settings
6
6
  */
7
7
 
8
- export interface SDKExtensionsConfig {
8
+ import type { TokenProvider } from './graphql/client'
9
+
10
+ export interface SDKClientConfig {
9
11
  baseUrl?: string
10
12
  credentials?: 'include' | 'same-origin' | 'omit'
11
13
  headers?: Record<string, string>
12
- token?: string // JWT token for authentication
14
+ /**
15
+ * Static credential captured at singleton construction. Fine for
16
+ * long-lived API keys — use `tokenProvider` instead when the
17
+ * JWT can rotate mid-session (browser login flows).
18
+ *
19
+ * When both `token` and `tokenProvider` are set, `tokenProvider`
20
+ * wins — the static value is effectively ignored. Pass
21
+ * `tokenProvider: undefined` to explicitly switch back to the
22
+ * static-token path.
23
+ */
24
+ token?: string
25
+ /**
26
+ * Dynamic credential callback, invoked on every GraphQL request.
27
+ * When set, JWT refresh flows through automatically: the lazy
28
+ * `clients` singleton picks it up at construction, and each
29
+ * request consults the callback for the current token instead of
30
+ * reusing a stale captured value.
31
+ */
32
+ tokenProvider?: TokenProvider
13
33
  timeout?: number
14
34
  maxRetries?: number
15
35
  retryDelay?: number
16
36
  }
17
37
 
18
38
  // Default configuration
19
- const defaultConfig: SDKExtensionsConfig = {
39
+ const defaultConfig: SDKClientConfig = {
20
40
  baseUrl: process.env.NEXT_PUBLIC_API_URL || 'http://localhost:8000',
21
41
  credentials: 'include',
22
42
  token: undefined, // Will be set from environment or programmatically
@@ -26,13 +46,13 @@ const defaultConfig: SDKExtensionsConfig = {
26
46
  }
27
47
 
28
48
  // Global configuration singleton
29
- let globalConfig: SDKExtensionsConfig = { ...defaultConfig }
49
+ let globalConfig: SDKClientConfig = { ...defaultConfig }
30
50
 
31
51
  /**
32
- * Set global configuration for SDK extensions
52
+ * Set global configuration for SDK clients
33
53
  * @param config Partial configuration to merge with defaults
34
54
  */
35
- export function setSDKExtensionsConfig(config: Partial<SDKExtensionsConfig>) {
55
+ export function setSDKClientConfig(config: Partial<SDKClientConfig>) {
36
56
  globalConfig = {
37
57
  ...globalConfig,
38
58
  ...config,
@@ -40,17 +60,17 @@ export function setSDKExtensionsConfig(config: Partial<SDKExtensionsConfig>) {
40
60
  }
41
61
 
42
62
  /**
43
- * Get current SDK extensions configuration
63
+ * Get current SDK clients configuration
44
64
  * @returns Current configuration
45
65
  */
46
- export function getSDKExtensionsConfig(): SDKExtensionsConfig {
66
+ export function getSDKClientConfig(): SDKClientConfig {
47
67
  return { ...globalConfig }
48
68
  }
49
69
 
50
70
  /**
51
71
  * Reset configuration to defaults
52
72
  */
53
- export function resetSDKExtensionsConfig() {
73
+ export function resetSDKClientConfig() {
54
74
  globalConfig = { ...defaultConfig }
55
75
  }
56
76
 
@@ -96,7 +116,7 @@ export function extractTokenFromSDKClient(): string | undefined {
96
116
  // Import dynamically to avoid circular dependency
97
117
  const { client } = require('../client.gen')
98
118
 
99
- const sdkConfig = getSDKExtensionsConfig()
119
+ const sdkConfig = getSDKClientConfig()
100
120
 
101
121
  // Priority 1: Use explicitly configured token
102
122
  if (sdkConfig.token) {
@@ -119,16 +139,16 @@ export function extractTokenFromSDKClient(): string | undefined {
119
139
  }
120
140
 
121
141
  /**
122
- * Configure SDK extensions for JWT authentication
142
+ * Configure SDK clients for JWT authentication
123
143
  * @param token JWT token
124
144
  * @param config Additional configuration options
125
145
  */
126
- export function configureWithJWT(token: string, config?: Partial<SDKExtensionsConfig>) {
146
+ export function configureWithJWT(token: string, config?: Partial<SDKClientConfig>) {
127
147
  if (!isValidJWT(token)) {
128
148
  console.warn('Warning: Provided JWT token does not appear to be valid')
129
149
  }
130
150
 
131
- setSDKExtensionsConfig({
151
+ setSDKClientConfig({
132
152
  ...config,
133
153
  token,
134
154
  // When using JWT, typically don't need cookies
@@ -143,8 +163,8 @@ export function configureWithJWT(token: string, config?: Partial<SDKExtensionsCo
143
163
  */
144
164
  export function getEnvironmentConfig(
145
165
  env: 'production' | 'staging' | 'development' = 'development'
146
- ): SDKExtensionsConfig {
147
- const baseConfigs: Record<string, Partial<SDKExtensionsConfig>> = {
166
+ ): SDKClientConfig {
167
+ const baseConfigs: Record<string, Partial<SDKClientConfig>> = {
148
168
  production: {
149
169
  baseUrl: process.env.NEXT_PUBLIC_API_URL || 'https://api.robosystems.ai',
150
170
  credentials: 'include',
@@ -0,0 +1,82 @@
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 clients/graphql/queries/.
20
+ */
21
+ import { GraphQLClient } from 'graphql-request';
22
+ /**
23
+ * Callback that returns the current auth credential on demand.
24
+ *
25
+ * Use this instead of the static `token` field when the credential
26
+ * can rotate during the lifetime of the client — the primary case
27
+ * is short-lived JWTs that auto-refresh from browser token storage.
28
+ * The provider is invoked on **every** GraphQL request, so the
29
+ * returned value should be cheap to obtain (a localStorage read or
30
+ * an in-memory lookup, not a network call if avoidable).
31
+ *
32
+ * May return `null`/`undefined` to indicate "no credential available
33
+ * right now" — the request will be sent unauthenticated in that
34
+ * case, which lets the caller distinguish auth-expired errors from
35
+ * never-authed errors at the transport layer.
36
+ */
37
+ export type TokenProvider = () => string | null | undefined | Promise<string | null | undefined>;
38
+ export interface GraphQLClientConfig {
39
+ baseUrl: string;
40
+ /**
41
+ * Static credential captured at construction time. Use this when
42
+ * the token won't rotate (e.g. CLI/server flows using a long-lived
43
+ * API key). For JWT flows prefer `tokenProvider` so refreshes are
44
+ * picked up without rebuilding the client.
45
+ */
46
+ token?: string;
47
+ /**
48
+ * Dynamic credential callback, read on every request. Wins over
49
+ * `token` when both are set. See `TokenProvider` for semantics.
50
+ */
51
+ tokenProvider?: TokenProvider;
52
+ headers?: Record<string, string>;
53
+ credentials?: 'include' | 'same-origin' | 'omit';
54
+ }
55
+ /**
56
+ * Build a new GraphQL client for the given graph. Prefer
57
+ * `GraphQLClientCache.get(graphId)` in facade code — this is the raw
58
+ * factory and bypasses the cache.
59
+ */
60
+ export declare function createGraphQLClient(config: GraphQLClientConfig, graphId: string): GraphQLClient;
61
+ /**
62
+ * Per-graph cache of GraphQL clients. Facade clients own one instance of
63
+ * this and call `.get(graphId)` on every GraphQL method — cheap after the
64
+ * first call per graph.
65
+ */
66
+ export declare class GraphQLClientCache {
67
+ private config;
68
+ private clients;
69
+ constructor(config: GraphQLClientConfig);
70
+ get(graphId: string): GraphQLClient;
71
+ /**
72
+ * Drop all cached clients. Only needed when swapping **static**
73
+ * credentials — e.g. replacing the `token` field on a long-lived
74
+ * facade between tenants, or resetting a CLI session. When the
75
+ * cache was built from a `tokenProvider`, rotation is handled
76
+ * per-request inside `requestMiddleware` and `clear()` is a no-op
77
+ * for auth purposes (the cached `GraphQLClient` instances keep
78
+ * using the same provider reference and will pick up the next
79
+ * token automatically).
80
+ */
81
+ clear(): void;
82
+ }
@@ -0,0 +1,148 @@
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 clients/graphql/queries/.
25
+ */
26
+ const graphql_request_1 = require("graphql-request");
27
+ /**
28
+ * Apply a credential to an in-progress request's headers, choosing
29
+ * the right header based on token shape:
30
+ *
31
+ * - `rfs…` prefix → `X-API-Key` (long-lived API key, validated
32
+ * against the database's api_keys table).
33
+ * - anything else → `Authorization: Bearer …` (short-lived JWT,
34
+ * validated by JWT middleware).
35
+ *
36
+ * The two credential types are NOT interchangeable at the backend —
37
+ * sending a JWT as `X-API-Key` or an API key as Bearer both 401.
38
+ */
39
+ function applyAuthHeader(headers, token) {
40
+ if (token.startsWith('rfs')) {
41
+ headers.set('X-API-Key', token);
42
+ }
43
+ else {
44
+ headers.set('Authorization', `Bearer ${token}`);
45
+ }
46
+ }
47
+ /**
48
+ * Build a new GraphQL client for the given graph. Prefer
49
+ * `GraphQLClientCache.get(graphId)` in facade code — this is the raw
50
+ * factory and bypasses the cache.
51
+ */
52
+ function createGraphQLClient(config, graphId) {
53
+ if (!graphId) {
54
+ throw new Error('createGraphQLClient requires a non-empty graphId');
55
+ }
56
+ const url = `${config.baseUrl.replace(/\/$/, '')}/extensions/${graphId}/graphql`;
57
+ const staticHeaders = {
58
+ ...(config.headers ?? {}),
59
+ };
60
+ // Dynamic-token path: defer credential injection to a per-request
61
+ // middleware so JWT refreshes are picked up without rebuilding or
62
+ // clearing the client. This is the recommended path for browser
63
+ // flows where the token in localStorage rotates every ~30 minutes.
64
+ if (config.tokenProvider) {
65
+ const providerFn = config.tokenProvider;
66
+ return new graphql_request_1.GraphQLClient(url, {
67
+ headers: staticHeaders,
68
+ credentials: config.credentials,
69
+ requestMiddleware: async (request) => {
70
+ let token;
71
+ try {
72
+ token = await providerFn();
73
+ }
74
+ catch (err) {
75
+ // A provider failure shouldn't crash the request — fall
76
+ // through unauthenticated so the backend returns a clean
77
+ // 401, which is easier to diagnose than a thrown middleware.
78
+ // We still log a breadcrumb so the failure is visible in
79
+ // devtools/log aggregators instead of silently disappearing;
80
+ // silently swallowing provider bugs in production is worse
81
+ // than the noise.
82
+ console.warn('[RoboSystems SDK] tokenProvider threw — sending unauthenticated request:', err);
83
+ token = undefined;
84
+ }
85
+ if (!token) {
86
+ return request;
87
+ }
88
+ // `request.headers` is a HeadersInit (Headers | string[][] |
89
+ // Record<string, string>), so normalize via Headers before
90
+ // mutating. Spreading it directly loses keys when it's a
91
+ // Headers instance.
92
+ const merged = new Headers(request.headers);
93
+ applyAuthHeader(merged, token);
94
+ return { ...request, headers: merged };
95
+ },
96
+ });
97
+ }
98
+ // Static-token path: pick the right header at construction time.
99
+ // Suitable for long-lived API keys that never rotate.
100
+ if (config.token) {
101
+ const headers = new Headers(staticHeaders);
102
+ applyAuthHeader(headers, config.token);
103
+ return new graphql_request_1.GraphQLClient(url, {
104
+ headers,
105
+ credentials: config.credentials,
106
+ });
107
+ }
108
+ // No credentials at all — used by unauthenticated introspection
109
+ // queries against public dev endpoints.
110
+ return new graphql_request_1.GraphQLClient(url, {
111
+ headers: staticHeaders,
112
+ credentials: config.credentials,
113
+ });
114
+ }
115
+ /**
116
+ * Per-graph cache of GraphQL clients. Facade clients own one instance of
117
+ * this and call `.get(graphId)` on every GraphQL method — cheap after the
118
+ * first call per graph.
119
+ */
120
+ class GraphQLClientCache {
121
+ constructor(config) {
122
+ this.config = config;
123
+ this.clients = new Map();
124
+ }
125
+ get(graphId) {
126
+ const existing = this.clients.get(graphId);
127
+ if (existing !== undefined) {
128
+ return existing;
129
+ }
130
+ const client = createGraphQLClient(this.config, graphId);
131
+ this.clients.set(graphId, client);
132
+ return client;
133
+ }
134
+ /**
135
+ * Drop all cached clients. Only needed when swapping **static**
136
+ * credentials — e.g. replacing the `token` field on a long-lived
137
+ * facade between tenants, or resetting a CLI session. When the
138
+ * cache was built from a `tokenProvider`, rotation is handled
139
+ * per-request inside `requestMiddleware` and `clear()` is a no-op
140
+ * for auth purposes (the cached `GraphQLClient` instances keep
141
+ * using the same provider reference and will pick up the next
142
+ * token automatically).
143
+ */
144
+ clear() {
145
+ this.clients.clear();
146
+ }
147
+ }
148
+ exports.GraphQLClientCache = GraphQLClientCache;