diff --git a/src/ego-token-utils.ts b/src/ego-token-utils.ts index 42566ae..bdfc86f 100644 --- a/src/ego-token-utils.ts +++ b/src/ego-token-utils.ts @@ -217,6 +217,10 @@ export const isProgramAdmin = (args: { egoJwt: string; programId: string }): boo // ); } +export const getReadableProgramShortNames = (egoJwt: string): string[] => { + return getReadableProgramScopes(egoJwt).map(({ policy }) => policy.replace(PROGRAM_PREFIX, '')) +} + export default { isPermission, decodeToken, @@ -229,5 +233,6 @@ export default { canReadProgram, canWriteProgram, isProgramAdmin, - canReadSomeProgram + canReadSomeProgram, + getReadableProgramShortNames } diff --git a/test/utils.test.ts b/test/utils.test.ts index 71f6d65..348fa06 100644 --- a/test/utils.test.ts +++ b/test/utils.test.ts @@ -12,7 +12,8 @@ const { parseScope, serializeScope, canReadSomeProgram, - decodeToken + decodeToken, + getReadableProgramShortNames } = utils /** has the following scopes: @@ -125,6 +126,14 @@ describe('getReadableProgramScopes', () => { }) }) +describe('getReadableProgramShortNames', () => { + it('should return authorized program names', () => { + expect(getReadableProgramShortNames(DATA_SUBMITTER)).toEqual([]) + expect(getReadableProgramShortNames(PROGRAM_ADMIN)).toEqual(['PACA-AU']) + expect(getReadableProgramShortNames(DCC_USER)).toEqual([]) + }) +}) + describe('isDccMember', () => { it('should validate DCC member as such', () => { expect(isDccMember(DCC_USER)).toBe(true)