whio-api-sdk 1.0.154 โ 1.0.156
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/.claude/settings.local.json +6 -1
- package/dist/src/sdk/index.d.ts +1 -0
- package/dist/src/sdk/index.js +1 -0
- package/dist/src/sdk/sdk.d.ts +40 -6
- package/dist/src/sdk/sdk.js +220 -9
- package/dist/src/sdk/types.d.ts +33 -2
- package/dist/src/sdk/types.js +8 -0
- package/dist/src/sdk/urls.d.ts +8 -5
- package/dist/src/sdk/urls.js +15 -5
- package/package.json +3 -2
- package/quick-test.mjs +155 -0
- package/src/sdk/index.ts +2 -1
- package/src/sdk/sdk.ts +215 -17
- package/src/sdk/types.ts +45 -7
- package/src/sdk/urls.ts +21 -5
- package/test-comprehensive.mjs +276 -0
- package/test-sdk.cjs +190 -0
- package/test-sdk.mjs +228 -0
- package/test-sdk.ts +167 -0
- package/test-simple.mjs +90 -0
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
// Comprehensive SDK test against localhost:3000
|
|
2
|
+
import { ApiSDK } from './dist/index.js';
|
|
3
|
+
|
|
4
|
+
class TestStorage {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.storage = new Map();
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
async getItem(key) {
|
|
10
|
+
return this.storage.get(key) || null;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
async setItem(key, value) {
|
|
14
|
+
this.storage.set(key, value);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async removeItem(key) {
|
|
18
|
+
this.storage.delete(key);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async function runTests() {
|
|
23
|
+
console.log('๐งช Starting comprehensive SDK tests against localhost:3000\n');
|
|
24
|
+
|
|
25
|
+
const storage = new TestStorage();
|
|
26
|
+
const sdk = new ApiSDK({
|
|
27
|
+
baseUrl: 'http://localhost:3000',
|
|
28
|
+
storage
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
let testResults = {
|
|
32
|
+
passed: 0,
|
|
33
|
+
failed: 0,
|
|
34
|
+
errors: []
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
async function test(name, testFn) {
|
|
38
|
+
try {
|
|
39
|
+
console.log(`๐ Testing: ${name}`);
|
|
40
|
+
await testFn();
|
|
41
|
+
console.log(`โ
${name} - PASSED\n`);
|
|
42
|
+
testResults.passed++;
|
|
43
|
+
} catch (error) {
|
|
44
|
+
console.log(`โ ${name} - FAILED: ${error.message}\n`);
|
|
45
|
+
testResults.failed++;
|
|
46
|
+
testResults.errors.push({ test: name, error: error.message });
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Test authentication
|
|
51
|
+
await test('Login with credentials', async () => {
|
|
52
|
+
const response = await sdk.login({
|
|
53
|
+
email: 'test@example.com',
|
|
54
|
+
password: 'password'
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
if (!response.access_token) throw new Error('No access token returned');
|
|
58
|
+
if (!response.user) throw new Error('No user returned');
|
|
59
|
+
console.log(` User: ${response.user.firstName} ${response.user.lastName}`);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
await test('Check authentication status', async () => {
|
|
63
|
+
const isAuth = sdk.isAuthenticated();
|
|
64
|
+
if (!isAuth) throw new Error('Should be authenticated after login');
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
await test('Get current user', async () => {
|
|
68
|
+
const user = sdk.getCurrentUser();
|
|
69
|
+
if (!user) throw new Error('Current user should be available');
|
|
70
|
+
console.log(` Current user: ${user.firstName} ${user.lastName}`);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
await test('Get profile', async () => {
|
|
74
|
+
const profile = await sdk.getProfile();
|
|
75
|
+
if (!profile.id) throw new Error('Profile should have ID');
|
|
76
|
+
console.log(` Profile ID: ${profile.id}`);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
// Test organization methods
|
|
80
|
+
await test('Get organizations', async () => {
|
|
81
|
+
const orgs = await sdk.getOrganizations();
|
|
82
|
+
if (!Array.isArray(orgs)) throw new Error('Should return array of organizations');
|
|
83
|
+
console.log(` Found ${orgs.length} organizations`);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
await test('Get current organization', async () => {
|
|
87
|
+
const user = sdk.getCurrentUser();
|
|
88
|
+
const org = await sdk.getOrganization(user.organizationId);
|
|
89
|
+
if (!org.id) throw new Error('Organization should have ID');
|
|
90
|
+
console.log(` Organization: ${org.name}`);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
// Test user methods
|
|
94
|
+
await test('Get users', async () => {
|
|
95
|
+
const users = await sdk.getUsers();
|
|
96
|
+
if (!Array.isArray(users)) throw new Error('Should return array of users');
|
|
97
|
+
console.log(` Found ${users.length} users`);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
await test('Get users by organization', async () => {
|
|
101
|
+
const user = sdk.getCurrentUser();
|
|
102
|
+
const users = await sdk.getUsersByOrganization(user.organizationId);
|
|
103
|
+
if (!Array.isArray(users)) throw new Error('Should return array of users');
|
|
104
|
+
console.log(` Found ${users.length} users in organization`);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
// Test team methods
|
|
108
|
+
await test('Get teams', async () => {
|
|
109
|
+
const teams = await sdk.getTeams();
|
|
110
|
+
if (!Array.isArray(teams)) throw new Error('Should return array of teams');
|
|
111
|
+
console.log(` Found ${teams.length} teams`);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
await test('Create team', async () => {
|
|
115
|
+
const team = await sdk.createTeam('Test Team', 'A test team for SDK testing');
|
|
116
|
+
if (!team.id) throw new Error('Created team should have ID');
|
|
117
|
+
console.log(` Created team: ${team.name} (ID: ${team.id})`);
|
|
118
|
+
|
|
119
|
+
// Store team ID for cleanup
|
|
120
|
+
global.testTeamId = team.id;
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
// Test template category methods
|
|
124
|
+
await test('Get template categories', async () => {
|
|
125
|
+
const categories = await sdk.getTemplateCategories();
|
|
126
|
+
if (!Array.isArray(categories)) throw new Error('Should return array of categories');
|
|
127
|
+
console.log(` Found ${categories.length} template categories`);
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
await test('Create template category', async () => {
|
|
131
|
+
const category = await sdk.createTemplateCategory('Test Category');
|
|
132
|
+
if (!category.id) throw new Error('Created category should have ID');
|
|
133
|
+
console.log(` Created category: ${category.name} (ID: ${category.id})`);
|
|
134
|
+
|
|
135
|
+
global.testCategoryId = category.id;
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
// Test template methods
|
|
139
|
+
await test('Get templates', async () => {
|
|
140
|
+
const templates = await sdk.getTemplates();
|
|
141
|
+
if (!Array.isArray(templates)) throw new Error('Should return array of templates');
|
|
142
|
+
console.log(` Found ${templates.length} templates`);
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
await test('Create template', async () => {
|
|
146
|
+
const template = await sdk.createTemplate(
|
|
147
|
+
'Test Template',
|
|
148
|
+
'This is a test template content',
|
|
149
|
+
global.testCategoryId
|
|
150
|
+
);
|
|
151
|
+
if (!template.id) throw new Error('Created template should have ID');
|
|
152
|
+
console.log(` Created template: ${template.title} (ID: ${template.id})`);
|
|
153
|
+
|
|
154
|
+
global.testTemplateId = template.id;
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
await test('Update template', async () => {
|
|
158
|
+
const updated = await sdk.updateTemplate(
|
|
159
|
+
'Updated Test Template',
|
|
160
|
+
'Updated test template content',
|
|
161
|
+
global.testTemplateId
|
|
162
|
+
);
|
|
163
|
+
if (updated.title !== 'Updated Test Template') {
|
|
164
|
+
throw new Error('Template title should be updated');
|
|
165
|
+
}
|
|
166
|
+
console.log(` Updated template title: ${updated.title}`);
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
// Test user template methods
|
|
170
|
+
await test('Get user templates', async () => {
|
|
171
|
+
const userTemplates = await sdk.getUserTemplates();
|
|
172
|
+
if (!Array.isArray(userTemplates)) throw new Error('Should return array of user templates');
|
|
173
|
+
console.log(` Found ${userTemplates.length} user templates`);
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
await test('Create user template', async () => {
|
|
177
|
+
const userTemplate = await sdk.createUserTemplate(
|
|
178
|
+
'Test User Template',
|
|
179
|
+
'This is a test user template',
|
|
180
|
+
global.testTemplateId
|
|
181
|
+
);
|
|
182
|
+
if (!userTemplate.id) throw new Error('Created user template should have ID');
|
|
183
|
+
console.log(` Created user template: ${userTemplate.title} (ID: ${userTemplate.id})`);
|
|
184
|
+
|
|
185
|
+
global.testUserTemplateId = userTemplate.id;
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
// Test transcription summary methods
|
|
189
|
+
await test('Get transcription summaries', async () => {
|
|
190
|
+
const summaries = await sdk.getTranscriptionSummaries();
|
|
191
|
+
if (!Array.isArray(summaries)) throw new Error('Should return array of summaries');
|
|
192
|
+
console.log(` Found ${summaries.length} transcription summaries`);
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
await test('Generate transcription summary', async () => {
|
|
196
|
+
const summary = await sdk.generateTranscriptionSummary(
|
|
197
|
+
'This is a test transcript for testing purposes',
|
|
198
|
+
global.testTemplateId
|
|
199
|
+
);
|
|
200
|
+
if (!summary.id) throw new Error('Generated summary should have ID');
|
|
201
|
+
console.log(` Generated summary (ID: ${summary.id})`);
|
|
202
|
+
|
|
203
|
+
global.testSummaryId = summary.id;
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
await test('Update transcription summary', async () => {
|
|
207
|
+
const updated = await sdk.updateTranscriptionSummary(
|
|
208
|
+
global.testSummaryId,
|
|
209
|
+
'Updated summary content'
|
|
210
|
+
);
|
|
211
|
+
if (updated.content !== 'Updated summary content') {
|
|
212
|
+
throw new Error('Summary content should be updated');
|
|
213
|
+
}
|
|
214
|
+
console.log(` Updated summary content`);
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
// Test audio upload (mock file)
|
|
218
|
+
await test('Upload audio file', async () => {
|
|
219
|
+
const formData = new FormData();
|
|
220
|
+
const blob = new Blob(['fake audio data'], { type: 'audio/wav' });
|
|
221
|
+
formData.append('audio', blob, 'test.wav');
|
|
222
|
+
|
|
223
|
+
try {
|
|
224
|
+
const result = await sdk.uploadAudioFile(formData);
|
|
225
|
+
console.log(` Upload result: ${result ? 'Success' : 'No response'}`);
|
|
226
|
+
} catch (error) {
|
|
227
|
+
if (error.message.includes('413') || error.message.includes('file')) {
|
|
228
|
+
console.log(` Upload failed as expected (file validation): ${error.message}`);
|
|
229
|
+
} else {
|
|
230
|
+
throw error;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
// Test base64 audio transcription
|
|
236
|
+
await test('Transcribe base64 audio', async () => {
|
|
237
|
+
try {
|
|
238
|
+
const transcript = await sdk.transcribeBase64Audio('fake-base64-audio-data');
|
|
239
|
+
console.log(` Transcript: ${transcript}`);
|
|
240
|
+
} catch (error) {
|
|
241
|
+
if (error.message.includes('400') || error.message.includes('base64')) {
|
|
242
|
+
console.log(` Transcription failed as expected (invalid base64): ${error.message}`);
|
|
243
|
+
} else {
|
|
244
|
+
throw error;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
// Test logout
|
|
250
|
+
await test('Logout', async () => {
|
|
251
|
+
await sdk.logout();
|
|
252
|
+
const isAuth = sdk.isAuthenticated();
|
|
253
|
+
if (isAuth) throw new Error('Should not be authenticated after logout');
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
// Print test results
|
|
257
|
+
console.log('\n๐ Test Results:');
|
|
258
|
+
console.log(`โ
Passed: ${testResults.passed}`);
|
|
259
|
+
console.log(`โ Failed: ${testResults.failed}`);
|
|
260
|
+
console.log(`๐ Success Rate: ${((testResults.passed / (testResults.passed + testResults.failed)) * 100).toFixed(1)}%`);
|
|
261
|
+
|
|
262
|
+
if (testResults.errors.length > 0) {
|
|
263
|
+
console.log('\n๐ฅ Errors:');
|
|
264
|
+
testResults.errors.forEach(({ test, error }) => {
|
|
265
|
+
console.log(` ${test}: ${error}`);
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
// Handle process termination
|
|
271
|
+
process.on('unhandledRejection', (reason, promise) => {
|
|
272
|
+
console.log('Unhandled Rejection at:', promise, 'reason:', reason);
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
// Run the tests
|
|
276
|
+
runTests().catch(console.error);
|
package/test-sdk.cjs
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
const { ApiSDK } = require('./dist/index.js');
|
|
2
|
+
|
|
3
|
+
// Custom storage implementation for Node.js
|
|
4
|
+
class NodeStorage {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.items = {};
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
getItem(key) {
|
|
10
|
+
return this.items[key] || null;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
setItem(key, value) {
|
|
14
|
+
this.items[key] = value;
|
|
15
|
+
console.log(`Stored ${key}`);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
removeItem(key) {
|
|
19
|
+
delete this.items[key];
|
|
20
|
+
console.log(`Removed ${key}`);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const config = {
|
|
25
|
+
baseUrl: 'http://localhost:3000',
|
|
26
|
+
storage: new NodeStorage(),
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const sdk = new ApiSDK(config);
|
|
30
|
+
|
|
31
|
+
async function createTestUser() {
|
|
32
|
+
console.log('๐ง Creating test user directly via API...');
|
|
33
|
+
|
|
34
|
+
const createUserDto = {
|
|
35
|
+
email: 'test@example.com',
|
|
36
|
+
password: 'testpassword123',
|
|
37
|
+
firstName: 'Test',
|
|
38
|
+
lastName: 'User',
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
try {
|
|
42
|
+
const response = await fetch('http://localhost:3000/users', {
|
|
43
|
+
method: 'POST',
|
|
44
|
+
headers: {
|
|
45
|
+
'Content-Type': 'application/json',
|
|
46
|
+
},
|
|
47
|
+
body: JSON.stringify(createUserDto),
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
if (response.ok) {
|
|
51
|
+
const user = await response.json();
|
|
52
|
+
console.log('โ
Test user created:', user);
|
|
53
|
+
return {
|
|
54
|
+
email: createUserDto.email,
|
|
55
|
+
password: createUserDto.password,
|
|
56
|
+
};
|
|
57
|
+
} else {
|
|
58
|
+
const error = await response.json().catch(() => ({}));
|
|
59
|
+
console.log('โ ๏ธ User might already exist or need different approach:', error);
|
|
60
|
+
|
|
61
|
+
return {
|
|
62
|
+
email: 'test@example.com',
|
|
63
|
+
password: 'testpassword123',
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
} catch (error) {
|
|
67
|
+
console.log('โ ๏ธ Error creating user, trying with default credentials:', error);
|
|
68
|
+
return {
|
|
69
|
+
email: 'test@example.com',
|
|
70
|
+
password: 'testpassword123',
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
async function testSDK() {
|
|
76
|
+
try {
|
|
77
|
+
console.log('๐ Starting SDK Test...\n');
|
|
78
|
+
|
|
79
|
+
// Step 1: Create or get test credentials
|
|
80
|
+
const credentials = await createTestUser();
|
|
81
|
+
console.log('๐ Using credentials:', { email: credentials.email, password: '***' });
|
|
82
|
+
|
|
83
|
+
// Step 2: Test login
|
|
84
|
+
console.log('\n๐ Testing login...');
|
|
85
|
+
const loginResponse = await sdk.login(credentials);
|
|
86
|
+
console.log('โ
Login successful!');
|
|
87
|
+
console.log('Access token:', loginResponse.access_token.substring(0, 20) + '...');
|
|
88
|
+
console.log('User ID:', loginResponse.user.id);
|
|
89
|
+
console.log('User Email:', loginResponse.user.email);
|
|
90
|
+
|
|
91
|
+
// Step 3: Test get profile
|
|
92
|
+
console.log('\n๐ค Testing get profile...');
|
|
93
|
+
try {
|
|
94
|
+
const profile = await sdk.getProfile();
|
|
95
|
+
console.log('โ
Profile retrieved - ID:', profile.id, 'Email:', profile.email);
|
|
96
|
+
} catch (error) {
|
|
97
|
+
console.log('โ ๏ธ Profile error:', error.message);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Step 4: Test template categories
|
|
101
|
+
console.log('\n๐ Testing template categories...');
|
|
102
|
+
try {
|
|
103
|
+
const categories = await sdk.getTemplateCategories();
|
|
104
|
+
console.log('โ
Template categories:', categories.length, 'found');
|
|
105
|
+
if (categories.length > 0) {
|
|
106
|
+
console.log('First category:', categories[0]);
|
|
107
|
+
}
|
|
108
|
+
} catch (error) {
|
|
109
|
+
console.log('โ ๏ธ Template categories error:', error.message);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Step 5: Test templates
|
|
113
|
+
console.log('\n๐ Testing templates...');
|
|
114
|
+
try {
|
|
115
|
+
const templates = await sdk.getTemplates();
|
|
116
|
+
console.log('โ
Templates retrieved:', templates.length, 'templates');
|
|
117
|
+
if (templates.length > 0) {
|
|
118
|
+
console.log('First template:', templates[0].title);
|
|
119
|
+
}
|
|
120
|
+
} catch (error) {
|
|
121
|
+
console.log('โ ๏ธ Templates error:', error.message);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Step 6: Test user templates
|
|
125
|
+
console.log('\n๐ Testing user templates...');
|
|
126
|
+
try {
|
|
127
|
+
const userTemplates = await sdk.getUserTemplates();
|
|
128
|
+
console.log('โ
User templates retrieved:', userTemplates.length, 'templates');
|
|
129
|
+
} catch (error) {
|
|
130
|
+
console.log('โ ๏ธ User templates error:', error.message);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// Step 7: Test organizations (if user has access)
|
|
134
|
+
console.log('\n๐ข Testing organizations...');
|
|
135
|
+
try {
|
|
136
|
+
const organizations = await sdk.getOrganizations();
|
|
137
|
+
console.log('โ
Organizations retrieved:', organizations.length, 'found');
|
|
138
|
+
} catch (error) {
|
|
139
|
+
console.log('โ ๏ธ Organizations error (might need admin access):', error.message);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// Step 8: Test teams (if user has access)
|
|
143
|
+
console.log('\n๐ฅ Testing teams...');
|
|
144
|
+
try {
|
|
145
|
+
const teams = await sdk.getTeams();
|
|
146
|
+
console.log('โ
Teams retrieved:', teams.length, 'found');
|
|
147
|
+
} catch (error) {
|
|
148
|
+
console.log('โ ๏ธ Teams error (might need admin access):', error.message);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// Step 9: Test creating a template category (if allowed)
|
|
152
|
+
console.log('\n๐ Testing create template category...');
|
|
153
|
+
try {
|
|
154
|
+
const newCategory = await sdk.createTemplateCategory('Test Category ' + Date.now());
|
|
155
|
+
console.log('โ
Template category created:', newCategory);
|
|
156
|
+
} catch (error) {
|
|
157
|
+
console.log('โ ๏ธ Create template category error:', error.message);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// Step 10: Test creating a user template
|
|
161
|
+
console.log('\n๐ Testing create user template...');
|
|
162
|
+
try {
|
|
163
|
+
const userTemplate = await sdk.createUserTemplate(
|
|
164
|
+
'Test User Template',
|
|
165
|
+
'This is a test template content',
|
|
166
|
+
undefined // no original template
|
|
167
|
+
);
|
|
168
|
+
console.log('โ
User template created:', userTemplate.title);
|
|
169
|
+
} catch (error) {
|
|
170
|
+
console.log('โ ๏ธ Create user template error:', error.message);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// Step 11: Test logout
|
|
174
|
+
console.log('\n๐ช Testing logout...');
|
|
175
|
+
await sdk.logout();
|
|
176
|
+
console.log('โ
Logout successful!');
|
|
177
|
+
console.log('Is authenticated:', sdk.isAuthenticated());
|
|
178
|
+
|
|
179
|
+
console.log('\n๐ SDK Test completed successfully!');
|
|
180
|
+
|
|
181
|
+
} catch (error) {
|
|
182
|
+
console.error('โ SDK Test failed:', error);
|
|
183
|
+
if (error instanceof Error) {
|
|
184
|
+
console.error('Error message:', error.message);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// Run the test
|
|
190
|
+
testSDK().catch(console.error);
|
package/test-sdk.mjs
ADDED
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import { ApiSDK } from './dist/index.js';
|
|
2
|
+
|
|
3
|
+
// Custom storage implementation for Node.js
|
|
4
|
+
class NodeStorage {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.items = {};
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
getItem(key) {
|
|
10
|
+
return this.items[key] || null;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
setItem(key, value) {
|
|
14
|
+
this.items[key] = value;
|
|
15
|
+
console.log(`โ
Stored ${key}`);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
removeItem(key) {
|
|
19
|
+
delete this.items[key];
|
|
20
|
+
console.log(`๐๏ธ Removed ${key}`);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const config = {
|
|
25
|
+
baseUrl: 'http://localhost:3000',
|
|
26
|
+
storage: new NodeStorage(),
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const sdk = new ApiSDK(config);
|
|
30
|
+
|
|
31
|
+
async function createTestUser() {
|
|
32
|
+
console.log('๐ง Creating test user directly via API...');
|
|
33
|
+
|
|
34
|
+
const createUserDto = {
|
|
35
|
+
email: 'test@example.com',
|
|
36
|
+
password: 'testpassword123',
|
|
37
|
+
firstName: 'Test',
|
|
38
|
+
lastName: 'User',
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
try {
|
|
42
|
+
const response = await fetch('http://localhost:3000/users', {
|
|
43
|
+
method: 'POST',
|
|
44
|
+
headers: {
|
|
45
|
+
'Content-Type': 'application/json',
|
|
46
|
+
},
|
|
47
|
+
body: JSON.stringify(createUserDto),
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
if (response.ok) {
|
|
51
|
+
const user = await response.json();
|
|
52
|
+
console.log('โ
Test user created:', user.email);
|
|
53
|
+
return {
|
|
54
|
+
email: createUserDto.email,
|
|
55
|
+
password: createUserDto.password,
|
|
56
|
+
};
|
|
57
|
+
} else {
|
|
58
|
+
const error = await response.json().catch(() => ({ message: `Status: ${response.status}` }));
|
|
59
|
+
console.log('โ ๏ธ User creation response:', error);
|
|
60
|
+
|
|
61
|
+
// Try with existing credentials
|
|
62
|
+
return {
|
|
63
|
+
email: 'test@example.com',
|
|
64
|
+
password: 'testpassword123',
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
} catch (error) {
|
|
68
|
+
console.log('โ ๏ธ Error creating user, trying with default credentials:', error.message);
|
|
69
|
+
return {
|
|
70
|
+
email: 'test@example.com',
|
|
71
|
+
password: 'testpassword123',
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
async function testSDK() {
|
|
77
|
+
try {
|
|
78
|
+
console.log('๐ Starting SDK Test against localhost:3000...\n');
|
|
79
|
+
|
|
80
|
+
// Step 1: Create or get test credentials
|
|
81
|
+
const credentials = await createTestUser();
|
|
82
|
+
console.log('๐ Using credentials:', { email: credentials.email, password: '***' });
|
|
83
|
+
|
|
84
|
+
// Step 2: Test login
|
|
85
|
+
console.log('\n๐ Testing login...');
|
|
86
|
+
const loginResponse = await sdk.login(credentials);
|
|
87
|
+
console.log('โ
Login successful!');
|
|
88
|
+
console.log('๐ Access token:', loginResponse.access_token.substring(0, 20) + '...');
|
|
89
|
+
console.log('๐ค User ID:', loginResponse.user.id);
|
|
90
|
+
console.log('๐ง User Email:', loginResponse.user.email);
|
|
91
|
+
console.log('๐ข Organization ID:', loginResponse.user.organizationId);
|
|
92
|
+
|
|
93
|
+
// Step 3: Test get profile
|
|
94
|
+
console.log('\n๐ค Testing get profile...');
|
|
95
|
+
try {
|
|
96
|
+
const profile = await sdk.getProfile();
|
|
97
|
+
console.log('โ
Profile retrieved - ID:', profile.id, 'Email:', profile.email);
|
|
98
|
+
} catch (error) {
|
|
99
|
+
console.log('โ ๏ธ Profile error:', error.message);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Step 4: Test template categories
|
|
103
|
+
console.log('\n๐ Testing template categories...');
|
|
104
|
+
try {
|
|
105
|
+
const categories = await sdk.getTemplateCategories();
|
|
106
|
+
console.log('โ
Template categories:', categories.length, 'found');
|
|
107
|
+
if (categories.length > 0) {
|
|
108
|
+
console.log('๐ First category:', categories[0]);
|
|
109
|
+
}
|
|
110
|
+
} catch (error) {
|
|
111
|
+
console.log('โ ๏ธ Template categories error:', error.message);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// Step 5: Test templates
|
|
115
|
+
console.log('\n๐ Testing templates...');
|
|
116
|
+
try {
|
|
117
|
+
const templates = await sdk.getTemplates();
|
|
118
|
+
console.log('โ
Templates retrieved:', templates.length, 'templates');
|
|
119
|
+
if (templates.length > 0) {
|
|
120
|
+
console.log('๐ First template:', templates[0].title);
|
|
121
|
+
}
|
|
122
|
+
} catch (error) {
|
|
123
|
+
console.log('โ ๏ธ Templates error:', error.message);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// Step 6: Test user templates
|
|
127
|
+
console.log('\n๐ Testing user templates...');
|
|
128
|
+
try {
|
|
129
|
+
const userTemplates = await sdk.getUserTemplates();
|
|
130
|
+
console.log('โ
User templates retrieved:', userTemplates.length, 'templates');
|
|
131
|
+
if (userTemplates.length > 0) {
|
|
132
|
+
console.log('๐ First user template:', userTemplates[0].title);
|
|
133
|
+
}
|
|
134
|
+
} catch (error) {
|
|
135
|
+
console.log('โ ๏ธ User templates error:', error.message);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// Step 7: Test organizations (if user has access)
|
|
139
|
+
console.log('\n๐ข Testing organizations...');
|
|
140
|
+
try {
|
|
141
|
+
const organizations = await sdk.getOrganizations();
|
|
142
|
+
console.log('โ
Organizations retrieved:', organizations.length, 'found');
|
|
143
|
+
if (organizations.length > 0) {
|
|
144
|
+
console.log('๐ข First org:', organizations[0].name);
|
|
145
|
+
}
|
|
146
|
+
} catch (error) {
|
|
147
|
+
console.log('โ ๏ธ Organizations error (might need admin access):', error.message);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// Step 8: Test teams (if user has access)
|
|
151
|
+
console.log('\n๐ฅ Testing teams...');
|
|
152
|
+
try {
|
|
153
|
+
const teams = await sdk.getTeams();
|
|
154
|
+
console.log('โ
Teams retrieved:', teams.length, 'found');
|
|
155
|
+
if (teams.length > 0) {
|
|
156
|
+
console.log('๐ฅ First team:', teams[0].name);
|
|
157
|
+
}
|
|
158
|
+
} catch (error) {
|
|
159
|
+
console.log('โ ๏ธ Teams error (might need admin access):', error.message);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// Step 9: Test transcription summaries for current user
|
|
163
|
+
console.log('\n๐ Testing transcription summaries...');
|
|
164
|
+
try {
|
|
165
|
+
const profile = sdk.getCurrentUser();
|
|
166
|
+
if (profile) {
|
|
167
|
+
const summaries = await sdk.getTranscriptionSummariesByUser(profile.id);
|
|
168
|
+
console.log('โ
Transcription summaries retrieved:', summaries.length, 'summaries');
|
|
169
|
+
}
|
|
170
|
+
} catch (error) {
|
|
171
|
+
console.log('โ ๏ธ Transcription summaries error:', error.message);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// Step 10: Test creating a user template
|
|
175
|
+
console.log('\n๐ Testing create user template...');
|
|
176
|
+
try {
|
|
177
|
+
const userTemplate = await sdk.createUserTemplate(
|
|
178
|
+
'SDK Test Template - ' + new Date().toISOString(),
|
|
179
|
+
'This is a test template created by the SDK test',
|
|
180
|
+
undefined // no original template
|
|
181
|
+
);
|
|
182
|
+
console.log('โ
User template created:', userTemplate.title);
|
|
183
|
+
|
|
184
|
+
// Test updating the template
|
|
185
|
+
console.log('\n๐ Testing update user template...');
|
|
186
|
+
const updatedTemplate = await sdk.updateUserTemplate(
|
|
187
|
+
userTemplate.id,
|
|
188
|
+
'Updated SDK Test Template - ' + new Date().toISOString(),
|
|
189
|
+
'This template was updated by the SDK test'
|
|
190
|
+
);
|
|
191
|
+
console.log('โ
User template updated:', updatedTemplate.title);
|
|
192
|
+
|
|
193
|
+
} catch (error) {
|
|
194
|
+
console.log('โ ๏ธ Create/update user template error:', error.message);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// Step 11: Test base64 audio transcription (if working)
|
|
198
|
+
console.log('\n๐๏ธ Testing base64 audio transcription...');
|
|
199
|
+
try {
|
|
200
|
+
// This is a very short base64 audio sample - replace with actual audio
|
|
201
|
+
const mockBase64Audio = 'SGVsbG8gV29ybGQ='; // "Hello World" in base64
|
|
202
|
+
const transcription = await sdk.transcribeBase64Audio(mockBase64Audio);
|
|
203
|
+
console.log('โ
Audio transcription result:', transcription);
|
|
204
|
+
} catch (error) {
|
|
205
|
+
console.log('โ ๏ธ Audio transcription error (expected with mock data):', error.message);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// Step 12: Test logout
|
|
209
|
+
console.log('\n๐ช Testing logout...');
|
|
210
|
+
await sdk.logout();
|
|
211
|
+
console.log('โ
Logout successful!');
|
|
212
|
+
console.log('๐ Is authenticated:', sdk.isAuthenticated());
|
|
213
|
+
|
|
214
|
+
console.log('\n๐ SDK Test completed successfully!');
|
|
215
|
+
console.log('๐ All major SDK functionality has been tested against localhost:3000');
|
|
216
|
+
|
|
217
|
+
} catch (error) {
|
|
218
|
+
console.error('โ SDK Test failed:', error);
|
|
219
|
+
if (error instanceof Error) {
|
|
220
|
+
console.error('๐ฅ Error message:', error.message);
|
|
221
|
+
console.error('๐ Stack trace:', error.stack);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// Run the test
|
|
227
|
+
console.log('๐ฏ Testing whio-SDK against localhost:3000...');
|
|
228
|
+
testSDK().catch(console.error);
|