@taruvi/sdk 1.4.6 → 1.4.7
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
|
@@ -107,6 +107,13 @@ export class Database<T = Record<string, unknown>> {
|
|
|
107
107
|
}, { ...this.graphParams }, this.isEdges)
|
|
108
108
|
}
|
|
109
109
|
|
|
110
|
+
allowedActions(actions: string[]): Database<T> {
|
|
111
|
+
return new Database<T>(this.client, { ...this.urlParams }, undefined, undefined, {
|
|
112
|
+
...this.queryParams,
|
|
113
|
+
allowed_actions: actions.join(',')
|
|
114
|
+
}, { ...this.graphParams }, this.isEdges)
|
|
115
|
+
}
|
|
116
|
+
|
|
110
117
|
aggregate(...expressions: string[]): Database<T> {
|
|
111
118
|
return new Database<T>(this.client, { ...this.urlParams }, undefined, undefined, {
|
|
112
119
|
...this.queryParams,
|
|
@@ -7,7 +7,7 @@ import type { ErrorResponseBody } from "../errors/index.js";
|
|
|
7
7
|
/**
|
|
8
8
|
* HttpClient handles all HTTP requests to the Taruvi API.
|
|
9
9
|
* Sends session token via X-Session-Token header.
|
|
10
|
-
* Clears tokens on 401
|
|
10
|
+
* Clears tokens on 401 auth failures.
|
|
11
11
|
*
|
|
12
12
|
* @internal
|
|
13
13
|
*/
|
|
@@ -37,12 +37,14 @@ export class HttpClient {
|
|
|
37
37
|
return config
|
|
38
38
|
})
|
|
39
39
|
|
|
40
|
-
// Response interceptor: clear tokens on
|
|
40
|
+
// Response interceptor: clear tokens on authentication failure
|
|
41
|
+
// Only 401 (Unauthorized) means the session is invalid
|
|
42
|
+
// 403 (Forbidden) means authenticated but lacking permission — don't clear tokens
|
|
41
43
|
this.axiosInstance.interceptors.response.use(
|
|
42
44
|
(response) => response,
|
|
43
45
|
(error: AxiosError) => {
|
|
44
46
|
const status = error.response?.status
|
|
45
|
-
if (status === 401
|
|
47
|
+
if (status === 401) {
|
|
46
48
|
this.tokenClient.clearTokens()
|
|
47
49
|
}
|
|
48
50
|
return Promise.reject(error)
|
|
@@ -132,7 +132,7 @@ describe('Encoding edge cases', () => {
|
|
|
132
132
|
it('handles storage bucket with hyphens', async () => {
|
|
133
133
|
mockHttpClient.get.mockResolvedValue([])
|
|
134
134
|
await new Storage(mockClient).from('my-bucket-name').execute()
|
|
135
|
-
expect(mockHttpClient.get).toHaveBeenCalledWith(expect.stringContaining('/buckets/my-bucket-name/'))
|
|
135
|
+
expect(mockHttpClient.get).toHaveBeenCalledWith(expect.stringContaining('/buckets/my-bucket-name/'), undefined)
|
|
136
136
|
})
|
|
137
137
|
|
|
138
138
|
it('handles empty string filter value', async () => {
|
|
@@ -32,7 +32,7 @@ describe('Storage', () => {
|
|
|
32
32
|
it('applies search filter', async () => {
|
|
33
33
|
mockHttpClient.get.mockResolvedValue([])
|
|
34
34
|
await new Storage(mockClient).from('documents').filter({ search: 'invoice' }).execute()
|
|
35
|
-
expect(mockHttpClient.get).toHaveBeenCalledWith(expect.stringContaining('search=invoice'))
|
|
35
|
+
expect(mockHttpClient.get).toHaveBeenCalledWith(expect.stringContaining('search=invoice'), undefined)
|
|
36
36
|
})
|
|
37
37
|
|
|
38
38
|
it('applies size filters', async () => {
|
|
@@ -46,19 +46,19 @@ describe('Storage', () => {
|
|
|
46
46
|
it('applies date filters', async () => {
|
|
47
47
|
mockHttpClient.get.mockResolvedValue([])
|
|
48
48
|
await new Storage(mockClient).from('documents').filter({ created_at__gte: '2024-01-01' }).execute()
|
|
49
|
-
expect(mockHttpClient.get).toHaveBeenCalledWith(expect.stringContaining('created_at__gte=2024-01-01'))
|
|
49
|
+
expect(mockHttpClient.get).toHaveBeenCalledWith(expect.stringContaining('created_at__gte=2024-01-01'), undefined)
|
|
50
50
|
})
|
|
51
51
|
|
|
52
52
|
it('applies mimetype filter', async () => {
|
|
53
53
|
mockHttpClient.get.mockResolvedValue([])
|
|
54
54
|
await new Storage(mockClient).from('documents').filter({ mimetype: 'application/pdf' }).execute()
|
|
55
|
-
expect(mockHttpClient.get).toHaveBeenCalledWith(expect.stringContaining('mimetype=application%2Fpdf'))
|
|
55
|
+
expect(mockHttpClient.get).toHaveBeenCalledWith(expect.stringContaining('mimetype=application%2Fpdf'), undefined)
|
|
56
56
|
})
|
|
57
57
|
|
|
58
58
|
it('applies visibility filter', async () => {
|
|
59
59
|
mockHttpClient.get.mockResolvedValue([])
|
|
60
60
|
await new Storage(mockClient).from('documents').filter({ visibility: 'public' }).execute()
|
|
61
|
-
expect(mockHttpClient.get).toHaveBeenCalledWith(expect.stringContaining('visibility=public'))
|
|
61
|
+
expect(mockHttpClient.get).toHaveBeenCalledWith(expect.stringContaining('visibility=public'), undefined)
|
|
62
62
|
})
|
|
63
63
|
|
|
64
64
|
it('applies pagination filters', async () => {
|
|
@@ -72,7 +72,7 @@ describe('Storage', () => {
|
|
|
72
72
|
it('applies ordering filter', async () => {
|
|
73
73
|
mockHttpClient.get.mockResolvedValue([])
|
|
74
74
|
await new Storage(mockClient).from('documents').filter({ ordering: '-created_at' }).execute()
|
|
75
|
-
expect(mockHttpClient.get).toHaveBeenCalledWith(expect.stringContaining('ordering=-created_at'))
|
|
75
|
+
expect(mockHttpClient.get).toHaveBeenCalledWith(expect.stringContaining('ordering=-created_at'), undefined)
|
|
76
76
|
})
|
|
77
77
|
})
|
|
78
78
|
|
|
@@ -80,7 +80,7 @@ describe('Storage', () => {
|
|
|
80
80
|
it('calls httpClient.get with encoded path', async () => {
|
|
81
81
|
mockHttpClient.get.mockResolvedValue(new Blob())
|
|
82
82
|
await new Storage(mockClient).from('documents').download('path/to/file.pdf').execute()
|
|
83
|
-
expect(mockHttpClient.get).toHaveBeenCalledWith(expect.stringContaining('path%2Fto%2Ffile.pdf'))
|
|
83
|
+
expect(mockHttpClient.get).toHaveBeenCalledWith(expect.stringContaining('path%2Fto%2Ffile.pdf'), { responseType: 'blob' })
|
|
84
84
|
})
|
|
85
85
|
})
|
|
86
86
|
|
|
@@ -141,14 +141,15 @@ describe('Storage', () => {
|
|
|
141
141
|
it('builds correct base URL with app slug and bucket', async () => {
|
|
142
142
|
mockHttpClient.get.mockResolvedValue([])
|
|
143
143
|
await new Storage(mockClient).from('documents').execute()
|
|
144
|
-
expect(mockHttpClient.get).toHaveBeenCalledWith('api/apps/test-app/storage/buckets/documents/objects/')
|
|
144
|
+
expect(mockHttpClient.get).toHaveBeenCalledWith('api/apps/test-app/storage/buckets/documents/objects/', undefined)
|
|
145
145
|
})
|
|
146
146
|
|
|
147
147
|
it('builds correct URL for download with encoded path', async () => {
|
|
148
148
|
mockHttpClient.get.mockResolvedValue(new Blob())
|
|
149
149
|
await new Storage(mockClient).from('documents').download('folder/file name.pdf').execute()
|
|
150
150
|
expect(mockHttpClient.get).toHaveBeenCalledWith(
|
|
151
|
-
'api/apps/test-app/storage/buckets/documents/objects/folder%2Ffile%20name.pdf
|
|
151
|
+
'api/apps/test-app/storage/buckets/documents/objects/folder%2Ffile%20name.pdf/',
|
|
152
|
+
{ responseType: 'blob' }
|
|
152
153
|
)
|
|
153
154
|
})
|
|
154
155
|
|