@taruvi/sdk 1.4.4 → 1.4.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@taruvi/sdk",
3
- "version": "1.4.4",
3
+ "version": "1.4.5",
4
4
  "description": "Taruvi SDK",
5
5
  "main": "src/index.ts",
6
6
  "type": "module",
@@ -52,6 +52,10 @@ export class Storage {
52
52
  }
53
53
 
54
54
  download(path: string): Storage {
55
+ return new Storage(this.client, { ...this.urlParams, path }, HttpMethod.GET)
56
+ }
57
+
58
+ metadata(path: string): Storage {
55
59
  return new Storage(this.client, { ...this.urlParams, path }, HttpMethod.GET, undefined, undefined, { metadata: 'true' })
56
60
  }
57
61
 
@@ -118,8 +122,10 @@ export class Storage {
118
122
  return await this.client.httpClient.delete<T>(url)
119
123
 
120
124
  case HttpMethod.GET:
121
- default:
122
- return await this.client.httpClient.get<T>(url)
125
+ default: {
126
+ const isDownload = this.urlParams.path && !this.queryParams?.metadata
127
+ return await this.client.httpClient.get<T>(url, isDownload ? { responseType: 'blob' } : undefined)
128
+ }
123
129
  }
124
130
  }
125
131
  }
@@ -66,10 +66,12 @@ export class HttpClient {
66
66
  throw error
67
67
  }
68
68
 
69
- async get<T>(endpoint: string): Promise<T> {
69
+ async get<T>(endpoint: string, options?: { responseType?: 'json' | 'blob' }): Promise<T> {
70
70
  try {
71
- const { data } = await this.axiosInstance.get<T>(`/${endpoint}`)
72
- return data
71
+ const { data } = await this.axiosInstance.get<T>(`/${endpoint}`, {
72
+ ...(options?.responseType && { responseType: options.responseType }),
73
+ })
74
+ return data as T
73
75
  } catch (error) {
74
76
  this.handleError(error)
75
77
  }