From 45b9ad7f09218f418d9fd80e52df3ee674bae455 Mon Sep 17 00:00:00 2001 From: FelixBlaisThon <52010042+FelixBlaisThon@users.noreply.github.com> Date: Mon, 2 Dec 2024 12:09:09 -0500 Subject: [PATCH] feat(api-keys): +listing apikey eligibility call endpoint (#889) --- src/resources/ApiKeyTemplate/ApiKeyTemplate.ts | 8 +++++++- .../ApiKeyTemplate/ApiKeyTemplateInterface.ts | 15 +++++++++++++++ .../ApiKeyTemplate/test/ApiKeyTemplate.spec.ts | 8 ++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/resources/ApiKeyTemplate/ApiKeyTemplate.ts b/src/resources/ApiKeyTemplate/ApiKeyTemplate.ts index a4795f056..ff9e3638b 100644 --- a/src/resources/ApiKeyTemplate/ApiKeyTemplate.ts +++ b/src/resources/ApiKeyTemplate/ApiKeyTemplate.ts @@ -1,5 +1,5 @@ import Resource from '../Resource.js'; -import {ApiKeyTemplateModel} from './ApiKeyTemplateInterface.js'; +import {ApiKeyTemplateEligibilityResponseModel, ApiKeyTemplateModel} from './ApiKeyTemplateInterface.js'; export default class ApiKeyTemplate extends Resource { static baseUrl = '/rest/templates/apikeys'; @@ -7,4 +7,10 @@ export default class ApiKeyTemplate extends Resource { get(apiKeyTemplateId: string) { return this.api.get(`${ApiKeyTemplate.baseUrl}/${apiKeyTemplateId}`); } + + listAPIKeysEligibility() { + return this.api.get( + `${ApiKeyTemplate.baseUrl}/privileges/eligibility`, + ); + } } diff --git a/src/resources/ApiKeyTemplate/ApiKeyTemplateInterface.ts b/src/resources/ApiKeyTemplate/ApiKeyTemplateInterface.ts index 2a2c31667..58ff273f7 100644 --- a/src/resources/ApiKeyTemplate/ApiKeyTemplateInterface.ts +++ b/src/resources/ApiKeyTemplate/ApiKeyTemplateInterface.ts @@ -26,3 +26,18 @@ export interface ApiKeyTemplateModel { */ privileges?: PrivilegeModel[]; } + +export interface ApiKeyTemplateEligibilityResponseModel { + /** + * The id of the template + */ + id: string; + /** + * The list of privileges missing to access the template + */ + missingPrivileges: PrivilegeModel[]; + /** + * If the user can generate an API key from this template + */ + canGenerate: boolean; +} diff --git a/src/resources/ApiKeyTemplate/test/ApiKeyTemplate.spec.ts b/src/resources/ApiKeyTemplate/test/ApiKeyTemplate.spec.ts index 838845aaa..dc034d3a9 100644 --- a/src/resources/ApiKeyTemplate/test/ApiKeyTemplate.spec.ts +++ b/src/resources/ApiKeyTemplate/test/ApiKeyTemplate.spec.ts @@ -22,4 +22,12 @@ describe('ApiKeyTemplateModel', () => { expect(api.get).toHaveBeenCalledWith(`${ApiKeyTemplate.baseUrl}/${apiKeyTemplateToGetId}`); }); }); + + describe('listAPIKeysEligibility', () => { + it('should make a GET call to the listAPIKeysEligibility endpoint', async () => { + await apiKeyTemplate.listAPIKeysEligibility(); + expect(api.get).toHaveBeenCalledTimes(1); + expect(api.get).toHaveBeenCalledWith(`${ApiKeyTemplate.baseUrl}/privileges/eligibility`); + }); + }); });