Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@smarterservices/iam-react-client

Package Overview
Dependencies
Maintainers
3
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@smarterservices/iam-react-client - npm Package Compare versions

Comparing version 0.0.4 to 1.0.0

39

index.js

@@ -7,2 +7,6 @@ 'use strict';

var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

@@ -18,10 +22,2 @@

var _lodash = require('lodash');
var _lodash2 = _interopRequireDefault(_lodash);
var _reactChildrenUtilities = require('react-children-utilities');
var _reactChildrenUtilities2 = _interopRequireDefault(_reactChildrenUtilities);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -46,9 +42,28 @@

_createClass(Validate, [{
key: 'deepMap',
value: function deepMap(children, deepMapFn) {
var _this2 = this;
return _react.Children.map(children, function (child) {
if (child) {
if (child.props && child.props.children && _typeof(child.props.children) === 'object') {
// Clone the child that has children and map them too
return deepMapFn((0, _react.cloneElement)(child, _extends({}, child.props, {
children: _this2.deepMap(child.props.children, deepMapFn)
})));
}
return deepMapFn(child);
} else {
return child;
}
});
}
}, {
key: 'render',
value: function render() {
var localIam = _lodash2.default.cloneDeep(config.iam);
var localIam = config.iam;
var children = null;
//if action and resource was tagged to validate then it is applyed to every child nested inside
if (this.props.iamAction && this.props.iamResource) {
if (this.props && this.props.iamAction && this.props.iamResource) {
//check auth based on the iam doc action and resource to decide if this child content should be displayed.

@@ -64,3 +79,3 @@ if (_openIam2.default.authorize(this.props.iamResource, this.props.iamAction, _openIam2.default.processIamData(localIam))) {

//else validate will loop its children recursively and look for action/resources tagged to any ui element
children = _reactChildrenUtilities2.default.deepMap(this.props.children, function (child) {
children = this.deepMap(this.props.children, function (child) {
//if this child has action and resource run auth against it

@@ -88,2 +103,2 @@ if (child.props && child.props.iamAction && child.props.iamResource) {

exports.default = ValidateConstructor;
exports.default = ValidateConstructor;

@@ -26,14 +26,14 @@ 'use strict';

var testIam = {
"Statement": [{
"Effect": "Allow",
"Action": ["CanRead"],
"Resource": ["ssrn:ss:iam:::account/100/assestmentgroup/*/customquestions"]
Statement: [{
Effect: 'Allow',
Action: ['CanRead'],
Resource: ['ssrn:ss:iam:::account/100/assestmentgroup/*/customquestions']
}, {
"Effect": "Allow",
"Action": ["CanUpdate", "CanDelete", "CanCreate"],
"Resource": "ssrn:ss:iam:::account/100/assestmentgroup/1/customquestions"
Effect: 'Allow',
Action: ['CanUpdate', 'CanDelete', 'CanCreate'],
Resource: 'ssrn:ss:iam:::account/100/assestmentgroup/1/customquestions'
}, {
"Effect": "Deny",
"Action": ["CanUpdate"],
"Resource": ["ssrn:ss:iam:::account/100/assestmentgroup/2/customquestions"]
Effect: 'Deny',
Action: ['CanUpdate'],
Resource: ['ssrn:ss:iam:::account/100/assestmentgroup/2/customquestions']
}]

@@ -66,3 +66,6 @@ };

'p',
{ iamAction: 'CanUpdate', iamResource: 'ssrn:ss:iam:::account/100/assestmentgroup/2/customquestions' },
{
iamAction: 'CanUpdate',
iamResource: 'ssrn:ss:iam:::account/100/assestmentgroup/2/customquestions'
},
'This is nested and should hide'

@@ -72,3 +75,6 @@ ),

'p',
{ iamAction: 'CanRead', iamResource: 'ssrn:ss:iam:::account/100/assestmentgroup/2/customquestions' },
{
iamAction: 'CanRead',
iamResource: 'ssrn:ss:iam:::account/100/assestmentgroup/2/customquestions'
},
'This is nested and should show'

@@ -79,3 +85,6 @@ )

'p',
{ iamAction: 'CanRead', iamResource: 'ssrn:ss:iam:::account/100/assestmentgroup/2/customquestions' },
{
iamAction: 'CanRead',
iamResource: 'ssrn:ss:iam:::account/100/assestmentgroup/2/customquestions'
},
'This should show'

@@ -85,3 +94,6 @@ ),

'p',
{ iamAction: 'CanUpdate', iamResource: 'ssrn:ss:iam:::account/100/assestmentgroup/2/customquestions' },
{
iamAction: 'CanUpdate',
iamResource: 'ssrn:ss:iam:::account/100/assestmentgroup/2/customquestions'
},
'This should hide'

@@ -94,3 +106,6 @@ ),

'option',
{ iamAction: 'CanRead', iamResource: 'ssrn:ss:iam:::account/100/assestmentgroup/2/customquestions' },
{
iamAction: 'CanRead',
iamResource: 'ssrn:ss:iam:::account/100/assestmentgroup/2/customquestions'
},
'This should show'

@@ -100,3 +115,6 @@ ),

'option',
{ iamAction: 'CanUpdate', iamResource: 'ssrn:ss:iam:::account/100/assestmentgroup/2/customquestions' },
{
iamAction: 'CanUpdate',
iamResource: 'ssrn:ss:iam:::account/100/assestmentgroup/2/customquestions'
},
'This should hide'

@@ -108,7 +126,24 @@ )

Validate,
{ iamAction: 'CanRead', iamResource: 'ssrn:ss:iam:::account/100/assestmentgroup/2/customquestions' },
null,
_react2.default.createElement(
'button',
{
iamAction: 'CanRead',
iamResource: 'ssrn:ss:iam:::account/100/assestmentgroup/2/customquestions',
className: 'btn--outline btn--negative'
},
'Text here'
)
),
_react2.default.createElement(
Validate,
{
iamAction: 'CanRead',
iamResource: 'ssrn:ss:iam:::account/100/assestmentgroup/2/customquestions'
},
_react2.default.createElement(
'p',
null,
' This should show and is nested in validate that has action and resourse'
' ',
'This should show and is nested in validate that has action and resourse'
)

@@ -118,8 +153,39 @@ ),

Validate,
{ iamAction: 'CanUpdate', iamResource: 'ssrn:ss:iam:::account/100/assestmentgroup/2/customquestions' },
{
iamAction: 'CanUpdate',
iamResource: 'ssrn:ss:iam:::account/100/assestmentgroup/2/customquestions'
},
_react2.default.createElement(
'p',
null,
' This should hide and is nested in validate that has action and resourse'
' ',
'This should hide and is nested in validate that has action and resourse'
)
),
_react2.default.createElement(
Validate,
null,
_react2.default.createElement(
'div',
{ className: 'wrap' },
_react2.default.createElement(
'header',
{ className: 'page__header' },
_react2.default.createElement(
'div',
{ className: 'wrap' },
_react2.default.createElement(
'h1',
{ className: 'page__title' },
'hi'
),
_react2.default.createElement(
'div',
{ className: 'page__actions actions' },
'hi',
null
)
)
)
)
)

@@ -126,0 +192,0 @@ );

@@ -7,2 +7,6 @@ 'use strict';

var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

@@ -18,10 +22,2 @@

var _lodash = require('lodash');
var _lodash2 = _interopRequireDefault(_lodash);
var _reactChildrenUtilities = require('react-children-utilities');
var _reactChildrenUtilities2 = _interopRequireDefault(_reactChildrenUtilities);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -46,9 +42,28 @@

_createClass(Validate, [{
key: 'deepMap',
value: function deepMap(children, deepMapFn) {
var _this2 = this;
return _react.Children.map(children, function (child) {
if (child) {
if (child.props && child.props.children && _typeof(child.props.children) === 'object') {
// Clone the child that has children and map them too
return deepMapFn((0, _react.cloneElement)(child, _extends({}, child.props, {
children: _this2.deepMap(child.props.children, deepMapFn)
})));
}
return deepMapFn(child);
} else {
return child;
}
});
}
}, {
key: 'render',
value: function render() {
var localIam = _lodash2.default.cloneDeep(config.iam);
var localIam = config.iam;
var children = null;
//if action and resource was tagged to validate then it is applyed to every child nested inside
if (this.props.iamAction && this.props.iamResource) {
if (this.props && this.props.iamAction && this.props.iamResource) {
//check auth based on the iam doc action and resource to decide if this child content should be displayed.

@@ -64,5 +79,5 @@ if (_openIam2.default.authorize(this.props.iamResource, this.props.iamAction, _openIam2.default.processIamData(localIam))) {

//else validate will loop its children recursively and look for action/resources tagged to any ui element
children = _reactChildrenUtilities2.default.deepMap(this.props.children, function (child) {
children = this.deepMap(this.props.children, function (child) {
//if this child has action and resource run auth against it
if (child.props.iamAction && child.props.iamResource) {
if (child.props && child.props.iamAction && child.props.iamResource) {
//either return the child or blank based on iam authorize

@@ -69,0 +84,0 @@ return _openIam2.default.authorize(child.props.iamResource, child.props.iamAction, _openIam2.default.processIamData(localIam)) ? child : '';

{
"name": "@smarterservices/iam-react-client",
"version": "0.0.4",
"version": "1.0.0",
"devDependencies": {
"react-scripts": "0.9.5"
"react-scripts": "0.9.5",
"react-dom": "^15.5.4"
},
"dependencies": {
"open-iam": "0.0.12",
"react": "^15.5.4",
"react-children-utilities": "^0.1.7",
"react-dom": "^15.5.4"
"react": "^15.5.4"
},

@@ -13,0 +12,0 @@ "author": {

@@ -5,5 +5,2 @@ import React from 'react';

ReactDOM.render(
<Test />,
document.getElementById('root')
);
ReactDOM.render(<Test />, document.getElementById('root'));
import React, { Component } from 'react';
import ValidateConstructor from './Validate'
import ValidateConstructor from './Validate';
var testIam = {
"Statement": [
Statement: [
{
"Effect": "Allow",
"Action": ["CanRead"],
"Resource": [
"ssrn:ss:iam:::account/100/assestmentgroup/*/customquestions"
Effect: 'Allow',
Action: [ 'CanRead' ],
Resource: [
'ssrn:ss:iam:::account/100/assestmentgroup/*/customquestions'
]
},
{
"Effect": "Allow",
"Action": ["CanUpdate","CanDelete","CanCreate"],
"Resource": "ssrn:ss:iam:::account/100/assestmentgroup/1/customquestions"
Effect: 'Allow',
Action: [ 'CanUpdate', 'CanDelete', 'CanCreate' ],
Resource: 'ssrn:ss:iam:::account/100/assestmentgroup/1/customquestions'
},
{
"Effect": "Deny",
"Action": ["CanUpdate"],
"Resource": [
"ssrn:ss:iam:::account/100/assestmentgroup/2/customquestions"
Effect: 'Deny',
Action: [ 'CanUpdate' ],
Resource: [
'ssrn:ss:iam:::account/100/assestmentgroup/2/customquestions'
]
}
]
}
var Validate = new ValidateConstructor({iam:testIam});
};
var Validate = new ValidateConstructor({ iam: testIam });
class Test extends Component {

@@ -33,29 +32,82 @@ render() {

<div className="App">
<Validate>
<div>
<p iamAction="CanUpdate" iamResource="ssrn:ss:iam:::account/100/assestmentgroup/2/customquestions">This is nested and should hide</p>
<p iamAction="CanRead" iamResource="ssrn:ss:iam:::account/100/assestmentgroup/2/customquestions">This is nested and should show</p>
</div>
<p iamAction="CanRead" iamResource="ssrn:ss:iam:::account/100/assestmentgroup/2/customquestions">This should show</p>
<p iamAction="CanUpdate" iamResource="ssrn:ss:iam:::account/100/assestmentgroup/2/customquestions">This should hide</p>
<select>
<option iamAction="CanRead" iamResource="ssrn:ss:iam:::account/100/assestmentgroup/2/customquestions">This should show</option>
<option iamAction="CanUpdate" iamResource="ssrn:ss:iam:::account/100/assestmentgroup/2/customquestions" >This should hide</option>
</select>
<div>
<p
iamAction="CanUpdate"
iamResource="ssrn:ss:iam:::account/100/assestmentgroup/2/customquestions"
>
This is nested and should hide
</p>
<p
iamAction="CanRead"
iamResource="ssrn:ss:iam:::account/100/assestmentgroup/2/customquestions"
>
This is nested and should show
</p>
</div>
<p
iamAction="CanRead"
iamResource="ssrn:ss:iam:::account/100/assestmentgroup/2/customquestions"
>
This should show
</p>
<p
iamAction="CanUpdate"
iamResource="ssrn:ss:iam:::account/100/assestmentgroup/2/customquestions"
>
This should hide
</p>
<select>
<option
iamAction="CanRead"
iamResource="ssrn:ss:iam:::account/100/assestmentgroup/2/customquestions"
>
This should show
</option>
<option
iamAction="CanUpdate"
iamResource="ssrn:ss:iam:::account/100/assestmentgroup/2/customquestions"
>
This should hide
</option>
</select>
</Validate>
<Validate iamAction="CanRead" iamResource="ssrn:ss:iam:::account/100/assestmentgroup/2/customquestions">
<p> This should show and is nested in validate that has action and resourse</p>
</Validate>
<Validate iamAction="CanUpdate" iamResource="ssrn:ss:iam:::account/100/assestmentgroup/2/customquestions">
<p> This should hide and is nested in validate that has action and resourse</p>
</Validate>
<Validate>
<button
iamAction="CanRead"
iamResource="ssrn:ss:iam:::account/100/assestmentgroup/2/customquestions"
className="btn--outline btn--negative"
>
Text here
</button>
</Validate>
<Validate
iamAction="CanRead"
iamResource="ssrn:ss:iam:::account/100/assestmentgroup/2/customquestions"
>
<p>
{' '}This should show and is nested in validate that has action and resourse
</p>
</Validate>
<Validate
iamAction="CanUpdate"
iamResource="ssrn:ss:iam:::account/100/assestmentgroup/2/customquestions"
>
<p>
{' '}This should hide and is nested in validate that has action and resourse
</p>
</Validate>
<Validate>
<div className="wrap">
<header className="page__header">
<div className="wrap">
<h1 className="page__title">hi</h1>
<div className="page__actions actions">
hi
{null}
</div>
</div>
</header>
</div>
</Validate>
</div>

@@ -62,0 +114,0 @@ );

@@ -1,46 +0,76 @@

import React, { Component } from 'react';
import React, { Component, Children, cloneElement } from 'react';
import iam from 'open-iam';
import Children from 'react-children-utilities';
var ValidateConstructor = function(config) {
return class Validate extends Component {
render() {
let localIam = config.iam
let children = null
return class Validate extends Component {
deepMap(children, deepMapFn) {
return Children.map(children, child => {
if (child) {
if (
child.props &&
child.props.children &&
typeof child.props.children === 'object'
) {
// Clone the child that has children and map them too
return deepMapFn(
cloneElement(child, {
...child.props,
children: this.deepMap(child.props.children, deepMapFn)
})
);
}
return deepMapFn(child);
} else {
return child;
}
});
}
render() {
let localIam = config.iam;
let children = null;
//if action and resource was tagged to validate then it is applyed to every child nested inside
if(this.props.iamAction && this.props.iamResource) {
//check auth based on the iam doc action and resource to decide if this child content should be displayed.
if(iam.authorize(this.props.iamResource,this.props.iamAction,iam.processIamData(localIam))) {
//set childWithProps to the unaltered children because auth returned true
children = this.props.children;
//if action and resource was tagged to validate then it is applyed to every child nested inside
if (this.props && this.props.iamAction && this.props.iamResource) {
//check auth based on the iam doc action and resource to decide if this child content should be displayed.
if (
iam.authorize(
this.props.iamResource,
this.props.iamAction,
iam.processIamData(localIam)
)
) {
//set childWithProps to the unaltered children because auth returned true
children = this.props.children;
} else {
//return nothing to display to the dom because authorize returned false
children = null;
}
} else {
//return nothing to display to the dom because authorize returned false
children = null;
//else validate will loop its children recursively and look for action/resources tagged to any ui element
children = this.deepMap(this.props.children, child => {
//if this child has action and resource run auth against it
if (child.props && child.props.iamAction && child.props.iamResource) {
//either return the child or blank based on iam authorize
return iam.authorize(
child.props.iamResource,
child.props.iamAction,
iam.processIamData(localIam)
)
? child
: '';
} else {
//no action or resource so its a normal dom element
return child;
}
});
}
} else {
//else validate will loop its children recursively and look for action/resources tagged to any ui element
children = Children.deepMap(this.props.children,
(child) => {
//if this child has action and resource run auth against it
if(child.props.iamAction && child.props.iamResource) {
//either return the child or blank based on iam authorize
return (iam.authorize(child.props.iamResource,child.props.iamAction,iam.processIamData(localIam))) ? child : ''
} else {
//no action or resource so its a normal dom element
return child
}
return (
<div className="none">
{children}
</div>
);
}
);
}
return (
<div className="none">
{children}
</div>
);
}
}
};
};
}
export default ValidateConstructor;
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