whio-api-sdk 1.0.168 → 1.0.169

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.
@@ -1,4 +1,4 @@
1
- import { LoginResponse, LoginCredentials, SDKConfig, User, UpdateUserDto, Organization, TemplateCategory, Template, Team, UserTemplate, TranscriptionSummary, TranscriptionAudioUploadResponse, PasswordChangeResponse, Session, CreateSessionDto, UpdateSessionDto, Agent } from './types';
1
+ import { LoginResponse, LoginCredentials, SDKConfig, User, UpdateUserDto, Organization, TemplateCategory, Template, Team, UserTemplate, TranscriptionSummary, TranscriptionAudioUploadResponse, PasswordChangeResponse, Session, CreateSessionDto, UpdateSessionDto, Agent, AudioFile, UpdateAudioFileDto } from './types';
2
2
  export declare class ApiSDK {
3
3
  private baseUrl;
4
4
  private storage;
@@ -96,4 +96,14 @@ export declare class ApiSDK {
96
96
  deleteAgent(id: string): Promise<void>;
97
97
  addAgentToOrganization(agentId: string, organizationId: string): Promise<void>;
98
98
  removeAgentFromOrganization(agentId: string, organizationId: string): Promise<void>;
99
+ uploadAudioFileToSession(sessionId: string, file: File | Blob, fileName?: string): Promise<AudioFile>;
100
+ getMyAudioFiles(): Promise<AudioFile[]>;
101
+ getAllAudioFiles(): Promise<AudioFile[]>;
102
+ getOrganizationAudioFiles(): Promise<AudioFile[]>;
103
+ getAudioFilesBySession(sessionId: string): Promise<AudioFile[]>;
104
+ getAudioFile(id: string): Promise<AudioFile>;
105
+ updateAudioFile(id: string, updates: UpdateAudioFileDto): Promise<AudioFile>;
106
+ deleteAudioFile(id: string): Promise<void>;
107
+ downloadAudioFile(id: string): Promise<Blob>;
108
+ downloadAudioFileAsUrl(id: string): Promise<string>;
99
109
  }
@@ -718,4 +718,78 @@ export class ApiSDK {
718
718
  yield this.request(`${urls.agents}/${agentId}/organizations/${organizationId}`, 'DELETE');
719
719
  });
720
720
  }
721
+ // ======================
722
+ // AUDIO FILE METHODS
723
+ // ======================
724
+ uploadAudioFileToSession(sessionId, file, fileName) {
725
+ return __awaiter(this, void 0, void 0, function* () {
726
+ const formData = new FormData();
727
+ formData.append('file', file, fileName);
728
+ return this.fileUploadRequest(`${urls.audioFiles}/upload/${sessionId}`, formData);
729
+ });
730
+ }
731
+ getMyAudioFiles() {
732
+ return __awaiter(this, void 0, void 0, function* () {
733
+ return this.request(`${urls.audioFiles}/my-files`, 'GET');
734
+ });
735
+ }
736
+ getAllAudioFiles() {
737
+ return __awaiter(this, void 0, void 0, function* () {
738
+ return this.request(`${urls.audioFiles}/all`, 'GET');
739
+ });
740
+ }
741
+ getOrganizationAudioFiles() {
742
+ return __awaiter(this, void 0, void 0, function* () {
743
+ return this.request(`${urls.audioFiles}/organization`, 'GET');
744
+ });
745
+ }
746
+ getAudioFilesBySession(sessionId) {
747
+ return __awaiter(this, void 0, void 0, function* () {
748
+ return this.request(`${urls.audioFiles}/session/${sessionId}`, 'GET');
749
+ });
750
+ }
751
+ getAudioFile(id) {
752
+ return __awaiter(this, void 0, void 0, function* () {
753
+ return this.request(`${urls.audioFiles}/${id}`, 'GET');
754
+ });
755
+ }
756
+ updateAudioFile(id, updates) {
757
+ return __awaiter(this, void 0, void 0, function* () {
758
+ return this.request(`${urls.audioFiles}/${id}`, 'PATCH', updates);
759
+ });
760
+ }
761
+ deleteAudioFile(id) {
762
+ return __awaiter(this, void 0, void 0, function* () {
763
+ yield this.request(`${urls.audioFiles}/${id}`, 'DELETE');
764
+ });
765
+ }
766
+ downloadAudioFile(id) {
767
+ return __awaiter(this, void 0, void 0, function* () {
768
+ // For file downloads, we need a different approach than JSON requests
769
+ const url = `${this.baseUrl}${urls.audioFiles}/${id}/download`;
770
+ // Get token first
771
+ yield this.getToken();
772
+ const defaultHeaders = {
773
+ 'ngrok-skip-browser-warning': 'true'
774
+ };
775
+ if (this.accessToken) {
776
+ defaultHeaders['Authorization'] = `Bearer ${this.accessToken}`;
777
+ }
778
+ const response = yield fetch(url, {
779
+ method: 'GET',
780
+ headers: defaultHeaders,
781
+ });
782
+ if (!response.ok) {
783
+ const errorData = yield response.json().catch(() => ({}));
784
+ throw new Error(errorData.message || `Download failed with status ${response.status}`);
785
+ }
786
+ return response.blob();
787
+ });
788
+ }
789
+ downloadAudioFileAsUrl(id) {
790
+ return __awaiter(this, void 0, void 0, function* () {
791
+ const blob = yield this.downloadAudioFile(id);
792
+ return URL.createObjectURL(blob);
793
+ });
794
+ }
721
795
  }
