Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/authorize/src/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ describe('authorize api', () => {
expect(region).toBe('FL');
});

test('getRegion returns undefined when given falsey value', async () => {
test('getRegion returns null when given falsey value', async () => {
const region = await getRegion(false);
expect(region).toBeUndefined();
expect(region).toBeNull();
});

test('getRegion returns value when not falsey', async () => {
Expand Down
12 changes: 6 additions & 6 deletions packages/authorize/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,27 @@ import type { Permission, RequestedPermissions, RequestedResources } from './typ
*
* If the region is a string then it will be returned without fetching.
*/
export const getRegion = async (region?: boolean | string): Promise<string | undefined> => {
export const getRegion = async (region?: boolean | string): Promise<string | null> => {
if (region === true) {
const resp = await avRegionsApi.getCurrentRegion();

return resp?.data?.regions?.[0]?.id;
return resp?.data?.regions?.[0]?.id || null;
}

return region || undefined;
return region || null;
};

/**
* Fetch the permissions for the logged in user
*/
export const getPermissions = async (
permissions: RequestedPermissions,
region?: string
region?: string | null
): Promise<Record<string, Permission>> => {
if (!permissions) return {};

// TODO: fix these types
const response = await avUserPermissionsApi.getPermissions(permissions as string[], region);
const response = await avUserPermissionsApi.getPermissions(permissions as string[], region || undefined);

return response.reduce<Record<string, Permission>>((prev, cur) => {
prev[cur.id] = cur;
Expand Down Expand Up @@ -91,7 +91,7 @@ export const checkPermission = (
*/
export const checkPermissions = async (
permissions: RequestedPermissions,
region?: string,
region?: string | null,
resources?: RequestedResources,
organizationId?: string,
customerId?: string
Expand Down
Loading