Skip to content

Commit 5d8691e

Browse files
authored
feat: allow permissions read_attach on token (#21)
* feat: allow permissions read_attach on token * docs(readme): attach read_attach example
1 parent 88420d5 commit 5d8691e

3 files changed

Lines changed: 35 additions & 0 deletions

File tree

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ const token = await turso.groups.createToken("default", {
4848
expiration: "1w2d6h3m",
4949
authorization: "full-access",
5050
});
51+
const token = await turso.groups.createToken("default", {
52+
permissions: {
53+
read_attach: {
54+
databases: ["db1", "db2"]
55+
}
56+
}
57+
});
5158
const token = await turso.groups.rotateTokens("default");
5259
```
5360

@@ -102,6 +109,13 @@ const token = await turso.databases.createToken("my-db", {
102109
expiration: "1w2d6h3n",
103110
authorization: "full-access",
104111
});
112+
const token = await turso.databases.createToken("my-db", {
113+
permissions: {
114+
read_attach: {
115+
databases: ["db1", "db2"]
116+
}
117+
}
118+
});
105119
const token = await turso.databases.rotateTokens("my-db");
106120

107121
const usageStatsWithDate = await turso.databases.usage("my-db");

src/database.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,9 @@ export class DatabaseClient {
212212
options?: {
213213
expiration: string;
214214
authorization: "read-only" | "full-access";
215+
permissions?: {
216+
read_attach: { databases: Database["name"][] };
217+
};
215218
}
216219
): Promise<DatabaseToken> {
217220
const queryParams = new URLSearchParams();
@@ -229,6 +232,13 @@ export class DatabaseClient {
229232
this.config,
230233
{
231234
method: "POST",
235+
body: JSON.stringify({
236+
permissions: {
237+
read_attach: {
238+
databases: options?.permissions?.read_attach?.databases ?? [],
239+
},
240+
},
241+
}),
232242
}
233243
);
234244

src/group.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { TursoConfig } from "./config";
22
import { LocationKeys } from "./location";
33
import { TursoClient } from "./client";
4+
import type { Database } from "./database";
45

56
export interface Group {
67
locations: Array<keyof LocationKeys>;
@@ -116,6 +117,9 @@ export class GroupClient {
116117
options?: {
117118
expiration: string;
118119
authorization: "read-only" | "full-access";
120+
permissions?: {
121+
read_attach: { databases: Database["name"][] };
122+
};
119123
}
120124
): Promise<GroupToken> {
121125
const queryParams = new URLSearchParams();
@@ -133,6 +137,13 @@ export class GroupClient {
133137
this.config,
134138
{
135139
method: "POST",
140+
body: JSON.stringify({
141+
permissions: {
142+
read_attach: {
143+
databases: options?.permissions?.read_attach?.databases ?? [],
144+
},
145+
},
146+
}),
136147
}
137148
);
138149

0 commit comments

Comments
 (0)