svector-sdk
Version:
Official JavaScript and TypeScript SDK for accessing SVECTOR APIs.
113 lines (112 loc) • 3.92 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.validateSDK = validateSDK;
const src_1 = require("../src");
async function validateSDK() {
console.log(' SVECTOR SDK Validation Tests\n');
console.log('Test 1: Constructor validation');
try {
new src_1.SVECTOR({ apiKey: '' });
console.log('Should have thrown AuthenticationError');
}
catch (error) {
if (error instanceof src_1.AuthenticationError) {
console.log('Properly validates missing API key');
}
else {
console.log('Unexpected error type:', error instanceof Error ? error.constructor.name : 'Unknown');
}
}
console.log('\nTest 2: Valid constructor');
try {
const client = new src_1.SVECTOR({
apiKey: 'test-key',
dangerouslyAllowBrowser: true
});
console.log('Client created successfully');
console.log(` • Has chat API: ${!!client.chat}`);
console.log(` • Has models API: ${!!client.models}`);
console.log(` • Has files API: ${!!client.files}`);
console.log(` • Has knowledge API: ${!!client.knowledge}`);
}
catch (error) {
console.log('Failed to create client:', error);
}
console.log('\nTest 3: Type definitions');
try {
const request = {
model: 'spec-3-turbo',
messages: [
{ role: 'user', content: 'test' }
],
temperature: 0.7,
max_tokens: 100,
};
console.log('TypeScript types are working correctly');
}
catch (error) {
console.log('TypeScript type error:', error);
}
console.log('\nTest 4: Utility functions');
try {
const file = await (0, src_1.toFile)('test content', 'test.txt', { type: 'text/plain' });
console.log('toFile utility works correctly');
console.log(` • File name: ${file.name}`);
console.log(` • File type: ${file.type}`);
console.log(` • File size: ${file.size} bytes`);
}
catch (error) {
console.log('toFile utility error:', error);
}
console.log('\nTest 5: Error hierarchy');
const errors = [
new src_1.AuthenticationError('test'),
new src_1.APIError('test', 500),
];
for (const error of errors) {
console.log(`${error.constructor.name} extends Error: ${error instanceof Error}`);
console.log(` • Has status: ${error.status !== undefined}`);
console.log(` • Message: ${error.message}`);
}
console.log('\nTest 6: API method signatures');
const client = new src_1.SVECTOR({
apiKey: 'test-key',
dangerouslyAllowBrowser: true
});
const expectedMethods = [
'chat.create',
'chat.createStream',
'models.list',
'files.create',
'knowledge.addFile',
'get',
'post',
'put',
'delete'
];
for (const method of expectedMethods) {
const parts = method.split('.');
let obj = client;
for (const part of parts) {
obj = obj[part];
}
if (typeof obj === 'function') {
console.log(`Method ${method} exists and is callable`);
}
else {
console.log(`Method ${method} is missing or not a function`);
}
}
console.log('\n🎉 Validation complete!');
if (process.env.SVECTOR_API_KEY) {
console.log('\n API key detected - you can run live tests:');
console.log(' npm run build && node dist/examples/basic-chat.js');
console.log(' npm run build && node dist/examples/advanced-rag.js');
}
else {
console.log('\n💡 To test with real API calls, set SVECTOR_API_KEY environment variable');
}
}
if (require.main === module) {
validateSDK().catch(console.error);
}