From b82bfb5aaba1db60c8aa2108a26e5887ec25ba12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ot=C3=A1vio=20Jacobi?= Date: Thu, 10 Aug 2023 19:06:28 -0300 Subject: [PATCH] **BREAKING**: Drop auth.getUserActorId in favor of auth.getActorId Change-type: major --- DOCUMENTATION.md | 17 ------- src/auth.ts | 30 ------------- src/models/api-key.ts | 2 +- tests/integration/auth.spec.ts | 56 ------------------------ tests/integration/models/api-key.spec.ts | 4 +- tests/integration/setup.ts | 2 +- 6 files changed, 4 insertions(+), 107 deletions(-) diff --git a/DOCUMENTATION.md b/DOCUMENTATION.md index e851810cb..407f615da 100644 --- a/DOCUMENTATION.md +++ b/DOCUMENTATION.md @@ -431,7 +431,6 @@ const sdk = fromSharedOptions(); * [.getToken()](#balena.auth.getToken) ⇒ Promise * [.getUserInfo()](#balena.auth.getUserInfo) ⇒ Promise * [.getActorId()](#balena.auth.getActorId) ⇒ Promise - * [.getUserActorId()](#balena.auth.getUserActorId) ⇒ Promise * [.logout()](#balena.auth.logout) ⇒ Promise * [.register(credentials)](#balena.auth.register) ⇒ Promise * [.verifyEmail(verificationPayload)](#balena.auth.verifyEmail) ⇒ Promise @@ -6485,7 +6484,6 @@ balena.models.billing.downloadInvoice(orgId, '0000').then(function(stream) { * [.getToken()](#balena.auth.getToken) ⇒ Promise * [.getUserInfo()](#balena.auth.getUserInfo) ⇒ Promise * [.getActorId()](#balena.auth.getActorId) ⇒ Promise - * [.getUserActorId()](#balena.auth.getUserActorId) ⇒ Promise * [.logout()](#balena.auth.logout) ⇒ Promise * [.register(credentials)](#balena.auth.register) ⇒ Promise * [.verifyEmail(verificationPayload)](#balena.auth.verifyEmail) ⇒ Promise @@ -6770,21 +6768,6 @@ balena.auth.getActorId().then(function(actorId) { console.log(actorId); }); ``` - - -#### auth.getUserActorId() ⇒ Promise -This will only work if you used [login](#balena.auth.login) to log in. - -**Kind**: static method of [auth](#balena.auth) -**Summary**: Get current logged in user's actor id -**Access**: public -**Fulfil**: Number - user id -**Example** -```js -balena.auth.getUserActorId().then(function(userActorId) { - console.log(userActorId); -}); -``` #### auth.logout() ⇒ Promise diff --git a/src/auth.ts b/src/auth.ts index 940769e7a..a47d440e6 100644 --- a/src/auth.ts +++ b/src/auth.ts @@ -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 { - const { id } = await getUserInfo(); - const { actor } = (await pine.get({ - resource: 'user', - id, - options: { - $select: 'actor', - }, - }))!; - return actor; - } - /** * @summary Logout * @name logout @@ -497,7 +468,6 @@ const getAuth = function ( isLoggedIn, getToken, getActorId, - getUserActorId, getUserInfo, logout, register, diff --git a/src/models/api-key.ts b/src/models/api-key.ts index 9c338dcfd..f41a04d21 100644 --- a/src/models/api-key.ts +++ b/src/models/api-key.ts @@ -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. diff --git a/tests/integration/auth.spec.ts b/tests/integration/auth.spec.ts index eed848402..044e64855 100644 --- a/tests/integration/auth.spec.ts +++ b/tests/integration/auth.spec.ts @@ -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({ @@ -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 () { @@ -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(); @@ -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(); @@ -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(); @@ -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(); diff --git a/tests/integration/models/api-key.spec.ts b/tests/integration/models/api-key.spec.ts index 512066521..b2358405d 100644 --- a/tests/integration/models/api-key.spec.ts +++ b/tests/integration/models/api-key.spec.ts @@ -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 }, }, }); @@ -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 }, }, }); diff --git a/tests/integration/setup.ts b/tests/integration/setup.ts index fda0fd404..6a335c710 100644 --- a/tests/integration/setup.ts +++ b/tests/integration/setup.ts @@ -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, },