Skip to content

Commit 62c4e98

Browse files
SpiralPanneeb
andcommitted
[VET-1380] Add admin/status/whoami to Stardog.js (#271)
* [VET-1380] Add `admin/status/whoami` to Stardog.js * camel case * add test for `user.whoAmI` Co-authored-by: Annee Barrett <annee.barrett@stardog.com>
1 parent c7726e1 commit 62c4e98

4 files changed

Lines changed: 38 additions & 0 deletions

File tree

lib/index.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,6 +1065,13 @@ declare namespace Stardog {
10651065
*/
10661066
function token(conn: Connection): Promise<HTTP.Body>;
10671067

1068+
/**
1069+
* Returns the username for the given connection.
1070+
*
1071+
* @param {Connection} conn the Stardog server connection
1072+
*/
1073+
function whoAmI(conn: Connection): Promise<HTTP.Body>;
1074+
10681075
interface Permission {
10691076
action: Action,
10701077
resourceType: ResourceType,

lib/user/main.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,13 @@ const token = conn => {
171171
}).then(httpBody);
172172
};
173173

174+
const whoAmI = conn => {
175+
const headers = conn.headers();
176+
return fetch(conn.request('admin', 'status', 'whoami'), {
177+
headers,
178+
}).then(httpBody);
179+
};
180+
174181
module.exports = {
175182
assignPermission,
176183
changePassword,
@@ -188,4 +195,5 @@ module.exports = {
188195
superUser,
189196
token,
190197
valid,
198+
whoAmI,
191199
};

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,5 +129,9 @@
129129
]
130130
}
131131
},
132+
"prettier": {
133+
"singleQuote": true,
134+
"trailingComma": "es5"
135+
},
132136
"stardog-version": ">=7.0.0"
133137
}

test/whoAmI.spec.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/* eslint-env jest */
2+
3+
const { user } = require('../lib');
4+
const { ConnectionFactory } = require('./setup-database');
5+
6+
describe('whoAmI', () => {
7+
let conn;
8+
9+
beforeEach(() => {
10+
conn = ConnectionFactory();
11+
});
12+
13+
it("should return the current user's username.", () =>
14+
user.whoAmI(conn).then(res => {
15+
expect(res.status).toEqual(200);
16+
expect(conn.username).toBeTruthy();
17+
expect(res.body).toEqual(conn.username);
18+
}));
19+
});

0 commit comments

Comments
 (0)