@robosystems/client 0.2.48 → 0.3.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/extensions/InvestorClient.d.ts +91 -0
- package/extensions/InvestorClient.js +223 -0
- package/extensions/InvestorClient.ts +501 -0
- package/extensions/LedgerClient.d.ts +213 -165
- package/extensions/LedgerClient.js +315 -393
- package/extensions/LedgerClient.ts +887 -564
- package/extensions/ReportClient.d.ts +77 -115
- package/extensions/ReportClient.js +124 -211
- package/extensions/ReportClient.ts +298 -358
- package/extensions/config.js +1 -1
- package/extensions/config.ts +1 -1
- package/extensions/graphql/client.d.ts +46 -0
- package/extensions/graphql/client.js +75 -0
- package/extensions/graphql/client.ts +82 -0
- package/extensions/graphql/generated/graphql.d.ts +1786 -0
- package/extensions/graphql/generated/graphql.js +2671 -0
- package/extensions/graphql/generated/graphql.ts +4491 -0
- package/extensions/graphql/queries/investor/holdings.d.ts +8 -0
- package/extensions/graphql/queries/investor/holdings.js +36 -0
- package/extensions/graphql/queries/investor/holdings.ts +34 -0
- package/extensions/graphql/queries/investor/portfolio.d.ts +4 -0
- package/extensions/graphql/queries/investor/portfolio.js +21 -0
- package/extensions/graphql/queries/investor/portfolio.ts +19 -0
- package/extensions/graphql/queries/investor/portfolios.d.ts +4 -0
- package/extensions/graphql/queries/investor/portfolios.js +29 -0
- package/extensions/graphql/queries/investor/portfolios.ts +27 -0
- package/extensions/graphql/queries/investor/position.d.ts +4 -0
- package/extensions/graphql/queries/investor/position.js +33 -0
- package/extensions/graphql/queries/investor/position.ts +31 -0
- package/extensions/graphql/queries/investor/positions.d.ts +8 -0
- package/extensions/graphql/queries/investor/positions.js +57 -0
- package/extensions/graphql/queries/investor/positions.ts +55 -0
- package/extensions/graphql/queries/investor/securities.d.ts +8 -0
- package/extensions/graphql/queries/investor/securities.js +50 -0
- package/extensions/graphql/queries/investor/securities.ts +48 -0
- package/extensions/graphql/queries/investor/security.d.ts +4 -0
- package/extensions/graphql/queries/investor/security.js +26 -0
- package/extensions/graphql/queries/investor/security.ts +24 -0
- package/extensions/graphql/queries/ledger/accountRollups.d.ts +7 -0
- package/extensions/graphql/queries/ledger/accountRollups.js +36 -0
- package/extensions/graphql/queries/ledger/accountRollups.ts +34 -0
- package/extensions/graphql/queries/ledger/accountTree.d.ts +11 -0
- package/extensions/graphql/queries/ledger/accountTree.js +61 -0
- package/extensions/graphql/queries/ledger/accountTree.ts +59 -0
- package/extensions/graphql/queries/ledger/accounts.d.ts +8 -0
- package/extensions/graphql/queries/ledger/accounts.js +45 -0
- package/extensions/graphql/queries/ledger/accounts.ts +43 -0
- package/extensions/graphql/queries/ledger/closingBookStructures.d.ts +6 -0
- package/extensions/graphql/queries/ledger/closingBookStructures.js +27 -0
- package/extensions/graphql/queries/ledger/closingBookStructures.ts +25 -0
- package/extensions/graphql/queries/ledger/elements.d.ts +6 -0
- package/extensions/graphql/queries/ledger/elements.js +56 -0
- package/extensions/graphql/queries/ledger/elements.ts +54 -0
- package/extensions/graphql/queries/ledger/entities.d.ts +7 -0
- package/extensions/graphql/queries/ledger/entities.js +31 -0
- package/extensions/graphql/queries/ledger/entities.ts +29 -0
- package/extensions/graphql/queries/ledger/entity.d.ts +14 -0
- package/extensions/graphql/queries/ledger/entity.js +55 -0
- package/extensions/graphql/queries/ledger/entity.ts +54 -0
- package/extensions/graphql/queries/ledger/fiscalCalendar.d.ts +8 -0
- package/extensions/graphql/queries/ledger/fiscalCalendar.js +35 -0
- package/extensions/graphql/queries/ledger/fiscalCalendar.ts +33 -0
- package/extensions/graphql/queries/ledger/mappedTrialBalance.d.ts +9 -0
- package/extensions/graphql/queries/ledger/mappedTrialBalance.js +29 -0
- package/extensions/graphql/queries/ledger/mappedTrialBalance.ts +27 -0
- package/extensions/graphql/queries/ledger/mapping.d.ts +5 -0
- package/extensions/graphql/queries/ledger/mapping.js +35 -0
- package/extensions/graphql/queries/ledger/mapping.ts +33 -0
- package/extensions/graphql/queries/ledger/mappingCoverage.d.ts +5 -0
- package/extensions/graphql/queries/ledger/mappingCoverage.js +22 -0
- package/extensions/graphql/queries/ledger/mappingCoverage.ts +20 -0
- package/extensions/graphql/queries/ledger/mappings.d.ts +6 -0
- package/extensions/graphql/queries/ledger/mappings.js +23 -0
- package/extensions/graphql/queries/ledger/mappings.ts +21 -0
- package/extensions/graphql/queries/ledger/periodCloseStatus.d.ts +6 -0
- package/extensions/graphql/queries/ledger/periodCloseStatus.js +29 -0
- package/extensions/graphql/queries/ledger/periodCloseStatus.ts +27 -0
- package/extensions/graphql/queries/ledger/periodDrafts.d.ts +8 -0
- package/extensions/graphql/queries/ledger/periodDrafts.js +45 -0
- package/extensions/graphql/queries/ledger/periodDrafts.ts +43 -0
- package/extensions/graphql/queries/ledger/publishList.d.ts +5 -0
- package/extensions/graphql/queries/ledger/publishList.js +29 -0
- package/extensions/graphql/queries/ledger/publishList.ts +27 -0
- package/extensions/graphql/queries/ledger/publishLists.d.ts +5 -0
- package/extensions/graphql/queries/ledger/publishLists.js +29 -0
- package/extensions/graphql/queries/ledger/publishLists.ts +27 -0
- package/extensions/graphql/queries/ledger/report.d.ts +5 -0
- package/extensions/graphql/queries/ledger/report.js +40 -0
- package/extensions/graphql/queries/ledger/report.ts +38 -0
- package/extensions/graphql/queries/ledger/reportingTaxonomy.d.ts +6 -0
- package/extensions/graphql/queries/ledger/reportingTaxonomy.js +27 -0
- package/extensions/graphql/queries/ledger/reportingTaxonomy.ts +25 -0
- package/extensions/graphql/queries/ledger/reports.d.ts +8 -0
- package/extensions/graphql/queries/ledger/reports.js +45 -0
- package/extensions/graphql/queries/ledger/reports.ts +43 -0
- package/extensions/graphql/queries/ledger/scheduleFacts.d.ts +7 -0
- package/extensions/graphql/queries/ledger/scheduleFacts.js +24 -0
- package/extensions/graphql/queries/ledger/scheduleFacts.ts +22 -0
- package/extensions/graphql/queries/ledger/schedules.d.ts +6 -0
- package/extensions/graphql/queries/ledger/schedules.js +24 -0
- package/extensions/graphql/queries/ledger/schedules.ts +22 -0
- package/extensions/graphql/queries/ledger/statement.d.ts +9 -0
- package/extensions/graphql/queries/ledger/statement.js +43 -0
- package/extensions/graphql/queries/ledger/statement.ts +41 -0
- package/extensions/graphql/queries/ledger/structures.d.ts +5 -0
- package/extensions/graphql/queries/ledger/structures.js +22 -0
- package/extensions/graphql/queries/ledger/structures.ts +20 -0
- package/extensions/graphql/queries/ledger/summary.d.ts +7 -0
- package/extensions/graphql/queries/ledger/summary.js +25 -0
- package/extensions/graphql/queries/ledger/summary.ts +23 -0
- package/extensions/graphql/queries/ledger/taxonomies.d.ts +5 -0
- package/extensions/graphql/queries/ledger/taxonomies.js +28 -0
- package/extensions/graphql/queries/ledger/taxonomies.ts +26 -0
- package/extensions/graphql/queries/ledger/transaction.d.ts +6 -0
- package/extensions/graphql/queries/ledger/transaction.js +49 -0
- package/extensions/graphql/queries/ledger/transaction.ts +47 -0
- package/extensions/graphql/queries/ledger/transactions.d.ts +7 -0
- package/extensions/graphql/queries/ledger/transactions.js +49 -0
- package/extensions/graphql/queries/ledger/transactions.ts +47 -0
- package/extensions/graphql/queries/ledger/trialBalance.d.ts +7 -0
- package/extensions/graphql/queries/ledger/trialBalance.js +28 -0
- package/extensions/graphql/queries/ledger/trialBalance.ts +26 -0
- package/extensions/graphql/queries/ledger/unmappedElements.d.ts +8 -0
- package/extensions/graphql/queries/ledger/unmappedElements.js +29 -0
- package/extensions/graphql/queries/ledger/unmappedElements.ts +27 -0
- package/extensions/hooks.d.ts +1 -1
- package/extensions/index.d.ts +5 -1
- package/extensions/index.js +13 -1
- package/extensions/index.ts +14 -0
- package/index.ts +2 -2
- package/package.json +14 -5
- package/sdk/index.d.ts +2 -2
- package/sdk/index.js +38 -65
- package/sdk/index.ts +2 -2
- package/sdk/sdk.gen.d.ts +101 -220
- package/sdk/sdk.gen.js +251 -445
- package/sdk/sdk.gen.ts +216 -409
- package/sdk/types.gen.d.ts +4586 -7045
- package/sdk/types.gen.ts +4702 -7334
- package/sdk.gen.d.ts +101 -220
- package/sdk.gen.js +251 -445
- package/sdk.gen.ts +216 -409
- package/types.gen.d.ts +4586 -7045
- package/types.gen.ts +4702 -7334
- package/extensions/AgentClient.test.ts +0 -403
- package/extensions/LedgerClient.test.ts +0 -1138
- package/extensions/OperationClient.test.ts +0 -365
- package/extensions/QueryClient.test.ts +0 -432
- package/extensions/ReportClient.test.ts +0 -828
- package/extensions/SSEClient.test.ts +0 -375
- package/extensions/config.test.ts +0 -199
- package/extensions/hooks.test.ts +0 -373
- package/extensions/index.test.ts +0 -420
- package/sdk-extensions/AgentClient.d.ts +0 -82
- package/sdk-extensions/AgentClient.js +0 -218
- package/sdk-extensions/AgentClient.test.ts +0 -403
- package/sdk-extensions/AgentClient.ts +0 -321
- package/sdk-extensions/LedgerClient.d.ts +0 -242
- package/sdk-extensions/LedgerClient.js +0 -496
- package/sdk-extensions/LedgerClient.test.ts +0 -1138
- package/sdk-extensions/LedgerClient.ts +0 -800
- package/sdk-extensions/OperationClient.d.ts +0 -65
- package/sdk-extensions/OperationClient.js +0 -251
- package/sdk-extensions/OperationClient.test.ts +0 -365
- package/sdk-extensions/OperationClient.ts +0 -324
- package/sdk-extensions/QueryClient.d.ts +0 -52
- package/sdk-extensions/QueryClient.js +0 -313
- package/sdk-extensions/QueryClient.test.ts +0 -432
- package/sdk-extensions/QueryClient.ts +0 -420
- package/sdk-extensions/README.md +0 -901
- package/sdk-extensions/ReportClient.d.ts +0 -151
- package/sdk-extensions/ReportClient.js +0 -278
- package/sdk-extensions/ReportClient.test.ts +0 -828
- package/sdk-extensions/ReportClient.ts +0 -486
- package/sdk-extensions/SSEClient.d.ts +0 -62
- package/sdk-extensions/SSEClient.js +0 -154
- package/sdk-extensions/SSEClient.test.ts +0 -375
- package/sdk-extensions/SSEClient.ts +0 -210
- package/sdk-extensions/config.d.ts +0 -57
- package/sdk-extensions/config.js +0 -152
- package/sdk-extensions/config.test.ts +0 -199
- package/sdk-extensions/config.ts +0 -175
- package/sdk-extensions/hooks.d.ts +0 -110
- package/sdk-extensions/hooks.js +0 -384
- package/sdk-extensions/hooks.test.ts +0 -373
- package/sdk-extensions/hooks.ts +0 -459
- package/sdk-extensions/index.d.ts +0 -63
- package/sdk-extensions/index.js +0 -164
- package/sdk-extensions/index.test.ts +0 -420
- package/sdk-extensions/index.ts +0 -203
package/sdk-extensions/config.js
DELETED
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
"use strict";
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.setSDKExtensionsConfig = setSDKExtensionsConfig;
|
|
5
|
-
exports.getSDKExtensionsConfig = getSDKExtensionsConfig;
|
|
6
|
-
exports.resetSDKExtensionsConfig = resetSDKExtensionsConfig;
|
|
7
|
-
exports.extractJWTFromHeader = extractJWTFromHeader;
|
|
8
|
-
exports.isValidJWT = isValidJWT;
|
|
9
|
-
exports.extractTokenFromSDKClient = extractTokenFromSDKClient;
|
|
10
|
-
exports.configureWithJWT = configureWithJWT;
|
|
11
|
-
exports.getEnvironmentConfig = getEnvironmentConfig;
|
|
12
|
-
// Default configuration
|
|
13
|
-
const defaultConfig = {
|
|
14
|
-
baseUrl: process.env.NEXT_PUBLIC_API_URL || 'http://localhost:8000',
|
|
15
|
-
credentials: 'include',
|
|
16
|
-
token: undefined, // Will be set from environment or programmatically
|
|
17
|
-
timeout: 30000,
|
|
18
|
-
maxRetries: 3,
|
|
19
|
-
retryDelay: 1000,
|
|
20
|
-
};
|
|
21
|
-
// Global configuration singleton
|
|
22
|
-
let globalConfig = { ...defaultConfig };
|
|
23
|
-
/**
|
|
24
|
-
* Set global configuration for SDK extensions
|
|
25
|
-
* @param config Partial configuration to merge with defaults
|
|
26
|
-
*/
|
|
27
|
-
function setSDKExtensionsConfig(config) {
|
|
28
|
-
globalConfig = {
|
|
29
|
-
...globalConfig,
|
|
30
|
-
...config,
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Get current SDK extensions configuration
|
|
35
|
-
* @returns Current configuration
|
|
36
|
-
*/
|
|
37
|
-
function getSDKExtensionsConfig() {
|
|
38
|
-
return { ...globalConfig };
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Reset configuration to defaults
|
|
42
|
-
*/
|
|
43
|
-
function resetSDKExtensionsConfig() {
|
|
44
|
-
globalConfig = { ...defaultConfig };
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Extract JWT token from Authorization header
|
|
48
|
-
* @param authHeader Authorization header value
|
|
49
|
-
* @returns JWT token or undefined
|
|
50
|
-
*/
|
|
51
|
-
function extractJWTFromHeader(authHeader) {
|
|
52
|
-
if (!authHeader)
|
|
53
|
-
return undefined;
|
|
54
|
-
const headerValue = Array.isArray(authHeader) ? authHeader[0] : authHeader;
|
|
55
|
-
if (typeof headerValue === 'string' && headerValue.startsWith('Bearer ')) {
|
|
56
|
-
return headerValue.substring(7);
|
|
57
|
-
}
|
|
58
|
-
return undefined;
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Validate JWT token format (basic validation)
|
|
62
|
-
* @param token JWT token to validate
|
|
63
|
-
* @returns true if token appears valid
|
|
64
|
-
*/
|
|
65
|
-
function isValidJWT(token) {
|
|
66
|
-
if (!token || typeof token !== 'string')
|
|
67
|
-
return false;
|
|
68
|
-
try {
|
|
69
|
-
const parts = token.split('.');
|
|
70
|
-
// JWT should have exactly 3 parts: header.payload.signature
|
|
71
|
-
return parts.length === 3 && parts.every((part) => part.length > 0);
|
|
72
|
-
}
|
|
73
|
-
catch {
|
|
74
|
-
return false;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Extract JWT token from SDK client configuration
|
|
79
|
-
* Centralizes the logic for extracting tokens from the client
|
|
80
|
-
* @returns JWT token or undefined
|
|
81
|
-
*/
|
|
82
|
-
function extractTokenFromSDKClient() {
|
|
83
|
-
// Import dynamically to avoid circular dependency
|
|
84
|
-
const { client } = require('../sdk/client.gen');
|
|
85
|
-
const sdkConfig = getSDKExtensionsConfig();
|
|
86
|
-
// Priority 1: Use explicitly configured token
|
|
87
|
-
if (sdkConfig.token) {
|
|
88
|
-
return sdkConfig.token;
|
|
89
|
-
}
|
|
90
|
-
// Priority 2: Extract from SDK client headers
|
|
91
|
-
const clientConfig = client.getConfig();
|
|
92
|
-
if (clientConfig.headers) {
|
|
93
|
-
if (typeof clientConfig.headers === 'object' && !Array.isArray(clientConfig.headers)) {
|
|
94
|
-
const headers = clientConfig.headers;
|
|
95
|
-
const token = extractJWTFromHeader(headers.Authorization);
|
|
96
|
-
if (isValidJWT(token)) {
|
|
97
|
-
return token;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
return undefined;
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Configure SDK extensions for JWT authentication
|
|
105
|
-
* @param token JWT token
|
|
106
|
-
* @param config Additional configuration options
|
|
107
|
-
*/
|
|
108
|
-
function configureWithJWT(token, config) {
|
|
109
|
-
if (!isValidJWT(token)) {
|
|
110
|
-
console.warn('Warning: Provided JWT token does not appear to be valid');
|
|
111
|
-
}
|
|
112
|
-
setSDKExtensionsConfig({
|
|
113
|
-
...config,
|
|
114
|
-
token,
|
|
115
|
-
// When using JWT, typically don't need cookies
|
|
116
|
-
credentials: config?.credentials || 'omit',
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* Get configuration for a specific environment
|
|
121
|
-
* @param env Environment name (production, staging, development)
|
|
122
|
-
* @returns Environment-specific configuration
|
|
123
|
-
*/
|
|
124
|
-
function getEnvironmentConfig(env = 'development') {
|
|
125
|
-
const baseConfigs = {
|
|
126
|
-
production: {
|
|
127
|
-
baseUrl: process.env.NEXT_PUBLIC_API_URL || 'https://api.robosystems.ai',
|
|
128
|
-
credentials: 'include',
|
|
129
|
-
timeout: 60000,
|
|
130
|
-
maxRetries: 5,
|
|
131
|
-
retryDelay: 2000,
|
|
132
|
-
},
|
|
133
|
-
staging: {
|
|
134
|
-
baseUrl: process.env.NEXT_PUBLIC_API_URL || 'https://staging-api.robosystems.ai',
|
|
135
|
-
credentials: 'include',
|
|
136
|
-
timeout: 45000,
|
|
137
|
-
maxRetries: 3,
|
|
138
|
-
retryDelay: 1500,
|
|
139
|
-
},
|
|
140
|
-
development: {
|
|
141
|
-
baseUrl: process.env.NEXT_PUBLIC_API_URL || 'http://localhost:8000',
|
|
142
|
-
credentials: 'include',
|
|
143
|
-
timeout: 30000,
|
|
144
|
-
maxRetries: 3,
|
|
145
|
-
retryDelay: 1000,
|
|
146
|
-
},
|
|
147
|
-
};
|
|
148
|
-
return {
|
|
149
|
-
...defaultConfig,
|
|
150
|
-
...baseConfigs[env],
|
|
151
|
-
};
|
|
152
|
-
}
|
|
@@ -1,199 +0,0 @@
|
|
|
1
|
-
import { beforeEach, describe, expect, it } from 'vitest'
|
|
2
|
-
import {
|
|
3
|
-
configureWithJWT,
|
|
4
|
-
extractJWTFromHeader,
|
|
5
|
-
getEnvironmentConfig,
|
|
6
|
-
getSDKExtensionsConfig,
|
|
7
|
-
isValidJWT,
|
|
8
|
-
resetSDKExtensionsConfig,
|
|
9
|
-
setSDKExtensionsConfig,
|
|
10
|
-
} from './config'
|
|
11
|
-
|
|
12
|
-
describe('config', () => {
|
|
13
|
-
beforeEach(() => {
|
|
14
|
-
resetSDKExtensionsConfig()
|
|
15
|
-
})
|
|
16
|
-
|
|
17
|
-
describe('setSDKExtensionsConfig / getSDKExtensionsConfig', () => {
|
|
18
|
-
it('should set and get configuration', () => {
|
|
19
|
-
setSDKExtensionsConfig({
|
|
20
|
-
baseUrl: 'https://api.example.com',
|
|
21
|
-
token: 'test-token',
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
const config = getSDKExtensionsConfig()
|
|
25
|
-
expect(config.baseUrl).toBe('https://api.example.com')
|
|
26
|
-
expect(config.token).toBe('test-token')
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
it('should merge configuration with defaults', () => {
|
|
30
|
-
setSDKExtensionsConfig({ token: 'new-token' })
|
|
31
|
-
|
|
32
|
-
const config = getSDKExtensionsConfig()
|
|
33
|
-
expect(config.token).toBe('new-token')
|
|
34
|
-
expect(config.credentials).toBe('include') // Default value
|
|
35
|
-
})
|
|
36
|
-
|
|
37
|
-
it('should allow partial updates', () => {
|
|
38
|
-
setSDKExtensionsConfig({ baseUrl: 'https://first.com' })
|
|
39
|
-
setSDKExtensionsConfig({ token: 'token-123' })
|
|
40
|
-
|
|
41
|
-
const config = getSDKExtensionsConfig()
|
|
42
|
-
expect(config.baseUrl).toBe('https://first.com')
|
|
43
|
-
expect(config.token).toBe('token-123')
|
|
44
|
-
})
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
describe('resetSDKExtensionsConfig', () => {
|
|
48
|
-
it('should reset configuration to defaults', () => {
|
|
49
|
-
setSDKExtensionsConfig({
|
|
50
|
-
baseUrl: 'https://custom.com',
|
|
51
|
-
token: 'custom-token',
|
|
52
|
-
})
|
|
53
|
-
|
|
54
|
-
resetSDKExtensionsConfig()
|
|
55
|
-
|
|
56
|
-
const config = getSDKExtensionsConfig()
|
|
57
|
-
expect(config.baseUrl).toBe('http://localhost:8000')
|
|
58
|
-
expect(config.token).toBeUndefined()
|
|
59
|
-
expect(config.credentials).toBe('include')
|
|
60
|
-
})
|
|
61
|
-
})
|
|
62
|
-
|
|
63
|
-
describe('extractJWTFromHeader', () => {
|
|
64
|
-
it('should extract JWT from Bearer token', () => {
|
|
65
|
-
const token = extractJWTFromHeader('Bearer abc.def.ghi')
|
|
66
|
-
expect(token).toBe('abc.def.ghi')
|
|
67
|
-
})
|
|
68
|
-
|
|
69
|
-
it('should extract JWT from array of headers', () => {
|
|
70
|
-
const token = extractJWTFromHeader(['Bearer abc.def.ghi'])
|
|
71
|
-
expect(token).toBe('abc.def.ghi')
|
|
72
|
-
})
|
|
73
|
-
|
|
74
|
-
it('should return undefined for non-Bearer tokens', () => {
|
|
75
|
-
const token = extractJWTFromHeader('Basic abc123')
|
|
76
|
-
expect(token).toBeUndefined()
|
|
77
|
-
})
|
|
78
|
-
|
|
79
|
-
it('should return undefined for undefined header', () => {
|
|
80
|
-
const token = extractJWTFromHeader(undefined)
|
|
81
|
-
expect(token).toBeUndefined()
|
|
82
|
-
})
|
|
83
|
-
|
|
84
|
-
it('should return undefined for empty string', () => {
|
|
85
|
-
const token = extractJWTFromHeader('')
|
|
86
|
-
expect(token).toBeUndefined()
|
|
87
|
-
})
|
|
88
|
-
|
|
89
|
-
it('should handle Bearer without space', () => {
|
|
90
|
-
const token = extractJWTFromHeader('Bearerabc.def.ghi')
|
|
91
|
-
expect(token).toBeUndefined()
|
|
92
|
-
})
|
|
93
|
-
})
|
|
94
|
-
|
|
95
|
-
describe('isValidJWT', () => {
|
|
96
|
-
it('should validate a proper JWT format', () => {
|
|
97
|
-
const valid = isValidJWT('eyJhbGc.eyJzdWI.SflKxw')
|
|
98
|
-
expect(valid).toBe(true)
|
|
99
|
-
})
|
|
100
|
-
|
|
101
|
-
it('should reject tokens with fewer than 3 parts', () => {
|
|
102
|
-
const valid = isValidJWT('abc.def')
|
|
103
|
-
expect(valid).toBe(false)
|
|
104
|
-
})
|
|
105
|
-
|
|
106
|
-
it('should reject tokens with more than 3 parts', () => {
|
|
107
|
-
const valid = isValidJWT('a.b.c.d')
|
|
108
|
-
expect(valid).toBe(false)
|
|
109
|
-
})
|
|
110
|
-
|
|
111
|
-
it('should reject tokens with empty parts', () => {
|
|
112
|
-
const valid = isValidJWT('a..c')
|
|
113
|
-
expect(valid).toBe(false)
|
|
114
|
-
})
|
|
115
|
-
|
|
116
|
-
it('should reject undefined', () => {
|
|
117
|
-
const valid = isValidJWT(undefined)
|
|
118
|
-
expect(valid).toBe(false)
|
|
119
|
-
})
|
|
120
|
-
|
|
121
|
-
it('should reject empty string', () => {
|
|
122
|
-
const valid = isValidJWT('')
|
|
123
|
-
expect(valid).toBe(false)
|
|
124
|
-
})
|
|
125
|
-
|
|
126
|
-
it('should reject non-string values', () => {
|
|
127
|
-
const valid = isValidJWT(123 as any)
|
|
128
|
-
expect(valid).toBe(false)
|
|
129
|
-
})
|
|
130
|
-
|
|
131
|
-
it('should accept JWT with long parts', () => {
|
|
132
|
-
const longJWT =
|
|
133
|
-
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c'
|
|
134
|
-
const valid = isValidJWT(longJWT)
|
|
135
|
-
expect(valid).toBe(true)
|
|
136
|
-
})
|
|
137
|
-
})
|
|
138
|
-
|
|
139
|
-
describe('configureWithJWT', () => {
|
|
140
|
-
it('should configure SDK with JWT token', () => {
|
|
141
|
-
configureWithJWT('abc.def.ghi')
|
|
142
|
-
|
|
143
|
-
const config = getSDKExtensionsConfig()
|
|
144
|
-
expect(config.token).toBe('abc.def.ghi')
|
|
145
|
-
expect(config.credentials).toBe('omit') // Default when using JWT
|
|
146
|
-
})
|
|
147
|
-
|
|
148
|
-
it('should allow overriding credentials', () => {
|
|
149
|
-
configureWithJWT('abc.def.ghi', { credentials: 'include' })
|
|
150
|
-
|
|
151
|
-
const config = getSDKExtensionsConfig()
|
|
152
|
-
expect(config.credentials).toBe('include')
|
|
153
|
-
})
|
|
154
|
-
|
|
155
|
-
it('should merge additional config options', () => {
|
|
156
|
-
configureWithJWT('abc.def.ghi', {
|
|
157
|
-
baseUrl: 'https://custom.com',
|
|
158
|
-
timeout: 60000,
|
|
159
|
-
})
|
|
160
|
-
|
|
161
|
-
const config = getSDKExtensionsConfig()
|
|
162
|
-
expect(config.token).toBe('abc.def.ghi')
|
|
163
|
-
expect(config.baseUrl).toBe('https://custom.com')
|
|
164
|
-
expect(config.timeout).toBe(60000)
|
|
165
|
-
})
|
|
166
|
-
})
|
|
167
|
-
|
|
168
|
-
describe('getEnvironmentConfig', () => {
|
|
169
|
-
it('should return development config by default', () => {
|
|
170
|
-
const config = getEnvironmentConfig()
|
|
171
|
-
expect(config.baseUrl).toBe('http://localhost:8000')
|
|
172
|
-
expect(config.credentials).toBe('include')
|
|
173
|
-
expect(config.timeout).toBe(30000)
|
|
174
|
-
expect(config.maxRetries).toBe(3)
|
|
175
|
-
})
|
|
176
|
-
|
|
177
|
-
it('should return production config', () => {
|
|
178
|
-
const config = getEnvironmentConfig('production')
|
|
179
|
-
expect(config.baseUrl).toBe('https://api.robosystems.ai')
|
|
180
|
-
expect(config.timeout).toBe(60000)
|
|
181
|
-
expect(config.maxRetries).toBe(5)
|
|
182
|
-
expect(config.retryDelay).toBe(2000)
|
|
183
|
-
})
|
|
184
|
-
|
|
185
|
-
it('should return staging config', () => {
|
|
186
|
-
const config = getEnvironmentConfig('staging')
|
|
187
|
-
expect(config.baseUrl).toBe('https://staging-api.robosystems.ai')
|
|
188
|
-
expect(config.timeout).toBe(45000)
|
|
189
|
-
expect(config.maxRetries).toBe(3)
|
|
190
|
-
expect(config.retryDelay).toBe(1500)
|
|
191
|
-
})
|
|
192
|
-
|
|
193
|
-
it('should return development config explicitly', () => {
|
|
194
|
-
const config = getEnvironmentConfig('development')
|
|
195
|
-
expect(config.baseUrl).toBe('http://localhost:8000')
|
|
196
|
-
expect(config.timeout).toBe(30000)
|
|
197
|
-
})
|
|
198
|
-
})
|
|
199
|
-
})
|
package/sdk-extensions/config.ts
DELETED
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
'use client'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Configuration for SDK extensions
|
|
5
|
-
* Provides centralized configuration for CORS, credentials, and other settings
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
export interface SDKExtensionsConfig {
|
|
9
|
-
baseUrl?: string
|
|
10
|
-
credentials?: 'include' | 'same-origin' | 'omit'
|
|
11
|
-
headers?: Record<string, string>
|
|
12
|
-
token?: string // JWT token for authentication
|
|
13
|
-
timeout?: number
|
|
14
|
-
maxRetries?: number
|
|
15
|
-
retryDelay?: number
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
// Default configuration
|
|
19
|
-
const defaultConfig: SDKExtensionsConfig = {
|
|
20
|
-
baseUrl: process.env.NEXT_PUBLIC_API_URL || 'http://localhost:8000',
|
|
21
|
-
credentials: 'include',
|
|
22
|
-
token: undefined, // Will be set from environment or programmatically
|
|
23
|
-
timeout: 30000,
|
|
24
|
-
maxRetries: 3,
|
|
25
|
-
retryDelay: 1000,
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// Global configuration singleton
|
|
29
|
-
let globalConfig: SDKExtensionsConfig = { ...defaultConfig }
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Set global configuration for SDK extensions
|
|
33
|
-
* @param config Partial configuration to merge with defaults
|
|
34
|
-
*/
|
|
35
|
-
export function setSDKExtensionsConfig(config: Partial<SDKExtensionsConfig>) {
|
|
36
|
-
globalConfig = {
|
|
37
|
-
...globalConfig,
|
|
38
|
-
...config,
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Get current SDK extensions configuration
|
|
44
|
-
* @returns Current configuration
|
|
45
|
-
*/
|
|
46
|
-
export function getSDKExtensionsConfig(): SDKExtensionsConfig {
|
|
47
|
-
return { ...globalConfig }
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Reset configuration to defaults
|
|
52
|
-
*/
|
|
53
|
-
export function resetSDKExtensionsConfig() {
|
|
54
|
-
globalConfig = { ...defaultConfig }
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Extract JWT token from Authorization header
|
|
59
|
-
* @param authHeader Authorization header value
|
|
60
|
-
* @returns JWT token or undefined
|
|
61
|
-
*/
|
|
62
|
-
export function extractJWTFromHeader(authHeader?: string | string[]): string | undefined {
|
|
63
|
-
if (!authHeader) return undefined
|
|
64
|
-
|
|
65
|
-
const headerValue = Array.isArray(authHeader) ? authHeader[0] : authHeader
|
|
66
|
-
if (typeof headerValue === 'string' && headerValue.startsWith('Bearer ')) {
|
|
67
|
-
return headerValue.substring(7)
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
return undefined
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Validate JWT token format (basic validation)
|
|
75
|
-
* @param token JWT token to validate
|
|
76
|
-
* @returns true if token appears valid
|
|
77
|
-
*/
|
|
78
|
-
export function isValidJWT(token: string | undefined): boolean {
|
|
79
|
-
if (!token || typeof token !== 'string') return false
|
|
80
|
-
|
|
81
|
-
try {
|
|
82
|
-
const parts = token.split('.')
|
|
83
|
-
// JWT should have exactly 3 parts: header.payload.signature
|
|
84
|
-
return parts.length === 3 && parts.every((part) => part.length > 0)
|
|
85
|
-
} catch {
|
|
86
|
-
return false
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Extract JWT token from SDK client configuration
|
|
92
|
-
* Centralizes the logic for extracting tokens from the client
|
|
93
|
-
* @returns JWT token or undefined
|
|
94
|
-
*/
|
|
95
|
-
export function extractTokenFromSDKClient(): string | undefined {
|
|
96
|
-
// Import dynamically to avoid circular dependency
|
|
97
|
-
const { client } = require('../sdk/client.gen')
|
|
98
|
-
|
|
99
|
-
const sdkConfig = getSDKExtensionsConfig()
|
|
100
|
-
|
|
101
|
-
// Priority 1: Use explicitly configured token
|
|
102
|
-
if (sdkConfig.token) {
|
|
103
|
-
return sdkConfig.token
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// Priority 2: Extract from SDK client headers
|
|
107
|
-
const clientConfig = client.getConfig()
|
|
108
|
-
if (clientConfig.headers) {
|
|
109
|
-
if (typeof clientConfig.headers === 'object' && !Array.isArray(clientConfig.headers)) {
|
|
110
|
-
const headers = clientConfig.headers as Record<string, unknown>
|
|
111
|
-
const token = extractJWTFromHeader(headers.Authorization as string | undefined)
|
|
112
|
-
if (isValidJWT(token)) {
|
|
113
|
-
return token
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
return undefined
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* Configure SDK extensions for JWT authentication
|
|
123
|
-
* @param token JWT token
|
|
124
|
-
* @param config Additional configuration options
|
|
125
|
-
*/
|
|
126
|
-
export function configureWithJWT(token: string, config?: Partial<SDKExtensionsConfig>) {
|
|
127
|
-
if (!isValidJWT(token)) {
|
|
128
|
-
console.warn('Warning: Provided JWT token does not appear to be valid')
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
setSDKExtensionsConfig({
|
|
132
|
-
...config,
|
|
133
|
-
token,
|
|
134
|
-
// When using JWT, typically don't need cookies
|
|
135
|
-
credentials: config?.credentials || 'omit',
|
|
136
|
-
})
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* Get configuration for a specific environment
|
|
141
|
-
* @param env Environment name (production, staging, development)
|
|
142
|
-
* @returns Environment-specific configuration
|
|
143
|
-
*/
|
|
144
|
-
export function getEnvironmentConfig(
|
|
145
|
-
env: 'production' | 'staging' | 'development' = 'development'
|
|
146
|
-
): SDKExtensionsConfig {
|
|
147
|
-
const baseConfigs: Record<string, Partial<SDKExtensionsConfig>> = {
|
|
148
|
-
production: {
|
|
149
|
-
baseUrl: process.env.NEXT_PUBLIC_API_URL || 'https://api.robosystems.ai',
|
|
150
|
-
credentials: 'include',
|
|
151
|
-
timeout: 60000,
|
|
152
|
-
maxRetries: 5,
|
|
153
|
-
retryDelay: 2000,
|
|
154
|
-
},
|
|
155
|
-
staging: {
|
|
156
|
-
baseUrl: process.env.NEXT_PUBLIC_API_URL || 'https://staging-api.robosystems.ai',
|
|
157
|
-
credentials: 'include',
|
|
158
|
-
timeout: 45000,
|
|
159
|
-
maxRetries: 3,
|
|
160
|
-
retryDelay: 1500,
|
|
161
|
-
},
|
|
162
|
-
development: {
|
|
163
|
-
baseUrl: process.env.NEXT_PUBLIC_API_URL || 'http://localhost:8000',
|
|
164
|
-
credentials: 'include',
|
|
165
|
-
timeout: 30000,
|
|
166
|
-
maxRetries: 3,
|
|
167
|
-
retryDelay: 1000,
|
|
168
|
-
},
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
return {
|
|
172
|
-
...defaultConfig,
|
|
173
|
-
...baseConfigs[env],
|
|
174
|
-
}
|
|
175
|
-
}
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import type { OperationProgress, OperationResult } from './OperationClient';
|
|
2
|
-
import { OperationClient } from './OperationClient';
|
|
3
|
-
import type { QueryOptions, QueryResult } from './QueryClient';
|
|
4
|
-
import { QueryClient } from './QueryClient';
|
|
5
|
-
/**
|
|
6
|
-
* Hook for executing Cypher queries with loading states and error handling
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* ```tsx
|
|
10
|
-
* const { execute, loading, error, data } = useQuery('graph_123')
|
|
11
|
-
*
|
|
12
|
-
* const handleSearch = async () => {
|
|
13
|
-
* const result = await execute('MATCH (n:Company) RETURN n LIMIT 10')
|
|
14
|
-
* console.log(result.data)
|
|
15
|
-
* }
|
|
16
|
-
* ```
|
|
17
|
-
*/
|
|
18
|
-
export declare function useQuery(graphId: string): {
|
|
19
|
-
execute: (query: string, parameters?: Record<string, any>, options?: QueryOptions) => Promise<QueryResult | null>;
|
|
20
|
-
query: (cypher: string, parameters?: Record<string, any>) => Promise<any[]>;
|
|
21
|
-
loading: boolean;
|
|
22
|
-
error: Error;
|
|
23
|
-
data: QueryResult;
|
|
24
|
-
queuePosition: number;
|
|
25
|
-
};
|
|
26
|
-
/**
|
|
27
|
-
* Hook for streaming large query results
|
|
28
|
-
*
|
|
29
|
-
* @example
|
|
30
|
-
* ```tsx
|
|
31
|
-
* const { stream, isStreaming, error, cancel } = useStreamingQuery('graph_123')
|
|
32
|
-
*
|
|
33
|
-
* const handleStream = async () => {
|
|
34
|
-
* const iterator = stream('MATCH (n) RETURN n')
|
|
35
|
-
* for await (const batch of iterator) {
|
|
36
|
-
* console.log('Received batch:', batch)
|
|
37
|
-
* }
|
|
38
|
-
* }
|
|
39
|
-
* ```
|
|
40
|
-
*/
|
|
41
|
-
export declare function useStreamingQuery(graphId: string): {
|
|
42
|
-
stream: (query: string, parameters?: Record<string, any>, chunkSize?: number) => AsyncIterableIterator<any[]>;
|
|
43
|
-
isStreaming: boolean;
|
|
44
|
-
error: Error;
|
|
45
|
-
rowsReceived: number;
|
|
46
|
-
cancel: () => void;
|
|
47
|
-
};
|
|
48
|
-
/**
|
|
49
|
-
* Hook for monitoring long-running operations
|
|
50
|
-
*
|
|
51
|
-
* @example
|
|
52
|
-
* ```tsx
|
|
53
|
-
* const { monitor, status, progress, error, result } = useOperation<BackupResult>()
|
|
54
|
-
*
|
|
55
|
-
* const handleBackup = async () => {
|
|
56
|
-
* const { operation_id } = await createBackup({ ... })
|
|
57
|
-
* const result = await monitor(operation_id)
|
|
58
|
-
* console.log('Backup completed:', result)
|
|
59
|
-
* }
|
|
60
|
-
* ```
|
|
61
|
-
*/
|
|
62
|
-
export declare function useOperation<T = any>(operationId?: string): {
|
|
63
|
-
monitor: (id: string, timeout?: number) => Promise<OperationResult<T> | null>;
|
|
64
|
-
cancel: (id: string) => Promise<void>;
|
|
65
|
-
status: "error" | "idle" | "running" | "completed";
|
|
66
|
-
progress: OperationProgress;
|
|
67
|
-
error: Error;
|
|
68
|
-
result: OperationResult<T>;
|
|
69
|
-
};
|
|
70
|
-
/**
|
|
71
|
-
* Hook for monitoring multiple operations concurrently
|
|
72
|
-
*
|
|
73
|
-
* @example
|
|
74
|
-
* ```tsx
|
|
75
|
-
* const { monitorAll, results, allCompleted, hasErrors } = useMultipleOperations()
|
|
76
|
-
*
|
|
77
|
-
* const handleMultiple = async () => {
|
|
78
|
-
* const operations = await Promise.all([
|
|
79
|
-
* createBackup(...),
|
|
80
|
-
* createExport(...),
|
|
81
|
-
* ])
|
|
82
|
-
*
|
|
83
|
-
* const results = await monitorAll(operations.map(op => op.operation_id))
|
|
84
|
-
* }
|
|
85
|
-
* ```
|
|
86
|
-
*/
|
|
87
|
-
export declare function useMultipleOperations<T = any>(): {
|
|
88
|
-
monitorAll: (operationIds: string[]) => Promise<Map<string, OperationResult<T>>>;
|
|
89
|
-
results: Map<string, OperationResult<T>>;
|
|
90
|
-
errors: Map<string, Error>;
|
|
91
|
-
loading: boolean;
|
|
92
|
-
allCompleted: boolean;
|
|
93
|
-
hasErrors: boolean;
|
|
94
|
-
};
|
|
95
|
-
/**
|
|
96
|
-
* Hook that provides access to all SDK extension clients
|
|
97
|
-
* Useful when you need direct access to the underlying clients
|
|
98
|
-
*
|
|
99
|
-
* @example
|
|
100
|
-
* ```tsx
|
|
101
|
-
* const clients = useSDKClients()
|
|
102
|
-
*
|
|
103
|
-
* // Direct access to clients
|
|
104
|
-
* const result = await clients.query.query('graph_123', 'MATCH (n) RETURN n')
|
|
105
|
-
* ```
|
|
106
|
-
*/
|
|
107
|
-
export declare function useSDKClients(): {
|
|
108
|
-
query: QueryClient | null;
|
|
109
|
-
operations: OperationClient | null;
|
|
110
|
-
};
|