@taruvi/sdk 1.4.3 → 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.3",
3
+ "version": "1.4.5",
4
4
  "description": "Taruvi SDK",
5
5
  "main": "src/index.ts",
6
6
  "type": "module",
package/src/client.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { HttpClient } from "./lib-internal/http/HttpClient.js";
2
2
  import { TokenClient, type AuthTokens } from "./lib-internal/token/TokenClient.js";
3
3
  import type { TaruviConfig } from "./types.js";
4
+ import packageJson from "../package.json" with { type: "json" };
4
5
 
5
6
  export class Client {
6
7
  private readonly config: TaruviConfig
@@ -30,6 +31,8 @@ export class Client {
30
31
 
31
32
  // Check URL hash for tokens (OAuth callback)
32
33
  this.extractTokensFromUrl()
34
+
35
+ console.info(`Taruvi SDK v${packageJson.version} initialized`)
33
36
  }
34
37
 
35
38
  /**
@@ -82,4 +85,4 @@ export class Client {
82
85
  getConfig(): Readonly<TaruviConfig> {
83
86
  return { ...this.config }
84
87
  }
85
- }
88
+ }
@@ -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
  }
@@ -1,11 +1,18 @@
1
1
  import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'
2
2
  import { Client } from '../../../src/client.js'
3
+ import packageJson from '../../../package.json' with { type: 'json' }
3
4
 
4
5
  describe('Client', () => {
6
+ const consoleInfoSpy = vi.spyOn(console, 'info').mockImplementation(() => undefined)
7
+
5
8
  beforeEach(() => {
6
9
  vi.clearAllMocks()
7
10
  })
8
11
 
12
+ afterEach(() => {
13
+ consoleInfoSpy.mockClear()
14
+ })
15
+
9
16
  describe('constructor', () => {
10
17
  it('throws error when config is not provided', () => {
11
18
  expect(() => new Client(undefined as any)).toThrow('Config is required')
@@ -30,6 +37,16 @@ describe('Client', () => {
30
37
  expect(client).toBeInstanceOf(Client)
31
38
  })
32
39
 
40
+ it('logs the sdk version when initialized', () => {
41
+ new Client({
42
+ apiKey: 'test-key',
43
+ appSlug: 'test-app',
44
+ apiUrl: 'https://api.test.com'
45
+ })
46
+
47
+ expect(consoleInfoSpy).toHaveBeenCalledWith(`Taruvi SDK v${packageJson.version} initialized`)
48
+ })
49
+
33
50
  it('initializes httpClient and tokenClient', () => {
34
51
  const client = new Client({
35
52
  apiKey: 'test-key',
package/tsconfig.json CHANGED
@@ -34,6 +34,7 @@
34
34
  "jsx": "react-jsx",
35
35
  "verbatimModuleSyntax": true,
36
36
  "isolatedModules": true,
37
+ "resolveJsonModule": true,
37
38
  "noUncheckedSideEffectImports": true,
38
39
  "moduleDetection": "force",
39
40
  "skipLibCheck": true,