New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@availity/authorize

Package Overview
Dependencies
Maintainers
14
Versions
74
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@availity/authorize - npm Package Compare versions

Comparing version 1.4.1 to 2.0.0-alpha.128

9

Authorize.d.ts

@@ -1,8 +0,3 @@

export type NumberOrString = string | number;
export type Permission = string | number | NumberOrString[];
export type Resource = string | number | NumberOrString[];
export interface AuthorizeProps {
permissions: string | number | Permission[],
resources?: string | number | Resource[],
permissions: Array<string | number> | Array<Array<string | number>>;
region?: boolean | string;

@@ -18,2 +13,2 @@ loader?: boolean | React.ReactType;

declare const Authorize: React.ComponentType<AuthorizeProps>;
export default Authorize;
export default Authorize;

@@ -9,3 +9,2 @@ import React from 'react';

permissions,
resources,
customerId,

@@ -23,3 +22,2 @@ organizationId,

region,
resources,
});

@@ -53,15 +51,2 @@

]).isRequired,
resources: PropTypes.oneOfType([
PropTypes.arrayOf(
PropTypes.oneOfType([
PropTypes.arrayOf(
PropTypes.oneOfType([PropTypes.string, PropTypes.number])
),
PropTypes.string,
PropTypes.number,
])
),
PropTypes.string,
PropTypes.number,
]),
region: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]),

@@ -68,0 +53,0 @@ loader: PropTypes.oneOfType([PropTypes.bool, PropTypes.node]),

@@ -6,21 +6,2 @@ # Change Log

## [1.4.1](https://github.com/Availity/availity-react/compare/@availity/authorize@1.4.0...@availity/authorize@1.4.1) (2019-12-04)
**Note:** Version bump only for package @availity/authorize
# [1.4.0](https://github.com/Availity/availity-react/compare/@availity/authorize@1.3.1...@availity/authorize@1.4.0) (2019-12-03)
### Features
* **authorize:** add resources filter ([e266abc](https://github.com/Availity/availity-react/commit/e266abc037fd5940ffe7f5e4ef5852bff36a39de))
## [1.3.1](https://github.com/Availity/availity-react/compare/@availity/authorize@1.3.0...@availity/authorize@1.3.1) (2019-09-25)

@@ -27,0 +8,0 @@

{
"name": "@availity/authorize",
"version": "1.4.1",
"version": "2.0.0-alpha.128+4601c442",
"author": "Evan Sharp <evan.sharp@gmail.com>",

@@ -38,3 +38,3 @@ "description": "Check user permissions to see if the current user is authorized to see your content.",

},
"gitHead": "a8ed2535bdf2a0c29c7e50c129d3607b37d1d548"
"gitHead": "4601c44201dc4a9850c678bd068cf082efeefa04"
}

@@ -21,13 +21,2 @@ import React from 'react';

customerId: '1194',
resources: [
{
id: '1',
},
{
id: '2',
},
{
id: '3',
},
],
},

@@ -151,34 +140,2 @@ ],

});
test('should render authorized with correct resources', async () => {
const { getByText } = render(
<Authorize
permissions="1234"
customerId="1194"
unauthorized="You do not have permission to see this"
resources="2"
>
You have permission to see this
</Authorize>
);
await waitForElement(() => getByText('You have permission to see this'));
});
test('should render unauthorized with incorrect resources', async () => {
const { getByText } = render(
<Authorize
permissions="1234"
customerId="1194"
unauthorized="You do not have permission to see this"
resources="5"
>
You have permission to see this
</Authorize>
);
await waitForElement(() =>
getByText('You do not have permission to see this')
);
});
});

@@ -38,13 +38,2 @@ import React from 'react';

customerId: '1194',
resources: [
{
id: '1',
},
{
id: '2',
},
{
id: '3',
},
],
},

@@ -128,2 +117,24 @@ ],