@@ -327,3 +327,39 @@ export interface CreateAgentDto {
327
327
  export interface UpdateAgentDto {
328
328
  name?: string;
329
329
  }
330
+ export declare enum AudioFileStatus {
331
+ UPLOADED = "UPLOADED",
332
+ PROCESSING = "PROCESSING",
333
+ TRANSCRIBED = "TRANSCRIBED",
334
+ FAILED = "FAILED"
335
+ }
336
+ export interface AudioFile {
337
+ id: string;
338
+ originalName: string;
339
+ fileName: string;
340
+ filePath: string;
341
+ fileSize: number;
342
+ mimeType: string;
343
+ uploadId?: string;
344
+ transcriptionUrl?: string;
345
+ status: AudioFileStatus;
346
+ createdAt: string;
347
+ updatedAt: string;
348
+ sessionId: string;
349
+ userId: string;
350
+ session?: Session;
351
+ user?: User;
352
+ }
353
+ export interface CreateAudioFileDto {
354
+ originalName: string;
355
+ fileName: string;
356
+ filePath: string;
357
+ fileSize: number;
358
+ mimeType: string;
359
+ uploadId?: string;
360
+ sessionId: string;
361
+ }
362
+ export interface UpdateAudioFileDto {
363
+ transcriptionUrl?: string;
364
+ status?: AudioFileStatus;
365
+ }
@@ -13,3 +13,11 @@ export var RoleType;
13
13
  RoleType["TRIAL"] = "TRIAL";
14
14
  RoleType["PAID"] = "PAID";
15
15
  })(RoleType || (RoleType = {}));
16
+ // Audio File types
17
+ export var AudioFileStatus;
18
+ (function (AudioFileStatus) {
19
+ AudioFileStatus["UPLOADED"] = "UPLOADED";
20
+ AudioFileStatus["PROCESSING"] = "PROCESSING";
21
+ AudioFileStatus["TRANSCRIBED"] = "TRANSCRIBED";
22
+ AudioFileStatus["FAILED"] = "FAILED";
23
+ })(AudioFileStatus || (AudioFileStatus = {}));
@@ -26,5 +26,6 @@ declare const urls: {
26
26
  userRoles: string;
27
27
  sessions: string;
28
28
  agents: string;
29
+ audioFiles: string;
29
30
  };
30
31
  export default urls;
@@ -35,5 +35,7 @@ const urls = {
35
35
  sessions: '/sessions',
36
36
  // Agents
37
37
  agents: '/agents',
38
+ // Audio Files
39
+ audioFiles: '/audio-files',
38
40
  };
39
41
  export default urls;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "whio-api-sdk",
3
- "version": "1.0.168",
3
+ "version": "1.0.169",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "type": "module",
package/src/sdk/sdk.ts CHANGED
@@ -40,6 +40,10 @@ import {
40
40
  Agent,
41
41
  CreateAgentDto,
42
42
  UpdateAgentDto,
43
+ AudioFile,
44
+ AudioFileStatus,
45
+ CreateAudioFileDto,
46
+ UpdateAudioFileDto,
43
47
  } from './types';
44
48
  import urls from './urls';
45
49
  import { jwtDecode } from 'jwt-decode';
@@ -784,4 +788,78 @@ export class ApiSDK {
784
788
  await this.request(`${urls.agents}/${agentId}/organizations/${organizationId}`, 'DELETE');
785
789
  }
786
790
 
