@robosystems/client 0.1.10

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/prepare.js ADDED
@@ -0,0 +1,214 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Prepare script for SDK publishing
5
+ * This script copies the generated SDK files and creates the necessary structure for npm publishing
6
+ */
7
+
8
+ const fs = require('fs')
9
+ const path = require('path')
10
+ const { execSync } = require('child_process')
11
+
12
+ console.log('🚀 Preparing RoboSystems SDK for publishing...')
13
+
14
+ const sdkSourceDir = path.join(__dirname, 'sdk')
15
+ const currentDir = __dirname
16
+
17
+ // Check if SDK directory exists
18
+ if (!fs.existsSync(sdkSourceDir)) {
19
+ console.error('❌ SDK source directory not found. Please run "npm run generate" first.')
20
+ process.exit(1)
21
+ }
22
+
23
+ // Copy all SDK files
24
+ console.log('📋 Copying SDK files...')
25
+ const filesToCopy = fs.readdirSync(sdkSourceDir)
26
+
27
+ filesToCopy.forEach((file) => {
28
+ const sourcePath = path.join(sdkSourceDir, file)
29
+ const destPath = path.join(currentDir, file)
30
+
31
+ if (fs.statSync(sourcePath).isDirectory()) {
32
+ // Copy directory recursively
33
+ fs.cpSync(sourcePath, destPath, { recursive: true })
34
+ console.log(` ✓ Copied directory: ${file}/`)
35
+ } else {
36
+ // Copy file
37
+ fs.copyFileSync(sourcePath, destPath)
38
+ console.log(` ✓ Copied file: ${file}`)
39
+ }
40
+ })
41
+
42
+ // Create main index.js that re-exports everything
43
+ console.log('📝 Creating index files...')
44
+ const indexContent = `// Re-export everything from the generated SDK
45
+ export * from './sdk.gen.js';
46
+ export * from './types.gen.js';
47
+ export { client } from './client.gen.js';
48
+ export * from './client/index.js';
49
+
50
+ // Re-export SDK extensions
51
+ export * from './extensions/index.js';
52
+ `
53
+
54
+ fs.writeFileSync(path.join(currentDir, 'index.js'), indexContent)
55
+ console.log(' ✓ Created index.js')
56
+
57
+ // Create index.d.ts for TypeScript
58
+ const indexDtsContent = `// Re-export all types
59
+ export * from './sdk.gen';
60
+ export * from './types.gen';
61
+ export { client } from './client.gen';
62
+ export * from './client/index';
63
+
64
+ // Re-export SDK extensions
65
+ export * from './extensions/index';
66
+ `
67
+
68
+ fs.writeFileSync(path.join(currentDir, 'index.d.ts'), indexDtsContent)
69
+ console.log(' ✓ Created index.d.ts')
70
+
71
+ // Copy SDK extensions
72
+ console.log('🚀 Copying SDK extensions...')
73
+ const extensionsSourceDir = path.join(__dirname, 'sdk-extensions')
74
+ const extensionsDestDir = path.join(currentDir, 'extensions')
75
+
76
+ // Create extensions directory
77
+ if (!fs.existsSync(extensionsDestDir)) {
78
+ fs.mkdirSync(extensionsDestDir, { recursive: true })
79
+ }
80
+
81
+ // Copy extensions files
82
+ if (fs.existsSync(extensionsSourceDir)) {
83
+ const files = fs.readdirSync(extensionsSourceDir)
84
+ files.forEach((file) => {
85
+ const sourcePath = path.join(extensionsSourceDir, file)
86
+ const destPath = path.join(extensionsDestDir, file)
87
+
88
+ if (file.endsWith('.ts')) {
89
+ // Process TypeScript files
90
+ let content = fs.readFileSync(sourcePath, 'utf8')
91
+
92
+ // Adjust imports for published package structure
93
+ content = content
94
+ .replace(/from ['"]\.\.\/sdk\/sdk\.gen['"]/g, "from '../sdk.gen'")
95
+ .replace(/from ['"]\.\.\/sdk\/types\.gen['"]/g, "from '../types.gen'")
96
+ .replace(/from ['"]\.\.\/sdk\/client\.gen['"]/g, "from '../client.gen'")
97
+
98
+ // Save TypeScript version
99
+ fs.writeFileSync(destPath, content)
100
+
101
+ // Create JavaScript version
102
+ let jsContent = content
103
+ .replace(/export interface \w+[^}]+}/gs, '') // Remove interfaces
104
+ .replace(/export type[^;]+;/gs, '') // Remove type exports
105
+ .replace(/: (\w+(\[\])?|{[^}]+}|\([^)]+\) => \w+|['"][\w-]+['"])/g, '') // Remove type annotations
106
+ .replace(/<[^>]+>/g, '') // Remove generics
107
+ .replace(/\?:/g, ':') // Remove optional markers
108
+ .replace(/ as \w+/g, '') // Remove type assertions
109
+ .replace(/import type/g, 'import') // Convert type imports
110
+ .replace(/type \w+ = [^;]+;/g, '') // Remove type aliases
111
+
112
+ const jsFile = file.replace('.ts', '.js')
113
+ fs.writeFileSync(path.join(extensionsDestDir, jsFile), jsContent)
114
+ console.log(` ✓ Copied ${file} -> ${jsFile}`)
115
+ }
116
+ })
117
+ console.log(' ✓ SDK extensions copied')
118
+ } else {
119
+ console.log(' ⚠️ SDK extensions not found')
120
+ }
121
+
122
+ // No longer copying legacy utils - using sdk-extensions instead
123
+
124
+ // Create README if it doesn't exist
125
+ const readmePath = path.join(currentDir, 'README.md')
126
+ if (!fs.existsSync(readmePath)) {
127
+ const readmeContent = `# RoboSystems TypeScript SDK
128
+
129
+ Official TypeScript SDK for the RoboSystems Financial Knowledge Graph API with SSE support.
130
+
131
+ ## Installation
132
+
133
+ \`\`\`bash
134
+ npm install @robosystems/sdk
135
+ \`\`\`
136
+
137
+ ## Quick Start
138
+
139
+ \`\`\`typescript
140
+ import { client, getCurrentUser, extensions } from '@robosystems/sdk';
141
+
142
+ // Configure the client
143
+ client.setConfig({
144
+ baseUrl: 'https://api.robosystems.ai',
145
+ credentials: 'include'
146
+ });
147
+
148
+ // Use the SDK
149
+ const { data: user } = await getCurrentUser();
150
+
151
+ // Use SDK Extensions for enhanced features
152
+ const result = await extensions.query.query('graph_123', 'MATCH (n) RETURN n LIMIT 10');
153
+
154
+ // Monitor async operations with SSE
155
+ const opResult = await extensions.operations.monitorOperation('operation_123', {
156
+ onProgress: (progress) => console.log(progress.message)
157
+ });
158
+ \`\`\`
159
+
160
+ ## Features
161
+
162
+ - **Generated SDK**: Auto-generated from OpenAPI spec
163
+ - **SSE Support**: Real-time updates for async operations
164
+ - **Query Client**: Enhanced query execution with streaming
165
+ - **Operation Monitoring**: Track long-running operations
166
+ - **Type Safety**: Full TypeScript support
167
+
168
+ ## Documentation
169
+
170
+ Full documentation available at [https://api.robosystems.ai/docs](https://api.robosystems.ai/docs)
171
+ `
172
+
173
+ fs.writeFileSync(readmePath, readmeContent)
174
+ console.log(' ✓ Created README.md')
175
+ }
176
+
177
+ // Run TypeScript type checking
178
+ console.log('🔍 Type checking...')
179
+ try {
180
+ execSync(
181
+ 'npx tsc --noEmit --skipLibCheck --esModuleInterop --strict --target ES2022 --module commonjs src/*.ts',
182
+ {
183
+ cwd: currentDir,
184
+ stdio: 'pipe',
185
+ }
186
+ )
187
+ console.log(' ✓ Type checking passed')
188
+ } catch (error) {
189
+ console.error(' ❌ Type checking failed:', error.stderr?.toString() || error.message)
190
+ console.error(' ⚠️ Continuing anyway, but please review the generated files')
191
+ }
192
+
193
+ // Format the generated files
194
+ console.log('💅 Formatting files...')
195
+ try {
196
+ // Format TypeScript files
197
+ execSync('npx prettier --write "src/*.ts" --config ../prettier.config.cjs 2>/dev/null || true', {
198
+ cwd: currentDir,
199
+ stdio: 'pipe',
200
+ })
201
+ // Format JavaScript files
202
+ execSync('npx prettier --write "src/*.js" --config ../prettier.config.cjs 2>/dev/null || true', {
203
+ cwd: currentDir,
204
+ stdio: 'pipe',
205
+ })
206
+ console.log(' ✓ Files formatted')
207
+ } catch (error) {
208
+ console.log(' ⚠️ Formatting skipped (prettier not available)')
209
+ }
210
+
211
+ console.log('✅ SDK prepared for publishing!')
212
+ console.log('\nTo publish:')
213
+ console.log(' 1. cd sdk-publish')
214
+ console.log(' 2. npm publish')