Skip to content

Commit

Permalink
**BREAKING**: Drop auth.getUserActorId in favor of auth.getActorId
Browse files Browse the repository at this point in the history
Change-type: major
  • Loading branch information
otaviojacobi committed Aug 17, 2023
1 parent 4ee63a5 commit b82bfb5
Show file tree
Hide file tree
Showing 6 changed files with 4 additions and 107 deletions.
17 changes: 0 additions & 17 deletions DOCUMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,6 @@ const sdk = fromSharedOptions();
* [.getToken()](#balena.auth.getToken) ⇒ <code>Promise</code>
* [.getUserInfo()](#balena.auth.getUserInfo) ⇒ <code>Promise</code>
* [.getActorId()](#balena.auth.getActorId) ⇒ <code>Promise</code>
* [.getUserActorId()](#balena.auth.getUserActorId) ⇒ <code>Promise</code>
* [.logout()](#balena.auth.logout) ⇒ <code>Promise</code>
* [.register(credentials)](#balena.auth.register) ⇒ <code>Promise</code>
* [.verifyEmail(verificationPayload)](#balena.auth.verifyEmail) ⇒ <code>Promise</code>
Expand Down Expand Up @@ -6485,7 +6484,6 @@ balena.models.billing.downloadInvoice(orgId, '0000').then(function(stream) {
* [.getToken()](#balena.auth.getToken) ⇒ <code>Promise</code>
* [.getUserInfo()](#balena.auth.getUserInfo) ⇒ <code>Promise</code>
* [.getActorId()](#balena.auth.getActorId) ⇒ <code>Promise</code>
* [.getUserActorId()](#balena.auth.getUserActorId) ⇒ <code>Promise</code>
* [.logout()](#balena.auth.logout) ⇒ <code>Promise</code>
* [.register(credentials)](#balena.auth.register) ⇒ <code>Promise</code>
* [.verifyEmail(verificationPayload)](#balena.auth.verifyEmail) ⇒ <code>Promise</code>
Expand Down Expand Up @@ -6770,21 +6768,6 @@ balena.auth.getActorId().then(function(actorId) {
console.log(actorId);
});
```
<a name="balena.auth.getUserActorId"></a>

#### auth.getUserActorId() ⇒ <code>Promise</code>
This will only work if you used [login](#balena.auth.login) to log in.

**Kind**: static method of [<code>auth</code>](#balena.auth)
**Summary**: Get current logged in user's actor id
**Access**: public
**Fulfil**: <code>Number</code> - user id
**Example**
```js
balena.auth.getUserActorId().then(function(userActorId) {
console.log(userActorId);
});
```
<a name="balena.auth.logout"></a>

#### auth.logout() ⇒ <code>Promise</code>
Expand Down
30 changes: 0 additions & 30 deletions src/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,35 +332,6 @@ const getAuth = function (
return (await getActorDetails()).id;
}

/**
* @summary Get current logged in user's actor id
* @name getUserActorId
* @public
* @function
* @memberof balena.auth
*
* @description This will only work if you used {@link balena.auth.login} to log in.
*
* @fulfil {Number} - user id
* @returns {Promise}
*
* @example
* balena.auth.getUserActorId().then(function(userActorId) {
* console.log(userActorId);
* });
*/
async function getUserActorId(): Promise<number> {
const { id } = await getUserInfo();
const { actor } = (await pine.get({
resource: 'user',
id,
options: {
$select: 'actor',
},
}))!;
return actor;
}

/**
* @summary Logout
* @name logout
Expand Down Expand Up @@ -497,7 +468,6 @@ const getAuth = function (
isLoggedIn,
getToken,
getActorId,
getUserActorId,
getUserInfo,
logout,
register,
Expand Down
2 changes: 1 addition & 1 deletion src/models/api-key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ const getApiKeysModel = function (
mergePineOptions(
{
$filter: {
is_of__actor: await sdkInstance.auth.getUserActorId(),
is_of__actor: await sdkInstance.auth.getActorId(),
// the only way to reason whether it's
// a named user api key vs a deprecated user api key
// is whether it has a name.
Expand Down
56 changes: 0 additions & 56 deletions tests/integration/auth.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,6 @@ describe('SDK authentication', function () {
});
});

describe('balena.auth.getUserActorId()', () => {
it('should be rejected with an error', async function () {
const promise = balena.auth.getUserActorId();
await expect(promise).to.be.rejected.and.eventually.have.property(
'code',
'BalenaNotLoggedIn',
);
});
});

describe.skip('balena.auth.register()', function () {
beforeEach(async () => {
await balena.auth.login({
Expand Down Expand Up @@ -224,16 +214,6 @@ describe('SDK authentication', function () {
);
});
});

describe('balena.auth.getUserActorId()', () => {
it('should be rejected with an error', async function () {
const promise = balena.auth.getUserActorId();
await expect(promise).to.be.rejected.and.eventually.have.property(
'code',
'BalenaNotLoggedIn',
);
});
});
});

describe('when logged in with credentials', function () {
Expand Down Expand Up @@ -277,14 +257,6 @@ describe('SDK authentication', function () {
});
});

describe('balena.auth.getUserActorId()', () => {
it('should eventually be a user id', async () => {
const userId = await balena.auth.getUserActorId();
expect(userId).to.be.a('number');
expect(userId).to.be.greaterThan(0);
});
});

describe('balena.auth.logout()', () => {
it('should logout the user', async () => {
await balena.auth.logout();
Expand Down Expand Up @@ -333,16 +305,6 @@ describe('SDK authentication', function () {
});
});

describe('balena.auth.getUserActorId()', () => {
it('should be rejected with an error', async () => {
const promise = balena.auth.getUserActorId();
await expect(promise).to.be.rejected.and.eventually.have.property(
'message',
'The authentication credentials in use are not of a user',
);
});
});

describe('balena.auth.logout()', function () {
it('should logout the user', async () => {
await balena.auth.logout();
Expand Down Expand Up @@ -399,16 +361,6 @@ describe('SDK authentication', function () {
});
});

describe('balena.auth.getUserActorId()', () => {
it('should be rejected with an error', async () => {
const promise = balena.auth.getUserActorId();
await expect(promise).to.be.rejected.and.eventually.have.property(
'message',
'The authentication credentials in use are not of a user',
);
});
});

describe('balena.auth.logout()', function () {
it('should logout the user', async () => {
await balena.auth.logout();
Expand Down Expand Up @@ -465,14 +417,6 @@ describe('SDK authentication', function () {
});
});

describe('balena.auth.getUserActorId()', () => {
it('should eventually be a user id', async () => {
const userId = await balena.auth.getUserActorId();
expect(userId).to.be.a('number');
expect(userId).to.be.greaterThan(0);
});
});

describe('balena.auth.logout()', function () {
it('should logout the user', async () => {
await balena.auth.logout();
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/models/api-key.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe('API Key model', function () {
it('should retrieve an empty array', async function () {
const apiKeys = await balena.models.apiKey.getAll({
$filter: {
is_of__actor: await balena.auth.getUserActorId(),
is_of__actor: await balena.auth.getActorId(),
name: { $ne: null },
},
});
Expand All @@ -81,7 +81,7 @@ describe('API Key model', function () {
it('should be able to retrieve all api keys created', async function () {
const apiKeys = await balena.models.apiKey.getAll({
$filter: {
is_of__actor: await balena.auth.getUserActorId(),
is_of__actor: await balena.auth.getActorId(),
name: { $ne: null },
},
});
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export async function resetUser() {
// only delete named user api keys
options: {
$filter: {
is_of__actor: await balena.auth.getUserActorId(),
is_of__actor: await balena.auth.getActorId(),
name: {
$ne: null,
},
Expand Down

0 comments on commit b82bfb5

Please sign in to comment.