whio-api-sdk 1.0.9 → 1.0.11

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.
@@ -8,6 +8,7 @@ export declare class ApiSDK {
8
8
  constructor(config?: SDKConfig);
9
9
  private initialize;
10
10
  private request;
11
+ private fileUploadRequest;
11
12
  login(credentials: LoginCredentials): Promise<LoginResponse>;
12
13
  logout(): Promise<void>;
13
14
  private clearAuth;
@@ -38,4 +39,5 @@ export declare class ApiSDK {
38
39
  updateTranscriptionSummary(id: string, content: string): Promise<TranscriptionSummary>;
39
40
  uploadLargeAudioFile(formData: FormData): Promise<string>;
40
41
  uploadAudioFile(formData: FormData): Promise<TranscriptionAudioUploadResponse | null>;
42
+ transcribeBase64Audio(base64String: String): Promise<String>;
41
43
  }
@@ -52,6 +52,28 @@ export class ApiSDK {
52
52
  return response.json();
53
53
  });
54
54
  }
55
+ fileUploadRequest(endpoint, body, headers = {}) {
56
+ return __awaiter(this, void 0, void 0, function* () {
57
+ const url = `${this.baseUrl}${endpoint}`;
58
+ const defaultHeaders = {
59
+ 'Content-Type': 'multipart/form-data',
60
+ 'ngrok-skip-browser-warning': 'true'
61
+ };
62
+ if (this.accessToken) {
63
+ defaultHeaders['Authorization'] = `Bearer ${this.accessToken}`;
64
+ }
65
+ const response = yield fetch(url, {
66
+ method: 'POST',
67
+ headers: Object.assign(Object.assign({}, defaultHeaders), headers),
68
+ body,
69
+ });
70
+ if (!response.ok) {
71
+ const errorData = yield response.json().catch(() => ({}));
72
+ throw new Error(errorData.message || `Request failed with status ${response.status}`);
73
+ }
74
+ return response.json();
75
+ });
76
+ }
55
77
  login(credentials) {
56
78
  return __awaiter(this, void 0, void 0, function* () {
57
79
  try {
@@ -289,7 +311,7 @@ export class ApiSDK {
289
311
  }
290
312
  uploadLargeAudioFile(formData) {
291
313
  return __awaiter(this, void 0, void 0, function* () {
292
- const uploadId = yield this.request(urls.uploadAudioLarge, 'POST', formData, { 'Content-Type': 'multipart/form-data' });
314
+ const uploadId = yield this.fileUploadRequest(urls.uploadAudioLarge, formData);
293
315
  const uploadIds = (yield this.storage.getItem('uploadIds')) || '[]';
294
316
  const uploadIdsArray = JSON.parse(uploadIds);
295
317
  yield this.storage.setItem('uploadIds', JSON.stringify([...uploadIdsArray, uploadId]));
@@ -298,8 +320,14 @@ export class ApiSDK {
298
320
  }
299
321
  uploadAudioFile(formData) {
300
322
  return __awaiter(this, void 0, void 0, function* () {
301
- const data = yield this.request(urls.uploadAudio, 'POST', formData, { 'Content-Type': 'multipart/form-data' });
323
+ const data = yield this.fileUploadRequest(urls.uploadAudio, formData);
302
324
  return data;
303
325
  });
304
326
  }
327
+ transcribeBase64Audio(base64String) {
328
+ return __awaiter(this, void 0, void 0, function* () {
329
+ const transcript = yield this.request(urls.transcribeBase64Audio, 'POST', { base64Audio: base64String });
330
+ return transcript;
331
+ });
332
+ }
305
333
  }
@@ -18,5 +18,6 @@ declare const urls: {
18
18
  transcriptionSummary: string;
19
19
  uploadAudioLarge: string;
20
20
  uploadAudio: string;
21
+ transcribeBase64Audio: string;
21
22
  };
22
23
  export default urls;
@@ -18,5 +18,6 @@ const urls = {
18
18
  transcriptionSummary: '/transcription-summaries',
19
19
  uploadAudioLarge: '/transcription-summaries/upload-audio-large',
20
20
  uploadAudio: '/transcription-summaries/upload-audio',
21
+ transcribeBase64Audio: '/transcription-summaries/transcribe-base64',
21
22
  };
22
23
  export default urls;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "whio-api-sdk",
3
- "version": "1.0.9",
3
+ "version": "1.0.11",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "type": "module",
package/src/sdk/sdk.ts CHANGED
@@ -84,6 +84,37 @@ export class ApiSDK {
84
84
  return response.json();
85
85
  }
86
86
 
87
+ private async fileUploadRequest<T>(
88
+ endpoint: string,
89
+ body?: FormData,
90
+ headers: Record<string, string> = {}
91
+ ): Promise<T> {
92
+ const url = `${this.baseUrl}${endpoint}`;
93
+ const defaultHeaders: Record<string, string> = {
94
+ 'Content-Type': 'multipart/form-data',
95
+ 'ngrok-skip-browser-warning': 'true'
96
+ };
97
+
98
+ if (this.accessToken) {
99
+ defaultHeaders['Authorization'] = `Bearer ${this.accessToken}`;
100
+ }
101
+
102
+ const response = await fetch(url, {
103
+ method: 'POST',
104
+ headers: { ...defaultHeaders, ...headers },
105
+ body,
106
+ });
107
+
108
+ if (!response.ok) {
109
+ const errorData = await response.json().catch(() => ({}));
110
+ throw new Error(
111
+ errorData.message || `Request failed with status ${response.status}`
112
+ );
113
+ }
114
+
115
+ return response.json();
116
+ }
117
+
87
118
  public async login(credentials: LoginCredentials): Promise<LoginResponse> {
88
119
  try {
89
120
  const response = await this.request<LoginResponse>(
@@ -349,11 +380,9 @@ export class ApiSDK {
349
380
  }
350
381
 
351
382
  public async uploadLargeAudioFile(formData: FormData): Promise<string> {
352
- const uploadId: string = await this.request(
383
+ const uploadId: string = await this.fileUploadRequest(
353
384
  urls.uploadAudioLarge,
354
- 'POST',
355
- formData,
356
- { 'Content-Type': 'multipart/form-data' }
385
+ formData
357
386
  );
358
387
  const uploadIds: string = await this.storage!.getItem('uploadIds') || '[]';
359
388
  const uploadIdsArray = JSON.parse(uploadIds);
@@ -362,16 +391,19 @@ export class ApiSDK {
362
391
  }
363
392
 
364
393
  public async uploadAudioFile(formData: FormData): Promise<TranscriptionAudioUploadResponse | null> {
365
- const data: TranscriptionAudioUploadResponse = await this.request(
394
+ const data: TranscriptionAudioUploadResponse = await this.fileUploadRequest(
366
395
  urls.uploadAudio,
367
- 'POST',
368
396
  formData,
369
- { 'Content-Type': 'multipart/form-data' }
370
397
  );
371
398
  return data;
372
399
  }
373
400
 
374
-
375
-
401
+ public async transcribeBase64Audio(base64String: String): Promise<String> {
402
+ const transcript = await this.request<String>(
403
+ urls.transcribeBase64Audio,
404
+ 'POST',
405
+ { base64Audio: base64String });
406
+ return transcript;
407
+ }
376
408
 
377
409
  }
package/src/sdk/urls.ts CHANGED
@@ -18,6 +18,7 @@ const urls = {
18
18
  transcriptionSummary: '/transcription-summaries',
19
19
  uploadAudioLarge: '/transcription-summaries/upload-audio-large',
20
20
  uploadAudio: '/transcription-summaries/upload-audio',
21
+ transcribeBase64Audio: '/transcription-summaries/transcribe-base64',
21
22
  }
22
23
 
23
24
  export default urls;