mirror of
https://github.com/HeyPuter/puter.git
synced 2026-05-04 08:30:39 +00:00
dev: add puter.perms module to puter.js
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
export default class Perms {
|
||||
setAuthToken (authToken) {
|
||||
this.authToken = authToken;
|
||||
}
|
||||
setAPIOrigin (APIOrigin) {
|
||||
this.APIOrigin = APIOrigin;
|
||||
}
|
||||
async req_ (route, body) {
|
||||
const resp = await fetch(
|
||||
this.APIOrigin + route, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
Authorization: `Bearer ${this.authToken}`,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify(body),
|
||||
}
|
||||
);
|
||||
return await resp.json();
|
||||
}
|
||||
|
||||
// Grant Permissions
|
||||
async grantUser (target_username, permission) {
|
||||
return await this.req_('/auth/grant-user-user', {
|
||||
target_username, permission,
|
||||
})
|
||||
}
|
||||
|
||||
async grantGroup (group_uid, permission) {
|
||||
return await this.req_('/auth/grant-user-group', {
|
||||
group_uid, permission,
|
||||
})
|
||||
}
|
||||
|
||||
async grantApp (app_uid, permission) {
|
||||
return await this.req_('/auth/grant-user-app', {
|
||||
app_uid, permission,
|
||||
})
|
||||
}
|
||||
|
||||
async grantOrigin (origin, permission) {
|
||||
return await this.req_('/auth/grant-user-app', {
|
||||
origin, permission,
|
||||
})
|
||||
}
|
||||
|
||||
// Revoke Permissions
|
||||
async revokeUser (target_username, permission) {
|
||||
return await this.req_('/auth/revoke-user-user', {
|
||||
target_username, permission,
|
||||
})
|
||||
}
|
||||
|
||||
async revokeGroup (group_uid, permission) {
|
||||
return await this.req_('/auth/revoke-user-group', {
|
||||
group_uid, permission,
|
||||
})
|
||||
}
|
||||
|
||||
async revokeApp (app_uid, permission) {
|
||||
return await this.req_('/auth/revoke-user-app', {
|
||||
app_uid, permission,
|
||||
})
|
||||
}
|
||||
|
||||
async revokeOrigin (origin, permission) {
|
||||
return await this.req_('/auth/revoke-user-app', {
|
||||
origin, permission,
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user