@taruvi/sdk 1.4.4 → 1.4.6
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 +1 -1
- package/src/lib/database/DatabaseClient.ts +3 -2
- package/src/lib/policy/PolicyClient.ts +2 -2
- package/src/lib/policy/types.ts +2 -3
- package/src/lib/storage/StorageClient.ts +8 -2
- package/src/lib-internal/http/HttpClient.ts +5 -3
- package/tests/unit/policy/PolicyClient.test.ts +4 -8
package/package.json
CHANGED
|
@@ -137,8 +137,9 @@ export class Database<T = Record<string, unknown>> {
|
|
|
137
137
|
return new Database<T>(this.client, { ...this.urlParams }, HttpMethod.POST, body as object, this.queryParams, { ...this.graphParams }, this.isEdges)
|
|
138
138
|
}
|
|
139
139
|
|
|
140
|
-
upsert(body: Partial<T> | Partial<T>[]): Database<T> {
|
|
141
|
-
|
|
140
|
+
upsert(body: Partial<T> | Partial<T>[], uniqueFields?: string[]): Database<T> {
|
|
141
|
+
const qp = uniqueFields?.length ? { ...this.queryParams, unique_fields: uniqueFields.join(',') } : this.queryParams
|
|
142
|
+
return new Database<T>(this.client, { ...this.urlParams }, HttpMethod.POST, body as object, qp, { ...this.graphParams }, this.isEdges, true)
|
|
142
143
|
}
|
|
143
144
|
|
|
144
145
|
update(body: Partial<T> | EdgeRequest): Database<T> {
|
|
@@ -16,7 +16,7 @@ export class Policy {
|
|
|
16
16
|
const body = {
|
|
17
17
|
resources: resources.map(r => ({
|
|
18
18
|
resource: {
|
|
19
|
-
kind:
|
|
19
|
+
kind: r.resource,
|
|
20
20
|
id: r.recordId,
|
|
21
21
|
attr: r.attributes || {}
|
|
22
22
|
},
|
|
@@ -76,4 +76,4 @@ export class Policy {
|
|
|
76
76
|
|
|
77
77
|
return []
|
|
78
78
|
}
|
|
79
|
-
}
|
|
79
|
+
}
|
package/src/lib/policy/types.ts
CHANGED
|
@@ -13,8 +13,7 @@ export type Resource = {
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
export type Resources = {
|
|
16
|
-
|
|
17
|
-
tableName: string
|
|
16
|
+
resource: string
|
|
18
17
|
recordId: string
|
|
19
18
|
attributes: Record<string, unknown>
|
|
20
19
|
actions: string[]
|
|
@@ -37,4 +36,4 @@ export type GetAllowedActionsOptions = {
|
|
|
37
36
|
}
|
|
38
37
|
|
|
39
38
|
// Response types - uses standard wrapper
|
|
40
|
-
export type ResourceCheckResponse = TaruviResponse<PolicyCheckBatchResult>
|
|
39
|
+
export type ResourceCheckResponse = TaruviResponse<PolicyCheckBatchResult>
|
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
}
|
|
@@ -24,8 +24,7 @@ describe('Policy', () => {
|
|
|
24
24
|
const policy = new Policy(mockClient)
|
|
25
25
|
const result = await policy.checkResource([
|
|
26
26
|
{
|
|
27
|
-
|
|
28
|
-
tableName: 'accounts',
|
|
27
|
+
resource: 'crm:accounts',
|
|
29
28
|
recordId: 'record-123',
|
|
30
29
|
attributes: { owner_id: 'user-456' },
|
|
31
30
|
actions: ['read']
|
|
@@ -60,15 +59,13 @@ describe('Policy', () => {
|
|
|
60
59
|
const policy = new Policy(mockClient)
|
|
61
60
|
await policy.checkResource([
|
|
62
61
|
{
|
|
63
|
-
|
|
64
|
-
tableName: 'accounts',
|
|
62
|
+
resource: 'crm:accounts',
|
|
65
63
|
recordId: 'acc-1',
|
|
66
64
|
attributes: {},
|
|
67
65
|
actions: ['read', 'update']
|
|
68
66
|
},
|
|
69
67
|
{
|
|
70
|
-
|
|
71
|
-
tableName: 'documents',
|
|
68
|
+
resource: 'docs:documents',
|
|
72
69
|
recordId: 'doc-1',
|
|
73
70
|
attributes: {},
|
|
74
71
|
actions: ['delete']
|
|
@@ -98,8 +95,7 @@ describe('Policy', () => {
|
|
|
98
95
|
const policy = new Policy(mockClient)
|
|
99
96
|
await policy.checkResource([
|
|
100
97
|
{
|
|
101
|
-
|
|
102
|
-
tableName: 'contacts',
|
|
98
|
+
resource: 'crm:contacts',
|
|
103
99
|
recordId: 'contact-1',
|
|
104
100
|
attributes: {},
|
|
105
101
|
actions: ['read']
|