test('should render with console warning', async () => {
// eslint-disable-next-line no-console
console.error = jest.fn();
const { getByText } = render(
<Component
permissions="1234"
region="FL"
organizationId="1111"
customerId="1194"
>
You have permission to see this
</Component>
);
await waitForElement(() => getByText('You have permission to see this'));
// eslint-disable-next-line no-console
expect(console.error).toHaveBeenCalledWith(
'You provided both `organizationId` and `customerId` to Authorize but both cannot be used together; `organizationId` will be used and `customerId` will be ignored. If you want to use `customerId` do not provide `organizationId`.'
);
});
test('should render authorized with region', async () => {

@@ -195,90 +206,2 @@ const { getByText } = render(

});
test('should render authorized with correct resources as string', async () => {
const { getByText } = render(
<Component permissions="1234" customerId="1194" resources="1">
You have permission to see this
</Component>
);
await waitForElement(() => getByText('You have permission to see this'));
});
test('should render authorized with correct resources as number', async () => {
const { getByText } = render(
<Component permissions="1234" customerId="1194" resources={2}>
You have permission to see this
</Component>
);
await waitForElement(() => getByText('You have permission to see this'));
});
test('should render authorized with correct resources as array', async () => {
const { getByText } = render(
<Component permissions="1234" customerId="1194" resources={['1']}>
You have permission to see this
</Component>
);
await waitForElement(() => getByText('You have permission to see this'));
});
test('should render authorized with correct resources as nested array', async () => {
const { getByText } = render(
<Component permissions="1234" customerId="1194" resources={[['1', '2']]}>
You have permission to see this
</Component>
);
await waitForElement(() => getByText('You have permission to see this'));
});
test('should render unauthorized with incorrect resources as string', async () => {
const { getByText } = render(
<Component permissions="1234" customerId="1194" resources="5">
You have permission to see this
</Component>
);
await waitForElement(() =>
getByText('You do not have permission to see this')
);
});
test('should render unauthorized with incorrect resources as number', async () => {
const { getByText } = render(
<Component permissions="1234" customerId="1194" resources={6}>
You have permission to see this
</Component>
);
await waitForElement(() =>
getByText('You do not have permission to see this')
);
});
test('should render unauthorized with incorrect resources as array', async () => {
const { getByText } = render(
<Component permissions="1234" customerId="1194" resources={['5']}>
You have permission to see this
</Component>
);
await waitForElement(() =>
getByText('You do not have permission to see this')
);
});
test('should render unauthorized with incorrect resources as nested array', async () => {
const { getByText } = render(
<Component permissions="1234" customerId="1194" resources={[['1', '5']]}>
You have permission to see this
</Component>
);
await waitForElement(() =>
getByText('You do not have permission to see this')
);
});
});

@@ -1,3 +0,1 @@

import { Permission, Resource } from './Authorize';
export interface AuthorizeOpts {

@@ -7,7 +5,6 @@ organizationId?: string;

region?: boolean | string;
resources?: string | number | Resource[];
}
declare function useAuthorize(
permissions: string | number | Permission[],
permissions: string | Array<String>,
options?: AuthorizeOpts

@@ -14,0 +11,0 @@ ): [boolean,boolean];

import { useState, useEffect } from 'react';
import { avUserPermissionsApi, avRegionsApi } from '@availity/api-axios';
const warned = {};
function warnOnce(message) {
if (!warned[message]) {
// eslint-disable-next-line no-console
if (typeof console !== 'undefined' && typeof console.error === 'function') {
console.error(message); // eslint-disable-line no-console
}
warned[message] = true;
}
}
export default (
permissions,
{ organizationId, customerId, region = true, resources } = {}
{ organizationId, customerId, region = true } = {}
) => {

@@ -31,45 +43,25 @@ const [authorized, setAuthorized] = useState(false);

if (!permission) return false;
let isAuthorizedForCustomerId = true;
let isAuthorizedForOrganizationId = true;
let isAuthorizedForResources = true;
if (organizationId) {
isAuthorizedForOrganizationId =
if (customerId) {
warnOnce(
'You provided both `organizationId` and `customerId` to Authorize but both cannot be used together; `organizationId` will be used and `customerId` will be ignored. If you want to use `customerId` do not provide `organizationId`.'
);
}
return (
permission.organizations.filter(
({ id: orgId }) => orgId === organizationId
).length > 0;
).length > 0
);
}
if (customerId) {
isAuthorizedForCustomerId =
return (
permission.organizations.filter(
({ customerId: orgCustomerId }) => orgCustomerId === customerId
).length > 0;
).length > 0
);
}
if (resources !== undefined) {
const resourceSets = Array.isArray(resources) ? resources : [resources];
isAuthorizedForResources =
resourceSets.length === 0 ||
resourceSets.some(resourceSet => {
if (Array.isArray(resourceSet)) {
return resourceSet.every(resource =>
permission.organizations.some(
({ resources: orgResources = [] }) =>
orgResources.some(({ id }) => `${id}` === `${resource}`)
)
);
}
return permission.organizations.some(
({ resources: orgResources = [] }) =>
orgResources.some(({ id }) => `${id}` === `${resourceSet}`)
);
});
}
return (
isAuthorizedForCustomerId &&
isAuthorizedForOrganizationId &&
isAuthorizedForResources
);
return true;
};

@@ -83,8 +75,6 @@

const permissionsList = [].concat(...permissionsSets);
const newPermissions = (
await avUserPermissionsApi.getPermissions(
permissionsList,
await getRegion()
)
).reduce((prev, cur) => {
const newPermissions = (await avUserPermissionsApi.getPermissions(
permissionsList,
await getRegion()
)).reduce((prev, cur) => {
prev[cur.id] = cur;

@@ -91,0 +81,0 @@ return prev;

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc