@taruvi/sdk 1.3.3 → 1.3.4-beta.0
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/.claude/settings.local.json +19 -0
- package/.kiro/settings/lsp.json +198 -0
- package/MODULE_NAMING_CHANGES.md +81 -0
- package/PARAMETER_NAMING_CHANGES.md +106 -0
- package/README.md +4 -4
- package/USAGE_EXAMPLE.md +86 -0
- package/package.json +10 -9
- package/{dist/client.js → src/client.ts} +59 -39
- package/src/index.ts +54 -0
- package/src/lib/analytics/AnalyticsClient.ts +24 -0
- package/src/lib/analytics/types.ts +8 -0
- package/src/lib/app/AppClient.ts +54 -0
- package/src/lib/app/types.ts +50 -0
- package/{dist/lib/auth/AuthClient.js → src/lib/auth/AuthClient.ts} +106 -70
- package/src/lib/auth/types.ts +111 -0
- package/src/lib/database/DatabaseClient.ts +148 -0
- package/src/lib/database/types.ts +46 -0
- package/src/lib/functions/FunctionsClient.ts +27 -0
- package/src/lib/functions/types.ts +25 -0
- package/src/lib/graphs/GraphClient.ts +106 -0
- package/src/lib/graphs/types.ts +33 -0
- package/src/lib/policy/PolicyClient.ts +79 -0
- package/src/lib/policy/types.ts +40 -0
- package/src/lib/secrets/SecretsClient.ts +75 -0
- package/src/lib/secrets/types.ts +59 -0
- package/src/lib/settings/SettingsClient.ts +14 -0
- package/src/lib/settings/types.ts +9 -0
- package/src/lib/storage/StorageClient.ts +123 -0
- package/src/lib/storage/types.ts +86 -0
- package/src/lib/users/UserClient.ts +55 -0
- package/src/lib/users/types.ts +104 -0
- package/src/lib-internal/errors/ErrorClient.ts +102 -0
- package/src/lib-internal/errors/index.ts +3 -0
- package/src/lib-internal/errors/types.ts +28 -0
- package/src/lib-internal/http/HttpClient.ts +129 -0
- package/{dist/lib-internal/http/types.js → src/lib-internal/http/types.ts} +3 -2
- package/src/lib-internal/routes/AnalyticsRoutes.ts +3 -0
- package/src/lib-internal/routes/AppRoutes.ts +9 -0
- package/src/lib-internal/routes/AuthRoutes.ts +0 -0
- package/src/lib-internal/routes/DatabaseRoutes.ts +9 -0
- package/src/lib-internal/routes/FunctionRoutes.ts +3 -0
- package/src/lib-internal/routes/GraphRoutes.ts +14 -0
- package/src/lib-internal/routes/PolicyRoutes.ts +4 -0
- package/src/lib-internal/routes/SecretsRoutes.ts +5 -0
- package/{dist/lib-internal/routes/SettingsRoutes.js → src/lib-internal/routes/SettingsRoutes.ts} +1 -2
- package/src/lib-internal/routes/StorageRoutes.ts +15 -0
- package/src/lib-internal/routes/UserRoutes.ts +11 -0
- package/src/lib-internal/routes/index.ts +0 -0
- package/{dist/lib-internal/token/TokenClient.js → src/lib-internal/token/TokenClient.ts} +144 -99
- package/src/lib-internal/token/types.ts +0 -0
- package/src/types.ts +90 -0
- package/{dist/utils/enums.js → src/utils/enums.ts} +10 -4
- package/src/utils/utils.ts +37 -0
- package/tests/fixtures/mockClient.ts +19 -0
- package/tests/mocks/db.json +1 -0
- package/tests/unit/analytics/AnalyticsClient.test.ts +84 -0
- package/tests/unit/app/AppClient.test.ts +114 -0
- package/tests/unit/auth/AuthClient.test.ts +131 -0
- package/tests/unit/client/Client.test.ts +70 -0
- package/tests/unit/database/DatabaseClient.test.ts +304 -0
- package/tests/unit/edge-cases/robustness.test.ts +259 -0
- package/tests/unit/errors/errors.test.ts +209 -0
- package/tests/unit/functions/FunctionsClient.test.ts +99 -0
- package/tests/unit/graphs/GraphClient.test.ts +329 -0
- package/tests/unit/policy/PolicyClient.test.ts +184 -0
- package/tests/unit/secrets/SecretsClient.test.ts +146 -0
- package/tests/unit/settings/SettingsClient.test.ts +50 -0
- package/tests/unit/storage/StorageClient.test.ts +251 -0
- package/tests/unit/users/UserClient.test.ts +150 -0
- package/tsconfig.json +43 -0
- package/vitest.config.ts +7 -0
- package/dist/client.d.ts +0 -29
- package/dist/client.d.ts.map +0 -1
- package/dist/client.js.map +0 -1
- package/dist/index.d.ts +0 -25
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -15
- package/dist/index.js.map +0 -1
- package/dist/lib/Analytics/AnalyticsClient.d.ts +0 -9
- package/dist/lib/Analytics/AnalyticsClient.d.ts.map +0 -1
- package/dist/lib/Analytics/AnalyticsClient.js +0 -17
- package/dist/lib/Analytics/AnalyticsClient.js.map +0 -1
- package/dist/lib/Analytics/types.d.ts +0 -7
- package/dist/lib/Analytics/types.d.ts.map +0 -1
- package/dist/lib/Analytics/types.js +0 -2
- package/dist/lib/Analytics/types.js.map +0 -1
- package/dist/lib/App/AppClient.d.ts +0 -15
- package/dist/lib/App/AppClient.d.ts.map +0 -1
- package/dist/lib/App/AppClient.js +0 -41
- package/dist/lib/App/AppClient.js.map +0 -1
- package/dist/lib/App/types.d.ts +0 -36
- package/dist/lib/App/types.d.ts.map +0 -1
- package/dist/lib/App/types.js +0 -2
- package/dist/lib/App/types.js.map +0 -1
- package/dist/lib/Database/DatabaseClient.d.ts +0 -28
- package/dist/lib/Database/DatabaseClient.d.ts.map +0 -1
- package/dist/lib/Database/DatabaseClient.js +0 -116
- package/dist/lib/Database/DatabaseClient.js.map +0 -1
- package/dist/lib/Database/types.d.ts +0 -24
- package/dist/lib/Database/types.d.ts.map +0 -1
- package/dist/lib/Database/types.js +0 -2
- package/dist/lib/Database/types.js.map +0 -1
- package/dist/lib/Function/FunctionsClient.d.ts +0 -9
- package/dist/lib/Function/FunctionsClient.d.ts.map +0 -1
- package/dist/lib/Function/FunctionsClient.js +0 -20
- package/dist/lib/Function/FunctionsClient.js.map +0 -1
- package/dist/lib/Function/types.d.ts +0 -16
- package/dist/lib/Function/types.d.ts.map +0 -1
- package/dist/lib/Function/types.js +0 -2
- package/dist/lib/Function/types.js.map +0 -1
- package/dist/lib/Graphs/GraphClient.d.ts +0 -26
- package/dist/lib/Graphs/GraphClient.d.ts.map +0 -1
- package/dist/lib/Graphs/GraphClient.js +0 -86
- package/dist/lib/Graphs/GraphClient.js.map +0 -1
- package/dist/lib/Graphs/types.d.ts +0 -23
- package/dist/lib/Graphs/types.d.ts.map +0 -1
- package/dist/lib/Graphs/types.js +0 -2
- package/dist/lib/Graphs/types.js.map +0 -1
- package/dist/lib/Policy/PolicyClient.d.ts +0 -9
- package/dist/lib/Policy/PolicyClient.d.ts.map +0 -1
- package/dist/lib/Policy/PolicyClient.js +0 -24
- package/dist/lib/Policy/PolicyClient.js.map +0 -1
- package/dist/lib/Policy/types.d.ts +0 -22
- package/dist/lib/Policy/types.d.ts.map +0 -1
- package/dist/lib/Policy/types.js +0 -2
- package/dist/lib/Policy/types.js.map +0 -1
- package/dist/lib/Secrets/SecretsClient.d.ts +0 -14
- package/dist/lib/Secrets/SecretsClient.d.ts.map +0 -1
- package/dist/lib/Secrets/SecretsClient.js +0 -32
- package/dist/lib/Secrets/SecretsClient.js.map +0 -1
- package/dist/lib/Secrets/types.d.ts +0 -13
- package/dist/lib/Secrets/types.d.ts.map +0 -1
- package/dist/lib/Secrets/types.js +0 -2
- package/dist/lib/Secrets/types.js.map +0 -1
- package/dist/lib/Settings/SettingsClient.d.ts +0 -7
- package/dist/lib/Settings/SettingsClient.d.ts.map +0 -1
- package/dist/lib/Settings/SettingsClient.js +0 -11
- package/dist/lib/Settings/SettingsClient.js.map +0 -1
- package/dist/lib/Settings/types.d.ts +0 -4
- package/dist/lib/Settings/types.d.ts.map +0 -1
- package/dist/lib/Settings/types.js +0 -2
- package/dist/lib/Settings/types.js.map +0 -1
- package/dist/lib/Storage/StorageClient.d.ts +0 -26
- package/dist/lib/Storage/StorageClient.d.ts.map +0 -1
- package/dist/lib/Storage/StorageClient.js +0 -78
- package/dist/lib/Storage/StorageClient.js.map +0 -1
- package/dist/lib/Storage/types.d.ts +0 -35
- package/dist/lib/Storage/types.d.ts.map +0 -1
- package/dist/lib/Storage/types.js +0 -2
- package/dist/lib/Storage/types.js.map +0 -1
- package/dist/lib/auth/AuthClient.d.ts +0 -66
- package/dist/lib/auth/AuthClient.d.ts.map +0 -1
- package/dist/lib/auth/AuthClient.js.map +0 -1
- package/dist/lib/auth/types.d.ts +0 -9
- package/dist/lib/auth/types.d.ts.map +0 -1
- package/dist/lib/auth/types.js +0 -2
- package/dist/lib/auth/types.js.map +0 -1
- package/dist/lib/user/UserClient.d.ts +0 -16
- package/dist/lib/user/UserClient.d.ts.map +0 -1
- package/dist/lib/user/UserClient.js +0 -41
- package/dist/lib/user/UserClient.js.map +0 -1
- package/dist/lib/user/types.d.ts +0 -100
- package/dist/lib/user/types.d.ts.map +0 -1
- package/dist/lib/user/types.js +0 -2
- package/dist/lib/user/types.js.map +0 -1
- package/dist/lib-internal/errors/ErrorClient.d.ts +0 -4
- package/dist/lib-internal/errors/ErrorClient.d.ts.map +0 -1
- package/dist/lib-internal/errors/ErrorClient.js +0 -6
- package/dist/lib-internal/errors/ErrorClient.js.map +0 -1
- package/dist/lib-internal/errors/index.d.ts +0 -8
- package/dist/lib-internal/errors/index.d.ts.map +0 -1
- package/dist/lib-internal/errors/index.js +0 -23
- package/dist/lib-internal/errors/index.js.map +0 -1
- package/dist/lib-internal/errors/types.d.ts +0 -83
- package/dist/lib-internal/errors/types.d.ts.map +0 -1
- package/dist/lib-internal/errors/types.js +0 -65
- package/dist/lib-internal/errors/types.js.map +0 -1
- package/dist/lib-internal/http/HttpClient.d.ts +0 -22
- package/dist/lib-internal/http/HttpClient.d.ts.map +0 -1
- package/dist/lib-internal/http/HttpClient.js +0 -65
- package/dist/lib-internal/http/HttpClient.js.map +0 -1
- package/dist/lib-internal/http/types.d.ts +0 -12
- package/dist/lib-internal/http/types.d.ts.map +0 -1
- package/dist/lib-internal/http/types.js.map +0 -1
- package/dist/lib-internal/routes/AnalyticsRoutes.d.ts +0 -4
- package/dist/lib-internal/routes/AnalyticsRoutes.d.ts.map +0 -1
- package/dist/lib-internal/routes/AnalyticsRoutes.js +0 -4
- package/dist/lib-internal/routes/AnalyticsRoutes.js.map +0 -1
- package/dist/lib-internal/routes/AppRoutes.d.ts +0 -10
- package/dist/lib-internal/routes/AppRoutes.d.ts.map +0 -1
- package/dist/lib-internal/routes/AppRoutes.js +0 -6
- package/dist/lib-internal/routes/AppRoutes.js.map +0 -1
- package/dist/lib-internal/routes/AuthRoutes.d.ts +0 -2
- package/dist/lib-internal/routes/AuthRoutes.d.ts.map +0 -1
- package/dist/lib-internal/routes/AuthRoutes.js +0 -2
- package/dist/lib-internal/routes/AuthRoutes.js.map +0 -1
- package/dist/lib-internal/routes/DatabaseRoutes.d.ts +0 -10
- package/dist/lib-internal/routes/DatabaseRoutes.d.ts.map +0 -1
- package/dist/lib-internal/routes/DatabaseRoutes.js +0 -6
- package/dist/lib-internal/routes/DatabaseRoutes.js.map +0 -1
- package/dist/lib-internal/routes/FunctionRoutes.d.ts +0 -4
- package/dist/lib-internal/routes/FunctionRoutes.d.ts.map +0 -1
- package/dist/lib-internal/routes/FunctionRoutes.js +0 -4
- package/dist/lib-internal/routes/FunctionRoutes.js.map +0 -1
- package/dist/lib-internal/routes/GraphRoutes.d.ts +0 -14
- package/dist/lib-internal/routes/GraphRoutes.d.ts.map +0 -1
- package/dist/lib-internal/routes/GraphRoutes.js +0 -11
- package/dist/lib-internal/routes/GraphRoutes.js.map +0 -1
- package/dist/lib-internal/routes/PolicyRoutes.d.ts +0 -5
- package/dist/lib-internal/routes/PolicyRoutes.d.ts.map +0 -1
- package/dist/lib-internal/routes/PolicyRoutes.js +0 -5
- package/dist/lib-internal/routes/PolicyRoutes.js.map +0 -1
- package/dist/lib-internal/routes/SecretsRoutes.d.ts +0 -6
- package/dist/lib-internal/routes/SecretsRoutes.d.ts.map +0 -1
- package/dist/lib-internal/routes/SecretsRoutes.js +0 -6
- package/dist/lib-internal/routes/SecretsRoutes.js.map +0 -1
- package/dist/lib-internal/routes/SettingsRoutes.d.ts +0 -4
- package/dist/lib-internal/routes/SettingsRoutes.d.ts.map +0 -1
- package/dist/lib-internal/routes/SettingsRoutes.js.map +0 -1
- package/dist/lib-internal/routes/StorageRoutes.d.ts +0 -11
- package/dist/lib-internal/routes/StorageRoutes.d.ts.map +0 -1
- package/dist/lib-internal/routes/StorageRoutes.js +0 -8
- package/dist/lib-internal/routes/StorageRoutes.js.map +0 -1
- package/dist/lib-internal/routes/UserRoutes.d.ts +0 -11
- package/dist/lib-internal/routes/UserRoutes.d.ts.map +0 -1
- package/dist/lib-internal/routes/UserRoutes.js +0 -11
- package/dist/lib-internal/routes/UserRoutes.js.map +0 -1
- package/dist/lib-internal/routes/index.d.ts +0 -2
- package/dist/lib-internal/routes/index.d.ts.map +0 -1
- package/dist/lib-internal/routes/index.js +0 -2
- package/dist/lib-internal/routes/index.js.map +0 -1
- package/dist/lib-internal/token/TokenClient.d.ts +0 -71
- package/dist/lib-internal/token/TokenClient.d.ts.map +0 -1
- package/dist/lib-internal/token/TokenClient.js.map +0 -1
- package/dist/lib-internal/token/types.d.ts +0 -2
- package/dist/lib-internal/token/types.d.ts.map +0 -1
- package/dist/lib-internal/token/types.js +0 -2
- package/dist/lib-internal/token/types.js.map +0 -1
- package/dist/types.d.ts +0 -49
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -2
- package/dist/types.js.map +0 -1
- package/dist/utils/enums.d.ts +0 -20
- package/dist/utils/enums.d.ts.map +0 -1
- package/dist/utils/enums.js.map +0 -1
- package/dist/utils/utils.d.ts +0 -5
- package/dist/utils/utils.d.ts.map +0 -1
- package/dist/utils/utils.js +0 -32
- package/dist/utils/utils.js.map +0 -1
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { TaruviResponse } from "../../types.js"
|
|
2
|
+
|
|
3
|
+
// Internal types
|
|
4
|
+
export interface SecretsUrlParams {
|
|
5
|
+
path?: string
|
|
6
|
+
queryParams?: Record<string, unknown>
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
// Request types - matches SiteSecretIn from backend
|
|
10
|
+
export interface SecretCreateRequest {
|
|
11
|
+
key: string
|
|
12
|
+
value: string | Record<string, unknown>
|
|
13
|
+
secret_type: string
|
|
14
|
+
tags?: string[]
|
|
15
|
+
app?: string
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface SecretUpdateRequest {
|
|
19
|
+
value?: string | Record<string, unknown>
|
|
20
|
+
secret_type?: string
|
|
21
|
+
tags?: string[]
|
|
22
|
+
app?: string
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Options for getting a single secret
|
|
26
|
+
export interface GetSecretOptions {
|
|
27
|
+
app?: string
|
|
28
|
+
tags?: string[]
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Options for batch getting secrets
|
|
32
|
+
export interface GetSecretsOptions {
|
|
33
|
+
app?: string
|
|
34
|
+
includeMetadata?: boolean
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Secret data
|
|
38
|
+
export interface SecretData {
|
|
39
|
+
key: string
|
|
40
|
+
value: string | Record<string, unknown>
|
|
41
|
+
tags?: string[]
|
|
42
|
+
secret_type?: string
|
|
43
|
+
created_at?: string
|
|
44
|
+
updated_at?: string
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Response types - uses standard wrapper
|
|
48
|
+
export type SecretResponse = TaruviResponse<SecretData>
|
|
49
|
+
export type SecretsListResponse = TaruviResponse<SecretData[]>
|
|
50
|
+
|
|
51
|
+
// Batch get response - values only
|
|
52
|
+
export type SecretsBatchResponse = TaruviResponse<Record<string, string>>
|
|
53
|
+
|
|
54
|
+
// Batch get response - with metadata
|
|
55
|
+
export type SecretsBatchMetadataResponse = TaruviResponse<Record<string, {
|
|
56
|
+
value: string
|
|
57
|
+
tags: string[]
|
|
58
|
+
secret_type: string
|
|
59
|
+
}>>
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Client } from "../../client.js";
|
|
2
|
+
import { SettingsRoutes } from "../../lib-internal/routes/SettingsRoutes.js";
|
|
3
|
+
|
|
4
|
+
export class Settings {
|
|
5
|
+
private client: Client
|
|
6
|
+
|
|
7
|
+
constructor(client: Client) {
|
|
8
|
+
this.client = client
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
async get<T = unknown>(): Promise<T> {
|
|
12
|
+
return await this.client.httpClient.get<T>(SettingsRoutes.metadata)
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import type { Client } from "../../client.js";
|
|
2
|
+
import type {
|
|
3
|
+
BucketUrlParams,
|
|
4
|
+
StorageResponse,
|
|
5
|
+
StorageListResponse,
|
|
6
|
+
StorageUploadBatchResponse,
|
|
7
|
+
StorageDeleteBatchResponse
|
|
8
|
+
} from "./types.js";
|
|
9
|
+
import { StorageRoutes, type StorageRouteKey } from "../../lib-internal/routes/StorageRoutes.js";
|
|
10
|
+
import type { TaruviConfig, StorageFilters } from "../../types.js";
|
|
11
|
+
import { HttpMethod } from "../../lib-internal/http/types.js";
|
|
12
|
+
import { buildQueryString } from "../../utils/utils.js";
|
|
13
|
+
|
|
14
|
+
export class Storage {
|
|
15
|
+
|
|
16
|
+
private client: Client
|
|
17
|
+
private config: TaruviConfig
|
|
18
|
+
private urlParams: BucketUrlParams
|
|
19
|
+
private operation: HttpMethod | undefined
|
|
20
|
+
private body: object | undefined
|
|
21
|
+
private filters: StorageFilters | undefined
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
constructor(client: Client, urlParams: BucketUrlParams = {} as BucketUrlParams, operation?: HttpMethod | undefined, body?: object, filters?: StorageFilters) {
|
|
25
|
+
this.client = client
|
|
26
|
+
this.urlParams = urlParams
|
|
27
|
+
this.operation = operation
|
|
28
|
+
this.config = this.client.getConfig()
|
|
29
|
+
this.body = body
|
|
30
|
+
this.filters = filters
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
from(bucket: string): Storage {
|
|
35
|
+
return new Storage(this.client, { ...this.urlParams, bucket }, undefined, undefined)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
filter(filters: StorageFilters) {
|
|
39
|
+
return new Storage(this.client, { ...this.urlParams }, undefined, undefined, filters)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
delete(paths: string[]): Storage {
|
|
43
|
+
return new Storage(this.client, {
|
|
44
|
+
...this.urlParams, delete: "delete"
|
|
45
|
+
}, HttpMethod.POST, { paths })
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
update(path: string, body: object): Storage {
|
|
49
|
+
return new Storage(this.client, { ...this.urlParams, path }, HttpMethod.PUT, body)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
download(path: string): Storage {
|
|
53
|
+
return new Storage(this.client, { ...this.urlParams, path }, HttpMethod.GET)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
upload(filesData: { files: File[], metadatas: object[], paths: string[] }): Storage {
|
|
57
|
+
const formData = new FormData()
|
|
58
|
+
filesData.files.forEach(f => formData.append('files', f))
|
|
59
|
+
formData.append('paths', JSON.stringify(filesData.paths))
|
|
60
|
+
formData.append('metadata', JSON.stringify(filesData.metadatas))
|
|
61
|
+
return new Storage(this.client, {
|
|
62
|
+
...this.urlParams, upload: "upload"
|
|
63
|
+
}, HttpMethod.POST, formData)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
private buildRoute(): string {
|
|
67
|
+
if (!this.urlParams.bucket) {
|
|
68
|
+
throw new Error('Bucket is required. Call .from(bucketName) first.')
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return (
|
|
72
|
+
StorageRoutes.baseUrl(this.config.appSlug, this.urlParams.bucket) +
|
|
73
|
+
(Object.keys(this.urlParams) as StorageRouteKey[]).reduce((acc, key) => {
|
|
74
|
+
const value = this.urlParams[key as keyof BucketUrlParams]
|
|
75
|
+
|
|
76
|
+
if (!value) return acc
|
|
77
|
+
|
|
78
|
+
if (key === 'path' && typeof value === 'string') {
|
|
79
|
+
acc += StorageRoutes.path(value)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if ((key === 'upload' || key === 'delete') && typeof StorageRoutes[key] === 'function') {
|
|
83
|
+
acc += (StorageRoutes[key] as () => string)()
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return acc
|
|
87
|
+
}, '') +
|
|
88
|
+
'/' +
|
|
89
|
+
buildQueryString(this.filters as Record<string, unknown>)
|
|
90
|
+
)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Execute the storage operation.
|
|
97
|
+
* Returns different types based on the operation:
|
|
98
|
+
* - List files: StorageListResponse[]
|
|
99
|
+
* - Download: Blob
|
|
100
|
+
* - Upload: StorageUploadBatchResponse
|
|
101
|
+
* - Delete: StorageDeleteBatchResponse
|
|
102
|
+
* - Update: StorageResponse
|
|
103
|
+
*/
|
|
104
|
+
async execute<T = StorageListResponse[] | StorageResponse | StorageUploadBatchResponse | StorageDeleteBatchResponse | Blob>(): Promise<T> {
|
|
105
|
+
const url = this.buildRoute()
|
|
106
|
+
const operation = this.operation || HttpMethod.GET
|
|
107
|
+
|
|
108
|
+
switch (operation) {
|
|
109
|
+
case HttpMethod.POST:
|
|
110
|
+
return await this.client.httpClient.post<T>(url, this.body)
|
|
111
|
+
|
|
112
|
+
case HttpMethod.PUT:
|
|
113
|
+
return await this.client.httpClient.put<T>(url, this.body)
|
|
114
|
+
|
|
115
|
+
case HttpMethod.DELETE:
|
|
116
|
+
return await this.client.httpClient.delete<T>(url)
|
|
117
|
+
|
|
118
|
+
case HttpMethod.GET:
|
|
119
|
+
default:
|
|
120
|
+
return await this.client.httpClient.get<T>(url)
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type { TaruviResponse } from "../../types.js"
|
|
2
|
+
|
|
3
|
+
// Internal types - all optional since they're built incrementally via builder pattern
|
|
4
|
+
export interface BucketUrlParams {
|
|
5
|
+
appSlug?: string
|
|
6
|
+
bucket?: string
|
|
7
|
+
path?: string
|
|
8
|
+
upload?: string
|
|
9
|
+
delete?: string
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface BucketFileUpload {
|
|
13
|
+
files: []
|
|
14
|
+
path: string
|
|
15
|
+
metadata?: Record<string, unknown>
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Request types
|
|
19
|
+
export interface StorageRequest {
|
|
20
|
+
files: File[]
|
|
21
|
+
paths: string[]
|
|
22
|
+
metadatas: object[]
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface StorageUpdateRequest {
|
|
26
|
+
metadata?: Record<string, unknown>
|
|
27
|
+
visibility?: 'public' | 'private'
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Storage object - matches StorageObjectSerializer from API
|
|
31
|
+
export interface StorageObject {
|
|
32
|
+
id: number
|
|
33
|
+
uuid: string
|
|
34
|
+
bucket?: number
|
|
35
|
+
bucket_slug?: string
|
|
36
|
+
bucket_name?: string
|
|
37
|
+
filename: string
|
|
38
|
+
file_path: string
|
|
39
|
+
file_url: string
|
|
40
|
+
size: number
|
|
41
|
+
mimetype: string
|
|
42
|
+
metadata?: Record<string, unknown>
|
|
43
|
+
visibility?: string
|
|
44
|
+
created_at: string
|
|
45
|
+
updated_at: string
|
|
46
|
+
created_by?: number
|
|
47
|
+
modified_by?: number
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Response types - uses standard wrapper
|
|
51
|
+
export type StorageResponse = TaruviResponse<StorageObject>
|
|
52
|
+
export type StorageListResponse = TaruviResponse<StorageObject[]>
|
|
53
|
+
|
|
54
|
+
// Batch upload response
|
|
55
|
+
export interface StorageUploadBatchResponse {
|
|
56
|
+
status: "success" | "error"
|
|
57
|
+
message: string
|
|
58
|
+
data: {
|
|
59
|
+
uploaded_count: number
|
|
60
|
+
failed_count: number
|
|
61
|
+
total: number
|
|
62
|
+
successful: Array<{
|
|
63
|
+
index: number
|
|
64
|
+
path: string
|
|
65
|
+
object: StorageObject
|
|
66
|
+
}>
|
|
67
|
+
failed: Array<{
|
|
68
|
+
index: number
|
|
69
|
+
path: string
|
|
70
|
+
error: string
|
|
71
|
+
}>
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Batch delete response
|
|
76
|
+
export interface StorageDeleteBatchResponse {
|
|
77
|
+
status: "success" | "error"
|
|
78
|
+
message: string
|
|
79
|
+
data: {
|
|
80
|
+
deleted_count: number
|
|
81
|
+
failed: Array<{
|
|
82
|
+
path: string
|
|
83
|
+
error: string
|
|
84
|
+
}>
|
|
85
|
+
}
|
|
86
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { Client } from "../../client.js";
|
|
2
|
+
import type { UserCreateRequest, UserResponse, UserListResponse, UserListFilters, UserUpdateRequest, UserAppsResponse, AssignRolesRequest, RevokeRolesRequest, RolesResponse } from "./types.js";
|
|
3
|
+
import { UserRoutes } from "../../lib-internal/routes/UserRoutes.js";
|
|
4
|
+
import { buildQueryString } from "../../utils/utils.js";
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
export class User {
|
|
8
|
+
private client: Client
|
|
9
|
+
|
|
10
|
+
constructor(client: Client) {
|
|
11
|
+
this.client = client
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
async updateUser(username: string, body: UserUpdateRequest): Promise<UserResponse> {
|
|
15
|
+
return await this.client.httpClient.put(UserRoutes.updateUser(username), body)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async getUser(username: string): Promise<UserResponse> {
|
|
19
|
+
return await this.client.httpClient.get<UserResponse>(UserRoutes.getUser(username))
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async list(filters?: UserListFilters): Promise<UserListResponse> {
|
|
23
|
+
const queryString = buildQueryString(filters as unknown as Record<string, unknown>)
|
|
24
|
+
return await this.client.httpClient.get<UserListResponse>(UserRoutes.listUser(queryString))
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async getUserApps(username: string): Promise<UserAppsResponse> {
|
|
28
|
+
return await this.client.httpClient.get<UserAppsResponse>(UserRoutes.getUserApps(username))
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
async createUser(userData: UserCreateRequest): Promise<UserResponse> {
|
|
32
|
+
return await this.client.httpClient.post<UserResponse, UserCreateRequest>(
|
|
33
|
+
UserRoutes.baseUrl,
|
|
34
|
+
userData
|
|
35
|
+
)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async deleteUser(username: string): Promise<void> {
|
|
39
|
+
return await this.client.httpClient.delete(UserRoutes.deleteUser(username))
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async assignRoles(request: AssignRolesRequest): Promise<RolesResponse> {
|
|
43
|
+
return await this.client.httpClient.post<RolesResponse, AssignRolesRequest>(
|
|
44
|
+
UserRoutes.assignRoles(),
|
|
45
|
+
request
|
|
46
|
+
)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async revokeRoles(request: RevokeRolesRequest): Promise<RolesResponse> {
|
|
50
|
+
return await this.client.httpClient.delete<RolesResponse>(
|
|
51
|
+
UserRoutes.revokeRoles(),
|
|
52
|
+
request
|
|
53
|
+
)
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import type { TaruviResponse } from "../../types.js"
|
|
2
|
+
|
|
3
|
+
export interface UserCreateRequest {
|
|
4
|
+
username: string
|
|
5
|
+
email: string
|
|
6
|
+
password: string
|
|
7
|
+
confirm_password: string
|
|
8
|
+
first_name: string
|
|
9
|
+
last_name: string
|
|
10
|
+
is_active?: boolean
|
|
11
|
+
is_staff?: boolean
|
|
12
|
+
is_cloud_user?: boolean
|
|
13
|
+
attributes?: Record<string, unknown>
|
|
14
|
+
role_slugs?: string[]
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface UserData {
|
|
18
|
+
id: number
|
|
19
|
+
uuid?: string
|
|
20
|
+
username: string
|
|
21
|
+
email: string
|
|
22
|
+
first_name: string
|
|
23
|
+
last_name: string
|
|
24
|
+
full_name?: string
|
|
25
|
+
is_active: boolean
|
|
26
|
+
is_staff: boolean
|
|
27
|
+
is_superuser?: boolean
|
|
28
|
+
is_deleted: boolean
|
|
29
|
+
date_joined: string
|
|
30
|
+
last_login?: string
|
|
31
|
+
groups?: UserGroup[]
|
|
32
|
+
user_permissions?: UserPermission[]
|
|
33
|
+
attributes?: Record<string, unknown>
|
|
34
|
+
missing_attributes?: string[]
|
|
35
|
+
roles?: UserRole[]
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface UserGroup {
|
|
39
|
+
id: number
|
|
40
|
+
name: string
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface UserPermission {
|
|
44
|
+
id: number
|
|
45
|
+
name: string
|
|
46
|
+
codename: string
|
|
47
|
+
content_type: string
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface UserRole {
|
|
51
|
+
name: string
|
|
52
|
+
slug: string
|
|
53
|
+
type: string
|
|
54
|
+
app_slug: string
|
|
55
|
+
source: "direct" | "site_role" | "inherited"
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export interface UserUpdateRequest {
|
|
59
|
+
username?: string
|
|
60
|
+
email?: string
|
|
61
|
+
first_name?: string
|
|
62
|
+
last_name?: string
|
|
63
|
+
is_active?: boolean
|
|
64
|
+
is_staff?: boolean
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export interface UserListFilters {
|
|
68
|
+
search?: string
|
|
69
|
+
is_active?: boolean
|
|
70
|
+
is_staff?: boolean
|
|
71
|
+
is_superuser?: boolean
|
|
72
|
+
is_deleted?: boolean
|
|
73
|
+
ordering?: string
|
|
74
|
+
page?: number
|
|
75
|
+
page_size?: number
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export interface UserApp {
|
|
79
|
+
name: string
|
|
80
|
+
slug: string
|
|
81
|
+
icon: string
|
|
82
|
+
url: string
|
|
83
|
+
display_name: string
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Response types - uses standard wrapper
|
|
87
|
+
export type UserResponse = TaruviResponse<UserData>
|
|
88
|
+
export type UserListResponse = TaruviResponse<UserData[]>
|
|
89
|
+
export type UserAppsResponse = TaruviResponse<UserApp[]>
|
|
90
|
+
|
|
91
|
+
export interface AssignRolesRequest {
|
|
92
|
+
roles: string[]
|
|
93
|
+
usernames: string[]
|
|
94
|
+
expires_at?: string
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export interface RevokeRolesRequest {
|
|
98
|
+
roles: string[]
|
|
99
|
+
usernames: string[]
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export type RolesResponse = TaruviResponse<{
|
|
103
|
+
count: number
|
|
104
|
+
}>
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { ErrorCode, type ErrorResponseBody } from './types.js'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Base SDK error. All typed errors extend this.
|
|
5
|
+
*/
|
|
6
|
+
export class TaruviError extends Error {
|
|
7
|
+
public readonly code: string
|
|
8
|
+
public readonly statusCode: number
|
|
9
|
+
public readonly detail: string | undefined
|
|
10
|
+
public readonly errors: Record<string, unknown> | undefined
|
|
11
|
+
public readonly data: unknown
|
|
12
|
+
|
|
13
|
+
constructor(message: string, statusCode: number, code: string = ErrorCode.INTERNAL_ERROR, detail?: string, errors?: Record<string, unknown>, data?: unknown) {
|
|
14
|
+
super(message)
|
|
15
|
+
this.name = 'TaruviError'
|
|
16
|
+
this.statusCode = statusCode
|
|
17
|
+
this.code = code
|
|
18
|
+
this.detail = detail
|
|
19
|
+
this.errors = errors
|
|
20
|
+
this.data = data
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export class ValidationError extends TaruviError {
|
|
25
|
+
constructor(message = 'Validation failed', detail?: string, errors?: Record<string, unknown>) {
|
|
26
|
+
super(message, 400, ErrorCode.VALIDATION_ERROR, detail, errors)
|
|
27
|
+
this.name = 'ValidationError'
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export class AuthError extends TaruviError {
|
|
32
|
+
constructor(message = 'Authentication required') {
|
|
33
|
+
super(message, 401, ErrorCode.UNAUTHORIZED)
|
|
34
|
+
this.name = 'AuthError'
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export class ForbiddenError extends TaruviError {
|
|
39
|
+
constructor(message = 'Permission denied') {
|
|
40
|
+
super(message, 403, ErrorCode.FORBIDDEN)
|
|
41
|
+
this.name = 'ForbiddenError'
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export class NotFoundError extends TaruviError {
|
|
46
|
+
constructor(message = 'Resource not found') {
|
|
47
|
+
super(message, 404, ErrorCode.NOT_FOUND)
|
|
48
|
+
this.name = 'NotFoundError'
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export class ConflictError extends TaruviError {
|
|
53
|
+
constructor(message = 'Resource conflict', detail?: string) {
|
|
54
|
+
super(message, 409, ErrorCode.CONFLICT, detail)
|
|
55
|
+
this.name = 'ConflictError'
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export class TimeoutError extends TaruviError {
|
|
60
|
+
constructor(message = 'Request timeout') {
|
|
61
|
+
super(message, 504, ErrorCode.GATEWAY_TIMEOUT)
|
|
62
|
+
this.name = 'TimeoutError'
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export class NetworkError extends TaruviError {
|
|
67
|
+
constructor(message = 'Network error') {
|
|
68
|
+
super(message, 0, ErrorCode.NETWORK_ERROR)
|
|
69
|
+
this.name = 'NetworkError'
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Maps HTTP status + response body to the appropriate typed error.
|
|
75
|
+
*/
|
|
76
|
+
export function createErrorFromResponse(statusCode: number, body?: ErrorResponseBody): TaruviError {
|
|
77
|
+
const message = body?.message || 'Request failed'
|
|
78
|
+
const code = body?.code || ErrorCode.INTERNAL_ERROR
|
|
79
|
+
const detail = body?.detail
|
|
80
|
+
const errors = body?.errors
|
|
81
|
+
const data = body?.data
|
|
82
|
+
|
|
83
|
+
switch (statusCode) {
|
|
84
|
+
case 400:
|
|
85
|
+
if (code === ErrorCode.VALIDATION_ERROR) {
|
|
86
|
+
return new ValidationError(message, detail, errors)
|
|
87
|
+
}
|
|
88
|
+
return new TaruviError(message, 400, code, detail, errors, data)
|
|
89
|
+
case 401:
|
|
90
|
+
return new AuthError(message)
|
|
91
|
+
case 403:
|
|
92
|
+
return new ForbiddenError(message)
|
|
93
|
+
case 404:
|
|
94
|
+
return new NotFoundError(message)
|
|
95
|
+
case 409:
|
|
96
|
+
return new ConflictError(message, detail)
|
|
97
|
+
case 504:
|
|
98
|
+
return new TimeoutError(message)
|
|
99
|
+
default:
|
|
100
|
+
return new TaruviError(message, statusCode, code, detail, errors, data)
|
|
101
|
+
}
|
|
102
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error codes matching the backend's ErrorCode enum.
|
|
3
|
+
* Maps 1:1 with base.responses.error_codes.ErrorCode in Python.
|
|
4
|
+
*/
|
|
5
|
+
export enum ErrorCode {
|
|
6
|
+
BAD_REQUEST = 'BAD_REQUEST',
|
|
7
|
+
VALIDATION_ERROR = 'VALIDATION_ERROR',
|
|
8
|
+
UNAUTHORIZED = 'UNAUTHORIZED',
|
|
9
|
+
FORBIDDEN = 'FORBIDDEN',
|
|
10
|
+
NOT_FOUND = 'NOT_FOUND',
|
|
11
|
+
CONFLICT = 'CONFLICT',
|
|
12
|
+
INTERNAL_ERROR = 'INTERNAL_ERROR',
|
|
13
|
+
GATEWAY_TIMEOUT = 'GATEWAY_TIMEOUT',
|
|
14
|
+
NETWORK_ERROR = 'NETWORK_ERROR'
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Backend error response shape.
|
|
19
|
+
* Matches AppException.to_dict() output.
|
|
20
|
+
*/
|
|
21
|
+
export interface ErrorResponseBody {
|
|
22
|
+
status: 'error'
|
|
23
|
+
code: string
|
|
24
|
+
message: string
|
|
25
|
+
detail?: string
|
|
26
|
+
errors?: Record<string, unknown>
|
|
27
|
+
data?: unknown
|
|
28
|
+
}
|