@superawesome/permissions
Version:
Fine grained permissions / access control with ownerships & attribute picking, done right.
402 lines (369 loc) • 17.5 kB
HTML
<html class="no-js" lang="">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>SuperAwesome Permissions (@superawesome/permissions)</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="../images/favicon.ico">
<link rel="stylesheet" href="../styles/style.css">
<link rel="stylesheet" href="../styles/postmark.css">
</head>
<body>
<div class="navbar navbar-default navbar-fixed-top visible-xs">
<a href="../" class="navbar-brand">SuperAwesome Permissions (@superawesome/permissions)</a>
<button type="button" class="btn btn-default btn-menu ion-ios-menu" id="btn-menu"></button>
</div>
<div class="xs-menu menu" id="mobile-menu">
<div id="book-search-input" role="search"><input type="text" placeholder="Type to search"></div> <compodoc-menu></compodoc-menu>
</div>
<div class="container-fluid main">
<div class="row main">
<div class="hidden-xs menu">
<compodoc-menu mode="normal"></compodoc-menu>
</div>
<!-- START CONTENT -->
<div class="content miscellaneous-typealiases">
<div class="content-data">
<ol class="breadcrumb">
<li>Miscellaneous</li>
<li>Type aliases</li>
</ol>
<section>
<h3 id="index">Index</h3>
<table class="table table-sm table-bordered index-table">
<tbody>
<tr>
<td class="col-md-4">
<ul class="index-list">
<li>
<a href="#IContext" title="src/types.ts"><b>IContext</b> (src/.../types.ts)</a>
</li>
<li>
<a href="#PermissionDefinition" title="src/PermissionDefinitions.ts"><b>PermissionDefinition</b> (src/.../PermissionDefinitions.ts)</a>
</li>
<li>
<a href="#TActionsList" title="src/types.ts"><b>TActionsList</b> (src/.../types.ts)</a>
</li>
<li>
<a href="#TAttributes" title="src/types.ts"><b>TAttributes</b> (src/.../types.ts)</a>
</li>
<li>
<a href="#TGrants" title="src/types.ts"><b>TGrants</b> (src/.../types.ts)</a>
</li>
<li>
<a href="#Tid" title="src/types.ts"><b>Tid</b> (src/.../types.ts)</a>
</li>
<li>
<a href="#TisOwner" title="src/types.ts"><b>TisOwner</b> (src/.../types.ts)</a>
</li>
<li>
<a href="#TlimitOwned" title="src/types.ts"><b>TlimitOwned</b> (src/.../types.ts)</a>
</li>
<li>
<a href="#TlimitOwnReduce" title="src/types.ts"><b>TlimitOwnReduce</b> (src/.../types.ts)</a>
</li>
<li>
<a href="#TlistOwned" title="src/types.ts"><b>TlistOwned</b> (src/.../types.ts)</a>
</li>
</ul>
</td>
</tr>
</tbody>
</table>
</section>
<h3>src/types.ts</h3>
<section>
<table class="table table-sm table-bordered">
<tbody>
<tr>
<td class="col-md-4">
<a name="IContext"></a>
<span class="name"><b>IContext</b><a href="#IContext"><span class="icon ion-ios-link"></span></a></span>
</td>
</tr>
<tr>
<td class="col-md-4">
<code> <code>Tctx</code>
</code>
</td>
</tr>
</tbody>
</table>
<table class="table table-sm table-bordered">
<tbody>
<tr>
<td class="col-md-4">
<a name="TActionsList"></a>
<span class="name"><b>TActionsList</b><a href="#TActionsList"><span class="icon ion-ios-link"></span></a></span>
</td>
</tr>
<tr>
<td class="col-md-4">
<div class="io-description"><p>The "light" array of actions (and optional possession) that we can assign to <code>PermissionDefinition.grant</code>, granting these <strong>actions</strong>.</p>
<p>Internally all actions will inherit by default:</p>
<ul>
<li><p>the <strong>attributes</strong> of <code>PermissionDefinition.attributes</code> or default to <code>['*']</code>.</p>
</li>
<li><p>the <strong>possession</strong> of <code>PermissionDefinition.possession</code> or default to <code>any</code>.</p>
</li>
</ul>
<p>Example:</p>
<div><pre class="line-numbers"><code class="language-js"> {
// a PermissionDefinition object
...
grants: ['read', 'update:own', 'like:any', 'follow']
...
}</code></pre></div><p>Also see <a href="/miscellaneous/typealiases.html#TGrants"><code>TGrants</code></a></p>
</div>
</td>
</tr>
<tr>
<td class="col-md-4">
<code> <code>string[]</code>
</code>
</td>
</tr>
</tbody>
</table>
<table class="table table-sm table-bordered">
<tbody>
<tr>
<td class="col-md-4">
<a name="TAttributes"></a>
<span class="name"><b>TAttributes</b><a href="#TAttributes"><span class="icon ion-ios-link"></span></a></span>
</td>
</tr>
<tr>
<td class="col-md-4">
<div class="io-description"><p>Eg <code>['*', '!price', '!confidential']</code></p>
</div>
</td>
</tr>
<tr>
<td class="col-md-4">
<code> <code>string[]</code>
</code>
</td>
</tr>
</tbody>
</table>
<table class="table table-sm table-bordered">
<tbody>
<tr>
<td class="col-md-4">
<a name="TGrants"></a>
<span class="name"><b>TGrants</b><a href="#TGrants"><span class="icon ion-ios-link"></span></a></span>
</td>
</tr>
<tr>
<td class="col-md-4">
<div class="io-description"><p>The "full" object we can assign to <code>PermissionDefinition.grant</code>, granting <strong>actions</strong> and their corresponding <strong>attributes</strong>:</p>
<div><pre class="line-numbers"><code class="language-js"> {
'read': ['*'],
'read:own': ['*'],
'read:any': ['*', '!price', '!confidential'],
'delete:own': ['*'],
...
}
</code></pre></div><p><strong>Note</strong>: actions optionally accept possession "any" or "own" after the colon. Internally all actions missing the possession part, will inherit the <strong>possession</strong> of <code>PermissionDefinition.possession</code> or default to <code>any</code>.</p>
<p>Also see <a href="/miscellaneous/typealiases.html#TActionsList"><code>TActionsList</code></a></p>
</div>
</td>
</tr>
<tr>
<td class="col-md-4">
<code> <code>literal type</code>
</code>
</td>
</tr>
</tbody>
</table>
<table class="table table-sm table-bordered">
<tbody>
<tr>
<td class="col-md-4">
<a name="Tid"></a>
<span class="name"><b>Tid</b><a href="#Tid"><span class="icon ion-ios-link"></span></a></span>
</td>
</tr>
<tr>
<td class="col-md-4">
<div class="io-description"><p>An Id in your system, can be either <code>number</code> or <code>string</code> (eg a UUID).</p>
</div>
</td>
</tr>
<tr>
<td class="col-md-4">
<code> <code>number | string</code>
</code>
</td>
</tr>
</tbody>
</table>
<table class="table table-sm table-bordered">
<tbody>
<tr>
<td class="col-md-4">
<a name="TisOwner"></a>
<span class="name"><b>TisOwner</b><a href="#TisOwner"><span class="icon ion-ios-link"></span></a></span>
</td>
</tr>
<tr>
<td class="col-md-4">
<div class="io-description"><p>The interface of the <a href="/classes/PermissionDefinition_DOCS.html#isOwner"><code>isOwner</code> ownership hook</a>.</p>
<p>Should return <code>true</code> if <code>user</code> is owner of the <code>resourceId</code>, false otherwise - example:</p>
<div><pre class="line-numbers"><code class="language-js"> async ({user, resourceId}) => (await documentService.findById(resourceId).createdBby === user.id;</code></pre></div></div>
</td>
</tr>
<tr>
<td class="col-md-4">
<code> <code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/function" target="_blank" >function</a></code>
</code>
</td>
</tr>
</tbody>
</table>
<table class="table table-sm table-bordered">
<tbody>
<tr>
<td class="col-md-4">
<a name="TlimitOwned"></a>
<span class="name"><b>TlimitOwned</b><a href="#TlimitOwned"><span class="icon ion-ios-link"></span></a></span>
</td>
</tr>
<tr>
<td class="col-md-4">
<div class="io-description"><p>The interface of the <a href="/classes/PermissionDefinition_DOCS.html#limitOwned"><code>limitOwned</code> ownership hook</a>.</p>
<p>See <a href="/classes/Permit.html#limitOwn"><code>Permit.limitOwn()</code></a> and <a href="/additional-documentation/detailed-usage-&-examples.html">Examples 5 & 6</a> for how it is used in practice.</p>
<p><strong>Notes</strong>:</p>
<p>The <code>context</code> is of type any (IContext is just an alias for semantics).</p>
<p>Its up to the user what the context is (and how you add and retrieve data from it).</p>
<p>For instance, in an ORM scenario (consider TypeORM as an example) it could be your <code>query</code> or <code>subquery</code> object, to which you subsequently add <code>orWhere</code> expressions.</p>
<p>In a collection (eg array) filtering example, it might be just a bunch of filter functions that you accumulate in an array (i.e the <code>context</code>) and then somehow compose (eg with _.overSome).</p>
</div>
</td>
</tr>
<tr>
<td class="col-md-4">
<code> <code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/function" target="_blank" >function</a></code>
</code>
</td>
</tr>
</tbody>
</table>
<table class="table table-sm table-bordered">
<tbody>
<tr>
<td class="col-md-4">
<a name="TlimitOwnReduce"></a>
<span class="name"><b>TlimitOwnReduce</b><a href="#TlimitOwnReduce"><span class="icon ion-ios-link"></span></a></span>
</td>
</tr>
<tr>
<td class="col-md-4">
<div class="io-description"><p>The interface of the <code>limitOwnReduce</code> you can pass to override the built in <code>permit.limitOwn()</code> implementation.</p>
<p>See <a href="/additional-documentation/detailed-usage-&-examples.html">Example 6</a> for how it is used in practice.</p>
</div>
</td>
</tr>
<tr>
<td class="col-md-4">
<code> <code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/function" target="_blank" >function</a></code>
</code>
</td>
</tr>
</tbody>
</table>
<table class="table table-sm table-bordered">
<tbody>
<tr>
<td class="col-md-4">
<a name="TlistOwned"></a>
<span class="name"><b>TlistOwned</b><a href="#TlistOwned"><span class="icon ion-ios-link"></span></a></span>
</td>
</tr>
<tr>
<td class="col-md-4">
<div class="io-description"><p>The interface of the <a href="/classes/PermissionDefinition_DOCS.html#listOwned"><code>listOwned</code> ownership hook</a>.</p>
<p>Should return an array of ids (see <a href="/miscellaneous/typealiases.html#Tid"><code>Tid</code></a> eg <code>[1, 2, 3]</code> or <code>['abc123', 'def456']</code>.</p>
<p> Example:</p>
<div><pre class="line-numbers"><code class="language-js"> async (user) => documentService.findWhere({ createdBy: user.id })</code></pre></div></div>
</td>
</tr>
<tr>
<td class="col-md-4">
<code> <code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/function" target="_blank" >function</a></code>
</code>
</td>
</tr>
</tbody>
</table>
</section> <h3>src/PermissionDefinitions.ts</h3>
<section>
<table class="table table-sm table-bordered">
<tbody>
<tr>
<td class="col-md-4">
<a name="PermissionDefinition"></a>
<span class="name"><b>PermissionDefinition</b><a href="#PermissionDefinition"><span class="icon ion-ios-link"></span></a></span>
</td>
</tr>
<tr>
<td class="col-md-4">
<div class="io-description"><p>This is the actual PermissionDefinition implementation, but the docs are in <a href="/classes/PermissionDefinition_DOCS.html">PermissionDefinition_DOCS</a>.</p>
<p>Implements the ownership hooks rules.</p>
</div>
</td>
</tr>
<tr>
<td class="col-md-4">
<code> <code><a href="../miscellaneous/typealiases.html#PermissionDefinition" target="_self" >MergeExclusive<PermissionDefinitionNoOwnershipInternal | RequireExactlyOne<PermissionDefinitionWithOwnershipInternal<TUserId, TResourceId>, "listOwned" | "limitOwned">></a></code>
</code>
</td>
</tr>
</tbody>
</table>
</section>
</div><div class="search-results">
<div class="has-results">
<h1 class="search-results-title"><span class='search-results-count'></span> result-matching "<span class='search-query'></span>"</h1>
<ul class="search-results-list"></ul>
</div>
<div class="no-results">
<h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
</div>
</div>
</div>
<!-- END CONTENT -->
</div>
</div>
<script>
var COMPODOC_CURRENT_PAGE_DEPTH = 1;
var COMPODOC_CURRENT_PAGE_CONTEXT = 'miscellaneous-typealiases';
var COMPODOC_CURRENT_PAGE_URL = 'typealiases.html';
</script>
<script src="../js/libs/custom-elements.min.js"></script>
<script src="../js/libs/lit-html.js"></script>
<!-- Required to polyfill modern browsers as code is ES5 for IE... -->
<script src="../js/libs/custom-elements-es5-adapter.js" charset="utf-8" defer></script>
<script src="../js/menu-wc.js" defer></script>
<script src="../js/libs/bootstrap-native.js"></script>
<script src="../js/libs/es6-shim.min.js"></script>
<script src="../js/libs/EventDispatcher.js"></script>
<script src="../js/libs/promise.min.js"></script>
<script src="../js/libs/zepto.min.js"></script>
<script src="../js/compodoc.js"></script>
<script src="../js/tabs.js"></script>
<script src="../js/menu.js"></script>
<script src="../js/libs/clipboard.min.js"></script>
<script src="../js/libs/prism.js"></script>
<script src="../js/sourceCode.js"></script>
<script src="../js/search/search.js"></script>
<script src="../js/search/lunr.min.js"></script>
<script src="../js/search/search-lunr.js"></script>
<script src="../js/search/search_index.js"></script>
<script src="../js/lazy-load-graphs.js"></script>
</body>
</html>