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

@availity/authorizations-core

Package Overview
Dependencies
Maintainers
14
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@availity/authorizations-core - npm Package Compare versions

Comparing version 1.0.7 to 1.0.10

61

CHANGELOG.md

@@ -6,3 +6,3 @@ # Change Log

## [1.0.7](https://github.com/Availity/sdk-js/compare/@availity/authorizations-core@1.0.6...@availity/authorizations-core@1.0.7) (2020-01-03)
## [1.0.10](https://github.com/Availity/sdk-js/compare/@availity/authorizations-core@1.0.7...@availity/authorizations-core@1.0.10) (2020-02-13)

@@ -15,3 +15,3 @@ **Note:** Version bump only for package @availity/authorizations-core

## [1.0.6](https://github.com/Availity/sdk-js/compare/@availity/authorizations-core@1.0.5...@availity/authorizations-core@1.0.6) (2020-01-03)
## [1.0.9](https://github.com/Availity/sdk-js/compare/@availity/authorizations-core@1.0.8...@availity/authorizations-core@1.0.9) (2020-02-13)

@@ -24,3 +24,3 @@ **Note:** Version bump only for package @availity/authorizations-core

## [1.0.5](https://github.com/Availity/sdk-js/compare/@availity/authorizations-core@1.0.4...@availity/authorizations-core@1.0.5) (2019-04-17)
## [1.0.8](https://github.com/Availity/sdk-js/compare/@availity/authorizations-core@1.0.7...@availity/authorizations-core@1.0.8) (2020-02-13)

@@ -33,13 +33,20 @@ **Note:** Version bump only for package @availity/authorizations-core

