@taruvi/sdk 1.0.9 → 1.1.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/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -9,11 +9,13 @@ export { Database } from "./lib/Database/DatabaseClient.js"
|
|
|
9
9
|
export { Settings } from "./lib/Settings/SettingsClient.js"
|
|
10
10
|
export { Functions } from "./lib/Function/FunctionsClient.js"
|
|
11
11
|
export { Secrets } from "./lib/Secrets/SecretsClient.js"
|
|
12
|
+
export { Policy } from "./lib/Policy/PolicyClient.js"
|
|
12
13
|
|
|
13
14
|
// Export types
|
|
14
15
|
export type { TaruviConfig, StorageFilters, DatabaseFilters } from "./types.js"
|
|
15
16
|
export type { AuthTokens } from "./lib-internal/token/TokenClient.js"
|
|
16
17
|
export type { UserCreateRequest, UserCreateResponse as UserResponse, UserDataResponse } from "./lib/user/types.js"
|
|
18
|
+
export type { Principal, Resource, Resources } from "./lib/Policy/types.js"
|
|
17
19
|
export type { FunctionRequest, FunctionResponse, FunctionInvocation } from "./lib/Function/types.js"
|
|
18
20
|
export type { DatabaseRequest, DatabaseResponse } from "./lib/Database/types.js"
|
|
19
21
|
export type { StorageRequest, StorageUpdateRequest, StorageResponse } from "./lib/Storage/types.js"
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Client } from "../../client.js"
|
|
2
|
+
import { PolicyRoutes } from "../../lib-internal/routes/PolicyRoutes.js"
|
|
3
|
+
import type { TaruviConfig } from "../../types.js"
|
|
4
|
+
import type { Principal, Resource, Resources } from "./types.js"
|
|
5
|
+
|
|
6
|
+
export class Policy {
|
|
7
|
+
private client: Client
|
|
8
|
+
private config: TaruviConfig
|
|
9
|
+
constructor(client: Client) {
|
|
10
|
+
this.client = client
|
|
11
|
+
this.config = this.client.getConfig()
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
async checkResource(resources: Resources, principal?: Principal) {
|
|
15
|
+
const url = PolicyRoutes.baseUrl(this.config.appSlug) + PolicyRoutes.checkResource
|
|
16
|
+
const body = JSON.stringify({
|
|
17
|
+
principal,
|
|
18
|
+
resources: resources.map(r => ({
|
|
19
|
+
resource: {
|
|
20
|
+
kind: `${this.config.appSlug}:${r.tableName}`,
|
|
21
|
+
id: r.recordId,
|
|
22
|
+
attr: r.attributes || {}
|
|
23
|
+
}
|
|
24
|
+
}))
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
return await this.client.httpClient.post(url, body)
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export interface Principal {
|
|
2
|
+
id: string
|
|
3
|
+
roles: string[]
|
|
4
|
+
attr: Record<string, unknown>
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export type Resource = {
|
|
8
|
+
kind: string
|
|
9
|
+
id: string
|
|
10
|
+
attr: Record<string, unknown>
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export type Resources = {
|
|
14
|
+
tableName: string
|
|
15
|
+
recordId: string
|
|
16
|
+
attributes: Record<string, unknown>
|
|
17
|
+
actions: string[]
|
|
18
|
+
}[]
|
|
19
|
+
|
|
20
|
+
export type ResourceCheckResponse = {
|
|
21
|
+
allowed: boolean
|
|
22
|
+
reason: string
|
|
23
|
+
}
|