791
+ // ======================
792
+ // AUDIO FILE METHODS
793
+ // ======================
794
+
795
+ public async uploadAudioFileToSession(sessionId: string, file: File | Blob, fileName?: string): Promise<AudioFile> {
796
+ const formData = new FormData();
797
+ formData.append('file', file, fileName);
798
+
799
+ return this.fileUploadRequest<AudioFile>(`${urls.audioFiles}/upload/${sessionId}`, formData);
800
+ }
801
+
802
+ public async getMyAudioFiles(): Promise<AudioFile[]> {
803
+ return this.request<AudioFile[]>(`${urls.audioFiles}/my-files`, 'GET');
804
+ }
805
+
806
+ public async getAllAudioFiles(): Promise<AudioFile[]> {
807
+ return this.request<AudioFile[]>(`${urls.audioFiles}/all`, 'GET');
808
+ }
809
+
810
+ public async getOrganizationAudioFiles(): Promise<AudioFile[]> {
811
+ return this.request<AudioFile[]>(`${urls.audioFiles}/organization`, 'GET');
812
+ }
813
+
814
+ public async getAudioFilesBySession(sessionId: string): Promise<AudioFile[]> {
815
+ return this.request<AudioFile[]>(`${urls.audioFiles}/session/${sessionId}`, 'GET');
816
+ }
817
+
818
+ public async getAudioFile(id: string): Promise<AudioFile> {
819
+ return this.request<AudioFile>(`${urls.audioFiles}/${id}`, 'GET');
820
+ }
821
+
822
+ public async updateAudioFile(id: string, updates: UpdateAudioFileDto): Promise<AudioFile> {
823
+ return this.request<AudioFile>(`${urls.audioFiles}/${id}`, 'PATCH', updates);
824
+ }
825
+
826
+ public async deleteAudioFile(id: string): Promise<void> {
827
+ await this.request(`${urls.audioFiles}/${id}`, 'DELETE');
828
+ }
829
+
830
+ public async downloadAudioFile(id: string): Promise<Blob> {
831
+ // For file downloads, we need a different approach than JSON requests
832
+ const url = `${this.baseUrl}${urls.audioFiles}/${id}/download`;
833
+
834
+ // Get token first
835
+ await this.getToken();
836
+
837
+ const defaultHeaders: Record<string, string> = {
838
+ 'ngrok-skip-browser-warning': 'true'
839
+ };
840
+
841
+ if (this.accessToken) {
842
+ defaultHeaders['Authorization'] = `Bearer ${this.accessToken}`;
843
+ }
844
+
845
+ const response = await fetch(url, {
846
+ method: 'GET',
847
+ headers: defaultHeaders,
848
+ });
849
+
850
+ if (!response.ok) {
851
+ const errorData = await response.json().catch(() => ({}));
852
+ throw new Error(
853
+ errorData.message || `Download failed with status ${response.status}`
854
+ );
855
+ }
856
+
857
+ return response.blob();
858
+ }
859
+
860
+ public async downloadAudioFileAsUrl(id: string): Promise<string> {
861
+ const blob = await this.downloadAudioFile(id);
862
+ return URL.createObjectURL(blob);
863
+ }
864
+
787
865
  }
package/src/sdk/types.ts CHANGED
@@ -415,3 +415,48 @@ export interface CreateAgentDto {
415
415
  export interface UpdateAgentDto {
416
416
  name?: string;
417
417
  }
418
+
419
+ // Audio File types
420
+ export enum AudioFileStatus {
421
+ UPLOADED = 'UPLOADED',
422
+ PROCESSING = 'PROCESSING',
423
+ TRANSCRIBED = 'TRANSCRIBED',
424
+ FAILED = 'FAILED',
425
+ }
426
+
427
+ export interface AudioFile {
428
+ id: string;
429
+ originalName: string;
430
+ fileName: string;
431
+ filePath: string;
432
+ fileSize: number;
433
+ mimeType: string;
434
+ uploadId?: string;
435
+ transcriptionUrl?: string;
436
+ status: AudioFileStatus;
437
+ createdAt: string;
438
+ updatedAt: string;
439
+ sessionId: string;
440
+ userId: string;
441
+
442
+ // Relationships (populated by API)
443
+ session?: Session;
444
+ user?: User;
445
+ }
446
+
447
+ // Audio File DTOs
448
+ export interface CreateAudioFileDto {
449
+ originalName: string;
450
+ fileName: string;
451
+ filePath: string;
452
+ fileSize: number;
453
+ mimeType: string;
454
+ uploadId?: string;
455
+ sessionId: string;
456
+ // userId will be auto-injected by API
457
+ }
458
+
459
+ export interface UpdateAudioFileDto {
460
+ transcriptionUrl?: string;
461
+ status?: AudioFileStatus;
462
+ }
package/src/sdk/urls.ts CHANGED
@@ -43,6 +43,9 @@ const urls = {
43
43
 
44
44
  // Agents
45
45
  agents: '/agents',
46
+
47
+ // Audio Files
48
+ audioFiles: '/audio-files',
46
49
  }
47
50
 
48
51
  export default urls;
@@ -0,0 +1,92 @@
1
+ // Test audio files functionality
2
+ import { ApiSDK, AudioFileStatus } from './dist/index.js';
3
+
4
+ const sdk = new ApiSDK({
5
+ baseUrl: 'http://localhost:3000/api'
6
+ });
7
+
8
+ async function testAudioFiles() {
9
+ try {
10
+ // Login
11
+ const loginResponse = await sdk.login({
12
+ email: 'rimu.boddy@make.nz',
13
+ password: 'cbr400rr'
14
+ });
15
+ console.log('✅ Login successful');
16
+
17
+ // Get user sessions to find a session for audio upload
18
+ const sessions = await sdk.getSessions();
19
+ if (sessions.length === 0) {
20
+ console.log('❌ No sessions found. Create a session first.');
21
+ return;
22
+ }
23
+ const sessionId = sessions[0].id;
24
+ console.log('✅ Found session:', sessionId);
25
+
26
+ // Create a mock audio file (small MP3-like buffer)
27
+ const mockAudioData = new Uint8Array([
28
+ // Minimal MP3 header
29
+ 0x49, 0x44, 0x33, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09,
30
+ // Some fake MP3 data
31
+ 0x54, 0x58, 0x58, 0x58, 0x00, 0x00, 0x00, 0x0D, 0x00, 0x00,
32
+ 0x03, 0x74, 0x65, 0x73, 0x74, 0x20, 0x61, 0x75, 0x64, 0x69,
33
+ 0x6F, 0x20, 0x64, 0x61, 0x74, 0x61
34
+ ]);
35
+
36
+ const audioBlob = new Blob([mockAudioData], { type: 'audio/mpeg' });
37
+
38
+ // Test upload audio file
39
+ console.log('🔄 Testing audio file upload...');
40
+ const uploadedFile = await sdk.uploadAudioFileToSession(sessionId, audioBlob, 'test-audio.mp3');
41
+ console.log('✅ Audio file uploaded:', uploadedFile.id);
42
+ console.log(' - Original name:', uploadedFile.originalName);
43
+ console.log(' - Status:', uploadedFile.status);
44
+ console.log(' - File size:', uploadedFile.fileSize, 'bytes');
45
+
46
+ // Test get my audio files
47
+ console.log('🔄 Testing get my audio files...');
48
+ const myFiles = await sdk.getMyAudioFiles();
49
+ console.log('✅ Found', myFiles.length, 'audio files');
50
+
51
+ // Test get audio file details
52
+ console.log('🔄 Testing get audio file details...');
53
+ const fileDetails = await sdk.getAudioFile(uploadedFile.id);
54
+ console.log('✅ Audio file details:', fileDetails.originalName);
55
+
56
+ // Test get audio files by session
57
+ console.log('🔄 Testing get audio files by session...');
58
+ const sessionFiles = await sdk.getAudioFilesBySession(sessionId);
59
+ console.log('✅ Found', sessionFiles.length, 'audio files for session');
60
+
61
+ // Test update audio file
62
+ console.log('🔄 Testing update audio file...');
63
+ const updatedFile = await sdk.updateAudioFile(uploadedFile.id, {
64
+ status: AudioFileStatus.TRANSCRIBED,
65
+ transcriptionUrl: 'https://example.com/transcription'
66
+ });
67
+ console.log('✅ Audio file updated. New status:', updatedFile.status);
68
+
69
+ // Test download audio file
70
+ console.log('🔄 Testing download audio file...');
71
+ const downloadedBlob = await sdk.downloadAudioFile(uploadedFile.id);
72
+ console.log('✅ Audio file downloaded. Size:', downloadedBlob.size, 'bytes');
73
+
74
+ // Test download as URL
75
+ console.log('🔄 Testing download as URL...');
76
+ const downloadUrl = await sdk.downloadAudioFileAsUrl(uploadedFile.id);
77
+ console.log('✅ Audio file URL created:', downloadUrl.substring(0, 50) + '...');
78
+
79
+ // Clean up - delete the test file
80
+ console.log('🔄 Cleaning up - deleting test file...');
81
+ await sdk.deleteAudioFile(uploadedFile.id);
82
+ console.log('✅ Test file deleted');
83
+
84
+ console.log('\n🎉 All audio file SDK tests passed!');
85
+
86
+ } catch (error) {
87
+ console.error('❌ Test failed:', error.message);
88
+ console.error('Error details:', error);
89
+ }
90
+ }
91
+
92
+ testAudioFiles();