## [1.0.4](https://github.com/Availity/sdk-js/compare/@availity/authorizations-core@1.0.3...@availity/authorizations-core@1.0.4) (2019-03-18)
## [1.0.7](https://github.com/Availity/sdk-js/compare/@availity/authorizations-core@1.0.6...@availity/authorizations-core@1.0.7) (2020-01-03)
**Note:** Version bump only for package @availity/authorizations-core
### Bug Fixes
## [1.0.6](https://github.com/Availity/sdk-js/compare/@availity/authorizations-core@1.0.5...@availity/authorizations-core@1.0.6) (2020-01-03)
* **authorizations-core:** swap array.prototype.find for array.prototype.filter ([43b1b4a](https://github.com/Availity/sdk-js/commit/43b1b4a))
**Note:** Version bump only for package @availity/authorizations-core
## [1.0.5](https://github.com/Availity/sdk-js/compare/@availity/authorizations-core@1.0.4...@availity/authorizations-core@1.0.5) (2019-04-17)
**Note:** Version bump only for package @availity/authorizations-core
## [1.0.4](https://github.com/Availity/sdk-js/compare/@availity/authorizations-core@1.0.3...@availity/authorizations-core@1.0.4) (2019-03-18)
### Bug Fixes
- **authorizations-core:** swap array.prototype.find for array.prototype.filter ([43b1b4a](https://github.com/Availity/sdk-js/commit/43b1b4a))
## [1.0.3](https://github.com/Availity/sdk-js/compare/@availity/authorizations-core@1.0.2...@availity/authorizations-core@1.0.3) (2019-02-12)

@@ -49,84 +56,42 @@

## 1.0.2 (2019-02-12)
## 1.0.1 (2018-03-26)
# 1.0.0-alpha.17 (2018-01-18)
# 1.0.0-alpha.16 (2018-01-17)
# 1.0.0-alpha.15 (2018-01-12)
# 1.0.0-alpha.14 (2018-01-11)
# 1.0.0-alpha.13 (2018-01-10)
# 1.0.0-alpha.12 (2018-01-09)
# 1.0.0-alpha.11 (2018-01-06)
# 1.0.0-alpha.10 (2018-01-04)
# 1.0.0-alpha.9 (2018-01-03)
# 1.0.0-alpha.8 (2018-01-03)
# 1.0.0-alpha.7 (2018-01-03)
# 1.0.0-alpha.6 (2017-12-20)
# 1.0.0-alpha.5 (2017-12-20)
# 1.0.0-alpha.4 (2017-12-20)
# 1.0.0-alpha.3 (2017-12-19)
# 1.0.0-alpha.2 (2017-12-19)
# 1.0.0-alpha.1 (2017-12-19)
# 1.0.0-alpha.0 (2017-12-05)
**Note:** Version bump only for package @availity/authorizations-core

@@ -1,10 +0,10 @@

"use strict";
import _classCallCheck from "/home/circleci/project/node_modules/@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "/home/circleci/project/node_modules/@babel/runtime/helpers/esm/createClass";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var AvAuthorizations =
/*#__PURE__*/
function () {
function AvAuthorizations(avPermissions, avRegions, promise) {
_classCallCheck(this, AvAuthorizations);
class AvAuthorizations {
constructor(avPermissions, avRegions, promise) {
// make sure all params are passed in

@@ -24,123 +24,170 @@ if (!avPermissions || !avRegions || !promise) {

isAuthorized(permissionId, region) {
return this.getPermission(permissionId, region).then(permission => permission.isAuthorized);
} // return true/false if any of ther permissions in array are authorized in this region
_createClass(AvAuthorizations, [{
key: "isAuthorized",
value: function isAuthorized(permissionId, region) {
return this.getPermission(permissionId, region).then(function (permission) {
return permission.isAuthorized;
});
} // return true/false if any of ther permissions in array are authorized in this region
}, {
key: "isAnyAuthorized",
value: function isAnyAuthorized(permissionIds, region) {
return this.getPermissions(permissionIds, region).then(function (permissions) {
return permissions.some(function (permission) {
return permission.isAuthorized;
});
});
} // gets the permission for this id in this region
isAnyAuthorized(permissionIds, region) {
return this.getPermissions(permissionIds, region).then(permissions => permissions.some(permission => permission.isAuthorized));
} // gets the permission for this id in this region
}, {
key: "getPermission",
value: function getPermission(permissionId, region) {
if (typeof permissionId !== 'string') {
return this.promise.reject('permissionId must be a string');
}
return this.getPermissions([permissionId], region).then(function (permissions) {
return permissions.filter(function (permission) {
return permission.id === permissionId;
})[0];
});
} // if passed in region is undefined, use avRegions to get current region
getPermission(permissionId, region) {
if (typeof permissionId !== 'string') {
return this.promise.reject('permissionId must be a string');
}
}, {
key: "getRegion",
value: function getRegion(region) {
if (region) {
return this.promise.resolve(region);
}
return this.getPermissions([permissionId], region).then(permissions => permissions.filter(permission => permission.id === permissionId)[0]);
} // if passed in region is undefined, use avRegions to get current region
return this.avRegions.getCurrentRegion().then(function (response) {
return response && response.data && response.data.regions && response.data.regions[0] && response.data.regions[0].id;
});
} // get all permissions in this region
}, {
key: "getPermissions",
value: function getPermissions(permissionIds, region) {
var _this = this;
getRegion(region) {
if (region) {
return this.promise.resolve(region);
}
// check permissionIds
var throwError = !Array.isArray(permissionIds);
return this.avRegions.getCurrentRegion().then(response => response && response.data && response.data.regions && response.data.regions[0] && response.data.regions[0].id);
} // get all permissions in this region
if (!throwError) {
throwError = permissionIds.some(function (id) {
return typeof id !== 'string';
});
}
if (throwError) {
return this.promise.reject('permissionIds must be an array of strings');
}
getPermissions(permissionIds, region) {
// check permissionIds
let throwError = !Array.isArray(permissionIds);
var useRegion;
var neededIds = []; // get the region to use
if (!throwError) {
throwError = permissionIds.some(id => typeof id !== 'string');
}
return this.getRegion(region).then(function (response) {
useRegion = response; // get ids still needed
if (throwError) {
return this.promise.reject('permissionIds must be an array of strings');
}
neededIds = _this.getMissingIds(permissionIds, useRegion);
let useRegion;
let neededIds = []; // get the region to use
if (neededIds && neededIds.length > 0) {
return _this.avPermissions.getPermissions(neededIds, useRegion);
}
return this.getRegion(region).then(response => {
useRegion = response; // get ids still needed
return _this.promise.resolve([]);
}).then(function (permissions) {
// add new permissions to the map
_this.addPermissions(neededIds, permissions, useRegion); // return the final results from the map
neededIds = this.getMissingIds(permissionIds, useRegion);
if (neededIds && neededIds.length > 0) {
return this.avPermissions.getPermissions(neededIds, useRegion);
}
return _this.getFromMap(permissionIds, useRegion);
});
} // return ids that are not already in the map
return this.promise.resolve([]);
}).then(permissions => {
// add new permissions to the map
this.addPermissions(neededIds, permissions, useRegion); // return the final results from the map
}, {
key: "getMissingIds",
value: function getMissingIds(ids) {
var _this2 = this;
return this.getFromMap(permissionIds, useRegion);
});
} // return ids that are not already in the map
var region = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'default';
return ids.reduce(function (output, id) {
if (!_this2.authorizedMap[id] || !_this2.authorizedMap[id][region]) {
output.push(id);
}
return output;
}, []);
} // grab ids from map with region
getMissingIds(ids, region = 'default') {
return ids.reduce((output, id) => {
if (!this.authorizedMap[id] || !this.authorizedMap[id][region]) {
output.push(id);
}
}, {
key: "getFromMap",
value: function getFromMap(ids) {
var _this3 = this;
return output;
}, []);
} // grab ids from map with region
var region = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'default';
return ids.reduce(function (output, id) {
if (_this3.authorizedMap[id] && _this3.authorizedMap[id][region]) {
output.push(_this3.authorizedMap[id][region]);
}
return output;
}, []);
} // add all ids permission object to map
getFromMap(ids, region = 'default') {
return ids.reduce((output, id) => {
if (this.authorizedMap[id] && this.authorizedMap[id][region]) {
output.push(this.authorizedMap[id][region]);
}
}, {
key: "addPermissions",
value: function addPermissions(ids, permissions, region) {
var _this4 = this;
return output;
}, []);
} // add all ids permission object to map
ids.forEach(function (id) {
var permission = permissions.filter(function (val) {
return val.id === id;
})[0];
_this4.addPermission(permission || {
id: id
}, region);
});
} // add this permission to map
addPermissions(ids, permissions, region) {
ids.forEach(id => {
const permission = permissions.filter(val => val.id === id)[0];
this.addPermission(permission || {
id: id
}, region);
});
} // add this permission to map
}, {
key: "addPermission",
value: function addPermission(permission) {
var region = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'default';
if (!permission.id) {
return;
}
addPermission(permission, region = 'default') {
if (!permission.id) {
return;
this.authorizedMap[permission.id] = this.authorizedMap[permission.id] || {}; // set default values
permission.geographies = permission.geographies || [];
permission.organizations = permission.organizations || [];
permission.isAuthorized = !!(permission.organizations.length && permission.organizations.length > 0);
this.authorizedMap[permission.id][region] = permission;
}
}, {
key: "getOrganizations",
value: function getOrganizations(permissionId, region) {
return this.getPermission(permissionId, region).then(function (permission) {
return permission.organizations;
});
}
}, {
key: "getPayers",
value: function getPayers(permissionId, organizationId, region) {
return this.getPermission(permissionId, region).then(function (permission) {
var organization = permission.organizations.filter(function (org) {
return org.id === organizationId;
})[0];
return organization && organization.resources || [];
});
}
}]);
this.authorizedMap[permission.id] = this.authorizedMap[permission.id] || {}; // set default values
return AvAuthorizations;
}();
permission.geographies = permission.geographies || [];
permission.organizations = permission.organizations || [];
permission.isAuthorized = !!(permission.organizations.length && permission.organizations.length > 0);
this.authorizedMap[permission.id][region] = permission;
}
getOrganizations(permissionId, region) {
return this.getPermission(permissionId, region).then(permission => permission.organizations);
}
getPayers(permissionId, organizationId, region) {
return this.getPermission(permissionId, region).then(permission => {
const organization = permission.organizations.filter(org => org.id === organizationId)[0];
return organization && organization.resources || [];
});
}
}
var _default = AvAuthorizations;
exports.default = _default;
export default AvAuthorizations;

@@ -1,24 +0,21 @@

"use strict";
import _regeneratorRuntime from "/home/circleci/project/node_modules/@babel/runtime/regenerator";
import _asyncToGenerator from "/home/circleci/project/node_modules/@babel/runtime/helpers/esm/asyncToGenerator";
import AvAuthorizations from '..';
expect.extend({
toBeAuthorized: function toBeAuthorized(permissions, ids) {
var _this = this;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var permissionArray = Array.isArray(permissions);
var idsArray = Array.isArray(ids); // make sure both args are arrays
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
var isPass = permissionArray && idsArray;
var _ = _interopRequireDefault(require(".."));
expect.extend({
toBeAuthorized: function (permissions, ids) {
const permissionArray = Array.isArray(permissions);
const idsArray = Array.isArray(ids); // make sure both args are arrays
let isPass = permissionArray && idsArray;
if (!isPass) {
return {
pass: this.isNot,
message: () => {
let output = 'recieved ';
message: function message() {
var output = 'recieved ';
if (idsArray) {
output += `ids (${this.utils.printExpected(ids)})`;
output += "ids (".concat(_this.utils.printExpected(ids), ")");
}

@@ -31,3 +28,3 @@

if (permissionArray) {
output += `permissions (${this.utils.printReceived(permissions)})`;
output += "permissions (".concat(_this.utils.printReceived(permissions), ")");
}

@@ -45,9 +42,13 @@

isPass = ids.every(id => {
const permission = permissions.find(val => val.id === id);
return permission && permission.isAuthorized === !this.isNot;
isPass = ids.every(function (id) {
var permission = permissions.find(function (val) {
return val.id === id;
});
return permission && permission.isAuthorized === !_this.isNot;
});
return {
pass: isPass ? !this.isNot : this.isNot,
message: () => `expected ids (${this.utils.printExpected(ids)}) to ${this.isNot ? ' not ' : ''} have isAuthorized in permissions (${this.utils.printReceived(permissions)})`
message: function message() {
return "expected ids (".concat(_this.utils.printExpected(ids), ") to ").concat(_this.isNot ? ' not ' : '', " have isAuthorized in permissions (").concat(_this.utils.printReceived(permissions), ")");
}
};

@@ -58,20 +59,24 @@ }

function authorizedMockPermissions(permissionIds) {
return permissionIds.map(id => ({
id: id,
organizations: [{
id: 'testOrg',
resources: 'testResources'
}]
}));
return permissionIds.map(function (id) {
return {
id: id,
organizations: [{
id: 'testOrg',
resources: 'testResources'
}]
};
});
}
function unauthorizedMockPermissions(permissionIds) {
return permissionIds.map(id => ({
id: id
}));
return permissionIds.map(function (id) {
return {
id: id
};
});
}
function getMockPermissionValues(permissionIds, isAuthorized) {
return permissionIds.map(id => {
const output = {
return permissionIds.map(function (id) {
var output = {
id: id,

@@ -94,57 +99,59 @@ isAuthorized: isAuthorized,

const mockPermissions = {
var mockPermissions = {
getPermissions: jest.fn(authorizedMockPermissions)
};
const mockRegion = 'FL';
const mockRegions = {
getCurrentRegion: jest.fn(() => Promise.resolve({
data: {
regions: [{
id: mockRegion
}]
}
}))
var mockRegion = 'FL';
var mockRegions = {
getCurrentRegion: jest.fn(function () {
return Promise.resolve({
data: {
regions: [{
id: mockRegion
}]
}
});
})
};
describe('AvAuthorizations', () => {
let testAuthorizations;
beforeEach(() => {
testAuthorizations = new _.default(mockPermissions, mockRegions, Promise);
describe('AvAuthorizations', function () {
var testAuthorizations;
beforeEach(function () {
testAuthorizations = new AvAuthorizations(mockPermissions, mockRegions, Promise);
});
test('AvAuthorizations is defined', () => {
test('AvAuthorizations is defined', function () {
expect(testAuthorizations).toBeDefined();
});
test('AvAuthorizations throws error when constructed without all params', () => {
expect(() => {
testAuthorizations = new _.default();
test('AvAuthorizations throws error when constructed without all params', function () {
expect(function () {
testAuthorizations = new AvAuthorizations();
}).toThrow('A permission, region, and promise are required');
});
describe('Add permissions to map', () => {
test('permission should be added to map in default region', () => {
const testPermission = {
describe('Add permissions to map', function () {
test('permission should be added to map in default region', function () {
var testPermission = {
id: 'testId'
};
testAuthorizations.addPermission(testPermission);
expect(testAuthorizations.authorizedMap[testPermission.id].default.id).toBe(testPermission.id);
expect(testAuthorizations.authorizedMap[testPermission.id]["default"].id).toBe(testPermission.id);
});
test('permission should be given default geographies and organizations values', () => {
const testPermission = {
test('permission should be given default geographies and organizations values', function () {
var testPermission = {
id: 'testId'
};
testAuthorizations.addPermission(testPermission);
const authorizedMapVal = testAuthorizations.authorizedMap[testPermission.id];
expect(authorizedMapVal.default.id).toBe(testPermission.id);
expect(authorizedMapVal.default.geographies).toEqual([]);
expect(authorizedMapVal.default.organizations).toEqual([]);
var authorizedMapVal = testAuthorizations.authorizedMap[testPermission.id];
expect(authorizedMapVal["default"].id).toBe(testPermission.id);
expect(authorizedMapVal["default"].geographies).toEqual([]);
expect(authorizedMapVal["default"].organizations).toEqual([]);
});
test('permission should not be authorized without any organization', () => {
const testPermission = {
test('permission should not be authorized without any organization', function () {
var testPermission = {
id: 'testId'
};
testAuthorizations.addPermission(testPermission);
const authorizedMapVal = testAuthorizations.authorizedMap[testPermission.id];
expect(authorizedMapVal.default.id).toBe(testPermission.id);
expect(authorizedMapVal.default.isAuthorized).toBeFalsy();
var authorizedMapVal = testAuthorizations.authorizedMap[testPermission.id];
expect(authorizedMapVal["default"].id).toBe(testPermission.id);
expect(authorizedMapVal["default"].isAuthorized).toBeFalsy();
});
test('permission should be authorized when it has organizations', () => {
const testPermission = {
test('permission should be authorized when it has organizations', function () {
var testPermission = {
id: 'testId',

@@ -154,13 +161,13 @@ organizations: ['someOrganization']

testAuthorizations.addPermission(testPermission);
const authorizedMapVal = testAuthorizations.authorizedMap[testPermission.id];
expect(authorizedMapVal.default.id).toBe(testPermission.id);
expect(authorizedMapVal.default.isAuthorized).toBeTruthy();
var authorizedMapVal = testAuthorizations.authorizedMap[testPermission.id];
expect(authorizedMapVal["default"].id).toBe(testPermission.id);
expect(authorizedMapVal["default"].isAuthorized).toBeTruthy();
});
test('permission should be stored by region when one is provided', () => {
const testId = 'testId';
const testPermissionFl = {
test('permission should be stored by region when one is provided', function () {
var testId = 'testId';
var testPermissionFl = {
id: testId,
geographies: ['FL']
};
const testPermissionGa = {
var testPermissionGa = {
id: testId,

@@ -176,3 +183,3 @@ geographies: ['GA']

});
test('should do nothing when permission has no id', () => {
test('should do nothing when permission has no id', function () {
testAuthorizations.addPermission({});

@@ -182,50 +189,62 @@ expect(testAuthorizations.authorizedMap).toEqual({});

});
test('getRegion should return given region', () => {
test('getRegion should return given region',
/*#__PURE__*/
_asyncToGenerator(
/*#__PURE__*/
_regeneratorRuntime.mark(function _callee() {
var testRegion, region;
return _regenerator.default.async(function _callee$(_context) {
while (1) switch (_context.prev = _context.next) {
case 0:
testRegion = 'GA';
_context.next = 3;
return _regenerator.default.awrap(testAuthorizations.getRegion(testRegion));
return _regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
testRegion = 'GA';
_context.next = 3;
return testAuthorizations.getRegion(testRegion);
case 3:
region = _context.sent;
expect(region).toBe(testRegion);
case 3:
region = _context.sent;
expect(region).toBe(testRegion);
case 5:
case "end":
return _context.stop();
case 5:
case "end":
return _context.stop();
}
}
});
});
test('getRegion should use region api when no region is given', () => {
}, _callee);
})));
test('getRegion should use region api when no region is given',
/*#__PURE__*/
_asyncToGenerator(
/*#__PURE__*/
_regeneratorRuntime.mark(function _callee2() {
var region;
return _regenerator.default.async(function _callee2$(_context2) {
while (1) switch (_context2.prev = _context2.next) {
case 0:
_context2.next = 2;
return _regenerator.default.awrap(testAuthorizations.getRegion());
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
_context2.next = 2;
return testAuthorizations.getRegion();
case 2:
region = _context2.sent;
expect(mockRegions.getCurrentRegion).toHaveBeenCalled();
expect(region).toBe(mockRegion);
case 2:
region = _context2.sent;
expect(mockRegions.getCurrentRegion).toHaveBeenCalled();
expect(region).toBe(mockRegion);
case 5:
case "end":
return _context2.stop();
case 5:
case "end":
return _context2.stop();
}
}
});
});
test('addPermissions adds each id to map', () => {
const testId = 'testId';
const ids = [testId];
const permissions = [];
}, _callee2);
})));
test('addPermissions adds each id to map', function () {
var testId = 'testId';
var ids = [testId];
var permissions = [];
testAuthorizations.addPermissions(ids, permissions);
expect(testAuthorizations.authorizedMap[testId].default.id).toBe(testId);
expect(testAuthorizations.authorizedMap[testId]["default"].id).toBe(testId);
});
test('addPermissions adds each id from permissions to map', () => {
const ids = ['testId'];
const permissions = [{
test('addPermissions adds each id from permissions to map', function () {
var ids = ['testId'];
var permissions = [{
id: 'testId',

@@ -235,17 +254,17 @@ testKey: 'testValue'

testAuthorizations.addPermissions(ids, permissions);
expect(testAuthorizations.authorizedMap[ids[0]].default).toEqual(permissions[0]);
expect(testAuthorizations.authorizedMap[ids[0]]["default"]).toEqual(permissions[0]);
});
test('getMissingIds should return ids of permissions not in map', () => {
const allIds = ['123', '456', '789'];
const addedIds = ['789'];
const testIds = ['123', '456'];
test('getMissingIds should return ids of permissions not in map', function () {
var allIds = ['123', '456', '789'];
var addedIds = ['789'];
var testIds = ['123', '456'];
testAuthorizations.addPermissions(addedIds, []);
expect(testAuthorizations.getMissingIds(allIds)).toEqual(testIds);
});
test('getMissingIds should return ids of permissions not in map accounting for region', () => {
const allIds = ['123', '456', '789'];
const addedIds = ['789'];
const testIds = ['123', '456'];
const region1 = 'FL';
const region2 = 'GA';
test('getMissingIds should return ids of permissions not in map accounting for region', function () {
var allIds = ['123', '456', '789'];
var addedIds = ['789'];
var testIds = ['123', '456'];
var region1 = 'FL';
var region2 = 'GA';
testAuthorizations.addPermissions(allIds, [], region1);

@@ -255,13 +274,13 @@ testAuthorizations.addPermissions(addedIds, [], region2);

});
test('getFromMap should return permissions with ids in map', () => {
const allIds = ['123', '456', '789'];
const addedIds = ['789'];
test('getFromMap should return permissions with ids in map', function () {
var allIds = ['123', '456', '789'];
var addedIds = ['789'];
testAuthorizations.addPermissions(addedIds, []);
expect(testAuthorizations.getFromMap(allIds)).toEqual(getMockPermissionValues(addedIds, false));
});
test('getFromMap should return permissions with ids in map based on region', () => {
const allIds = ['123', '456', '789'];
const addedIds = ['789'];
const region1 = 'FL';
const region2 = 'GA';
test('getFromMap should return permissions with ids in map based on region', function () {
var allIds = ['123', '456', '789'];
var addedIds = ['789'];
var region1 = 'FL';
var region2 = 'GA';
testAuthorizations.addPermissions(allIds, [], region1);

@@ -271,302 +290,374 @@ testAuthorizations.addPermissions(addedIds, [], region2);

});
describe('Get Permissions', () => {
test('Get permissions should call permission api', () => {
describe('Get Permissions', function () {
test('Get permissions should call permission api',
/*#__PURE__*/
_asyncToGenerator(
/*#__PURE__*/
_regeneratorRuntime.mark(function _callee3() {
var testIds;
return _regenerator.default.async(function _callee3$(_context3) {
while (1) switch (_context3.prev = _context3.next) {
case 0:
testIds = ['123', '456'];
_context3.next = 3;
return _regenerator.default.awrap(testAuthorizations.getPermissions(testIds));
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
while (1) {
switch (_context3.prev = _context3.next) {
case 0:
testIds = ['123', '456'];
_context3.next = 3;
return testAuthorizations.getPermissions(testIds);
case 3:
expect(mockPermissions.getPermissions).toHaveBeenCalled();
case 3:
expect(mockPermissions.getPermissions).toHaveBeenCalled();
case 4:
case "end":
return _context3.stop();
case 4:
case "end":
return _context3.stop();
}
}
});
});
test('should return requested permissions with isAuthorized flag set', () => {
}, _callee3);
})));
test('should return requested permissions with isAuthorized flag set',
/*#__PURE__*/
_asyncToGenerator(
/*#__PURE__*/
_regeneratorRuntime.mark(function _callee4() {
var testIds, permissions;
return _regenerator.default.async(function _callee4$(_context4) {
while (1) switch (_context4.prev = _context4.next) {
case 0:
testIds = ['123', '456'];
_context4.next = 3;
return _regenerator.default.awrap(testAuthorizations.getPermissions(testIds));
return _regeneratorRuntime.wrap(function _callee4$(_context4) {
while (1) {
switch (_context4.prev = _context4.next) {
case 0:
testIds = ['123', '456'];
_context4.next = 3;
return testAuthorizations.getPermissions(testIds);
case 3:
permissions = _context4.sent;
expect(permissions).toBeAuthorized(testIds);
expect(permissions).toEqual(getMockPermissionValues(testIds, true));
case 3:
permissions = _context4.sent;
expect(permissions).toBeAuthorized(testIds);
expect(permissions).toEqual(getMockPermissionValues(testIds, true));
case 6:
case "end":
return _context4.stop();
case 6:
case "end":
return _context4.stop();
}
}
});
});
test('should reject when a non-array is passed in', () => {
}, _callee4);
})));
test('should reject when a non-array is passed in',
/*#__PURE__*/
_asyncToGenerator(
/*#__PURE__*/
_regeneratorRuntime.mark(function _callee5() {
var testIds;
return _regenerator.default.async(function _callee5$(_context5) {
while (1) switch (_context5.prev = _context5.next) {
case 0:
testIds = '123';
_context5.prev = 1;
_context5.next = 4;
return _regenerator.default.awrap(testAuthorizations.getPermissions(testIds));
return _regeneratorRuntime.wrap(function _callee5$(_context5) {
while (1) {
switch (_context5.prev = _context5.next) {
case 0:
testIds = '123';
_context5.prev = 1;
_context5.next = 4;
return testAuthorizations.getPermissions(testIds);
case 4:
_context5.next = 9;
break;
case 4:
_context5.next = 9;
break;
case 6:
_context5.prev = 6;
_context5.t0 = _context5["catch"](1);
expect(_context5.t0).toBe('permissionIds must be an array of strings');
case 6:
_context5.prev = 6;
_context5.t0 = _context5["catch"](1);
expect(_context5.t0).toBe('permissionIds must be an array of strings');
case 9:
case "end":
return _context5.stop();
case 9:
case "end":
return _context5.stop();
}
}
}, null, null, [[1, 6]]);
});
test('should reject when passed in array is not all strings', () => {
}, _callee5, null, [[1, 6]]);
})));
test('should reject when passed in array is not all strings',
/*#__PURE__*/
_asyncToGenerator(
/*#__PURE__*/
_regeneratorRuntime.mark(function _callee6() {
var testIds;
return _regenerator.default.async(function _callee6$(_context6) {
while (1) switch (_context6.prev = _context6.next) {
case 0:
testIds = ['123', 456];
_context6.prev = 1;
_context6.next = 4;
return _regenerator.default.awrap(testAuthorizations.getPermissions(testIds));
return _regeneratorRuntime.wrap(function _callee6$(_context6) {
while (1) {
switch (_context6.prev = _context6.next) {
case 0:
testIds = ['123', 456];
_context6.prev = 1;
_context6.next = 4;
return testAuthorizations.getPermissions(testIds);
case 4:
_context6.next = 9;
break;
case 4:
_context6.next = 9;
break;
case 6:
_context6.prev = 6;
_context6.t0 = _context6["catch"](1);
expect(_context6.t0).toBe('permissionIds must be an array of strings');
case 6:
_context6.prev = 6;
_context6.t0 = _context6["catch"](1);
expect(_context6.t0).toBe('permissionIds must be an array of strings');
case 9:
case "end":
return _context6.stop();
case 9:
case "end":
return _context6.stop();
}
}
}, null, null, [[1, 6]]);
});
}, _callee6, null, [[1, 6]]);
})));
});
test('getPermission should return single requested permission', () => {
test('getPermission should return single requested permission',
/*#__PURE__*/
_asyncToGenerator(
/*#__PURE__*/
_regeneratorRuntime.mark(function _callee7() {
var testId, testRegion, permission;
return _regenerator.default.async(function _callee7$(_context7) {
while (1) switch (_context7.prev = _context7.next) {
case 0:
testId = '123';
testRegion = 'GA';
_context7.next = 4;
return _regenerator.default.awrap(testAuthorizations.getPermission(testId, testRegion));
case 4:
permission = _context7.sent;
expect(mockPermissions.getPermissions).toHaveBeenLastCalledWith([testId], testRegion);
expect(permission).toEqual(getMockPermissionValues([testId], true)[0]);
case 7:
case "end":
return _context7.stop();
}
});
});
test('getPermission should reject when a non-string is passed in', () => {
const testId = 123;
return testAuthorizations.getPermission(testId).catch(error => {
expect(error).toBe('permissionId must be a string');
});
});
describe('Authorized', () => {
test('should return true for authorized permission', () => {
var testId, testRegion, isAuthorized;
return _regenerator.default.async(function _callee8$(_context8) {
while (1) switch (_context8.prev = _context8.next) {
return _regeneratorRuntime.wrap(function _callee7$(_context7) {
while (1) {
switch (_context7.prev = _context7.next) {
case 0:
testId = '123';
testRegion = 'GA';
_context8.next = 4;
return _regenerator.default.awrap(testAuthorizations.isAuthorized(testId, testRegion));
_context7.next = 4;
return testAuthorizations.getPermission(testId, testRegion);
case 4:
isAuthorized = _context8.sent;
permission = _context7.sent;
expect(mockPermissions.getPermissions).toHaveBeenLastCalledWith([testId], testRegion);
expect(isAuthorized).toBeTruthy();
expect(permission).toEqual(getMockPermissionValues([testId], true)[0]);
case 7:
case "end":
return _context8.stop();
return _context7.stop();
}
});
}
}, _callee7);
})));
test('getPermission should reject when a non-string is passed in', function () {
var testId = 123;
return testAuthorizations.getPermission(testId)["catch"](function (error) {
expect(error).toBe('permissionId must be a string');
});
test('should return false for unauthorized permission', () => {
});
describe('Authorized', function () {
test('should return true for authorized permission',
/*#__PURE__*/
_asyncToGenerator(
/*#__PURE__*/
_regeneratorRuntime.mark(function _callee8() {
var testId, testRegion, isAuthorized;
return _regenerator.default.async(function _callee9$(_context9) {
while (1) switch (_context9.prev = _context9.next) {
case 0:
testId = '123';
testRegion = 'GA';
mockPermissions.getPermissions.mockImplementationOnce(unauthorizedMockPermissions);
_context9.next = 5;
return _regenerator.default.awrap(testAuthorizations.isAuthorized(testId, testRegion));
return _regeneratorRuntime.wrap(function _callee8$(_context8) {
while (1) {
switch (_context8.prev = _context8.next) {
case 0:
testId = '123';
testRegion = 'GA';
_context8.next = 4;
return testAuthorizations.isAuthorized(testId, testRegion);
case 5:
isAuthorized = _context9.sent;
expect(mockPermissions.getPermissions).toHaveBeenLastCalledWith([testId], testRegion);
expect(isAuthorized).toBeFalsy();
case 4:
isAuthorized = _context8.sent;
expect(mockPermissions.getPermissions).toHaveBeenLastCalledWith([testId], testRegion);
expect(isAuthorized).toBeTruthy();
case 8:
case "end":
return _context9.stop();
case 7:
case "end":
return _context8.stop();
}
}
});
});
test('isAnyAuthorized should return true when all permissions are authorized', () => {
}, _callee8);
})));
test('should return false for unauthorized permission',
/*#__PURE__*/
_asyncToGenerator(
/*#__PURE__*/
_regeneratorRuntime.mark(function _callee9() {
var testId, testRegion, isAuthorized;
return _regeneratorRuntime.wrap(function _callee9$(_context9) {
while (1) {
switch (_context9.prev = _context9.next) {
case 0:
testId = '123';
testRegion = 'GA';
mockPermissions.getPermissions.mockImplementationOnce(unauthorizedMockPermissions);
_context9.next = 5;
return testAuthorizations.isAuthorized(testId, testRegion);
case 5:
isAuthorized = _context9.sent;
expect(mockPermissions.getPermissions).toHaveBeenLastCalledWith([testId], testRegion);
expect(isAuthorized).toBeFalsy();
case 8:
case "end":
return _context9.stop();
}
}
}, _callee9);
})));
test('isAnyAuthorized should return true when all permissions are authorized',
/*#__PURE__*/
_asyncToGenerator(
/*#__PURE__*/
_regeneratorRuntime.mark(function _callee10() {
var testIds, testRegion, isAuthorized;
return _regenerator.default.async(function _callee10$(_context10) {
while (1) switch (_context10.prev = _context10.next) {
case 0:
testIds = ['123', '456'];
testRegion = 'GA';
_context10.next = 4;
return _regenerator.default.awrap(testAuthorizations.isAnyAuthorized(testIds, testRegion));
return _regeneratorRuntime.wrap(function _callee10$(_context10) {
while (1) {
switch (_context10.prev = _context10.next) {
case 0:
testIds = ['123', '456'];
testRegion = 'GA';
_context10.next = 4;
return testAuthorizations.isAnyAuthorized(testIds, testRegion);
case 4:
isAuthorized = _context10.sent;
expect(mockPermissions.getPermissions).toHaveBeenLastCalledWith(testIds, testRegion);
expect(isAuthorized).toBeTruthy();
case 4:
isAuthorized = _context10.sent;
expect(mockPermissions.getPermissions).toHaveBeenLastCalledWith(testIds, testRegion);
expect(isAuthorized).toBeTruthy();
case 7:
case "end":
return _context10.stop();
case 7:
case "end":
return _context10.stop();
}
}
});
});
test('isAnyAuthorized should return true when some permissions are authorized', () => {
}, _callee10);
})));
test('isAnyAuthorized should return true when some permissions are authorized',
/*#__PURE__*/
_asyncToGenerator(
/*#__PURE__*/
_regeneratorRuntime.mark(function _callee11() {
var testIdsFalse, testIdsTrue, testIdsTotal, testRegion, isAuthorized;
return _regenerator.default.async(function _callee11$(_context11) {
while (1) switch (_context11.prev = _context11.next) {
case 0:
testIdsFalse = ['123', '456'];
testIdsTrue = ['789'];
testIdsTotal = ['123', '456', '789'];
testRegion = 'GA';
mockPermissions.getPermissions.mockImplementationOnce(unauthorizedMockPermissions);
_context11.next = 7;
return _regenerator.default.awrap(testAuthorizations.getPermissions(testIdsFalse, testRegion));
return _regeneratorRuntime.wrap(function _callee11$(_context11) {
while (1) {
switch (_context11.prev = _context11.next) {
case 0:
testIdsFalse = ['123', '456'];
testIdsTrue = ['789'];
testIdsTotal = ['123', '456', '789'];
testRegion = 'GA';
mockPermissions.getPermissions.mockImplementationOnce(unauthorizedMockPermissions);
_context11.next = 7;
return testAuthorizations.getPermissions(testIdsFalse, testRegion);
case 7:
expect(mockPermissions.getPermissions).toHaveBeenLastCalledWith(testIdsFalse, testRegion);
_context11.next = 10;
return _regenerator.default.awrap(testAuthorizations.getPermissions(testIdsTrue, testRegion));
case 7:
expect(mockPermissions.getPermissions).toHaveBeenLastCalledWith(testIdsFalse, testRegion);
_context11.next = 10;
return testAuthorizations.getPermissions(testIdsTrue, testRegion);
case 10:
expect(mockPermissions.getPermissions).toHaveBeenLastCalledWith(testIdsTrue, testRegion);
_context11.next = 13;
return _regenerator.default.awrap(testAuthorizations.isAnyAuthorized(testIdsTotal, testRegion));
case 10:
expect(mockPermissions.getPermissions).toHaveBeenLastCalledWith(testIdsTrue, testRegion);
_context11.next = 13;
return testAuthorizations.isAnyAuthorized(testIdsTotal, testRegion);
case 13:
isAuthorized = _context11.sent;
expect(isAuthorized).toBeTruthy();
case 13:
isAuthorized = _context11.sent;
expect(isAuthorized).toBeTruthy();
case 15:
case "end":
return _context11.stop();
case 15:
case "end":
return _context11.stop();
}
}
});
});
test('isAnyAuthorized should return false when none permissions are authorized', () => {
}, _callee11);
})));
test('isAnyAuthorized should return false when none permissions are authorized',
/*#__PURE__*/
_asyncToGenerator(
/*#__PURE__*/
_regeneratorRuntime.mark(function _callee12() {
var testIds, testRegion, isAuthorized;
return _regenerator.default.async(function _callee12$(_context12) {
while (1) switch (_context12.prev = _context12.next) {
case 0:
testIds = ['123', '456'];
testRegion = 'GA';
mockPermissions.getPermissions.mockImplementationOnce(unauthorizedMockPermissions);
_context12.next = 5;
return _regenerator.default.awrap(testAuthorizations.isAnyAuthorized(testIds, testRegion));
return _regeneratorRuntime.wrap(function _callee12$(_context12) {
while (1) {
switch (_context12.prev = _context12.next) {
case 0:
testIds = ['123', '456'];
testRegion = 'GA';
mockPermissions.getPermissions.mockImplementationOnce(unauthorizedMockPermissions);
_context12.next = 5;
return testAuthorizations.isAnyAuthorized(testIds, testRegion);
case 5:
isAuthorized = _context12.sent;
expect(mockPermissions.getPermissions).toHaveBeenLastCalledWith(testIds, testRegion);
expect(isAuthorized).toBeFalsy();
case 5:
isAuthorized = _context12.sent;
expect(mockPermissions.getPermissions).toHaveBeenLastCalledWith(testIds, testRegion);
expect(isAuthorized).toBeFalsy();
case 8:
case "end":
return _context12.stop();
case 8:
case "end":
return _context12.stop();
}
}
});
});
}, _callee12);
})));
});
test('getOrganizations should return organizations for permission', () => {
test('getOrganizations should return organizations for permission',
/*#__PURE__*/
_asyncToGenerator(
/*#__PURE__*/
_regeneratorRuntime.mark(function _callee13() {
var testId, testId2, testRegion, orgs;
return _regenerator.default.async(function _callee13$(_context13) {
while (1) switch (_context13.prev = _context13.next) {
case 0:
testId = '123';
testId2 = '456';
testRegion = 'GA';
_context13.next = 5;
return _regenerator.default.awrap(testAuthorizations.getOrganizations(testId, testRegion));
return _regeneratorRuntime.wrap(function _callee13$(_context13) {
while (1) {
switch (_context13.prev = _context13.next) {
case 0:
testId = '123';
testId2 = '456';
testRegion = 'GA';
_context13.next = 5;
return testAuthorizations.getOrganizations(testId, testRegion);
case 5:
orgs = _context13.sent;
expect(mockPermissions.getPermissions).toHaveBeenLastCalledWith([testId], testRegion);
expect(orgs).toEqual(getMockPermissionValues([testId], true)[0].organizations);
mockPermissions.getPermissions.mockImplementationOnce(unauthorizedMockPermissions);
_context13.next = 11;
return _regenerator.default.awrap(testAuthorizations.getOrganizations(testId2, testRegion));
case 5:
orgs = _context13.sent;
expect(mockPermissions.getPermissions).toHaveBeenLastCalledWith([testId], testRegion);
expect(orgs).toEqual(getMockPermissionValues([testId], true)[0].organizations);
mockPermissions.getPermissions.mockImplementationOnce(unauthorizedMockPermissions);
_context13.next = 11;
return testAuthorizations.getOrganizations(testId2, testRegion);
case 11:
orgs = _context13.sent;
expect(mockPermissions.getPermissions).toHaveBeenLastCalledWith([testId2], testRegion);
expect(orgs).toEqual(getMockPermissionValues([testId], false)[0].organizations);
case 11:
orgs = _context13.sent;
expect(mockPermissions.getPermissions).toHaveBeenLastCalledWith([testId2], testRegion);
expect(orgs).toEqual(getMockPermissionValues([testId], false)[0].organizations);
case 14:
case "end":
return _context13.stop();
case 14:
case "end":
return _context13.stop();
}
}
});
});
test('getPayers should return payers from permission with orgId', () => {
}, _callee13);
})));
test('getPayers should return payers from permission with orgId',
/*#__PURE__*/
_asyncToGenerator(
/*#__PURE__*/
_regeneratorRuntime.mark(function _callee14() {
var testId, testId2, orgId, testResource, testRegion, payers;
return _regenerator.default.async(function _callee14$(_context14) {
while (1) switch (_context14.prev = _context14.next) {
case 0:
testId = '123';
testId2 = '456';
orgId = 'testOrg';
testResource = 'testResources';
testRegion = 'GA';
_context14.next = 7;
return _regenerator.default.awrap(testAuthorizations.getPayers(testId, orgId, testRegion));
return _regeneratorRuntime.wrap(function _callee14$(_context14) {
while (1) {
switch (_context14.prev = _context14.next) {
case 0:
testId = '123';
testId2 = '456';
orgId = 'testOrg';
testResource = 'testResources';
testRegion = 'GA';
_context14.next = 7;
return testAuthorizations.getPayers(testId, orgId, testRegion);
case 7:
payers = _context14.sent;
expect(mockPermissions.getPermissions).toHaveBeenLastCalledWith([testId], testRegion);
expect(payers).toEqual(testResource);
mockPermissions.getPermissions.mockImplementationOnce(unauthorizedMockPermissions);
_context14.next = 13;
return _regenerator.default.awrap(testAuthorizations.getPayers(testId2, orgId, testRegion));
case 7:
payers = _context14.sent;
expect(mockPermissions.getPermissions).toHaveBeenLastCalledWith([testId], testRegion);
expect(payers).toEqual(testResource);
mockPermissions.getPermissions.mockImplementationOnce(unauthorizedMockPermissions);
_context14.next = 13;
return testAuthorizations.getPayers(testId2, orgId, testRegion);
case 13:
payers = _context14.sent;
expect(mockPermissions.getPermissions).toHaveBeenLastCalledWith([testId2], testRegion);
expect(payers).toEqual([]);
case 13:
payers = _context14.sent;
expect(mockPermissions.getPermissions).toHaveBeenLastCalledWith([testId2], testRegion);
expect(payers).toEqual([]);
case 16:
case "end":
return _context14.stop();
case 16:
case "end":
return _context14.stop();
}
}
});
});
}, _callee14);
})));
});
{
"name": "@availity/authorizations-core",
"version": "1.0.7",
"version": "1.0.10",
"description": "Base configurations for Availity Authorizations",

@@ -12,3 +12,3 @@ "main": "lib/index.js",

},
"gitHead": "58e503379e5371c8552cb0c9747c10945b7b20a4"
"gitHead": "88c0e7b48de05f599a97ad3547f8b96c63e2004e"
}

@@ -7,2 +7,16 @@ # Authorizations Core

## Install
### NPM
```bash
$ npm install @availity/authorizations-core
```
### Yarn
```bash
$ yarn add @availity/authorizations-core
```
## [Documentation](https://availity.github.io/sdk-js/api/authorizations)
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