-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit cc0bcec
Showing
227 changed files
with
16,163 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json", | ||
"changelog": "@changesets/cli/changelog", | ||
"commit": false, | ||
"fixed": [], | ||
"linked": [], | ||
"access": "public", | ||
"baseBranch": "master", | ||
"updateInternalDependencies": "patch", | ||
"ignore": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
extends: | ||
- '@commitlint/config-conventional' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# ignore husky hooks | ||
.husky/* linguist-detectable=false | ||
|
||
# ignore bin/index.js | ||
*.js linguist-detectable=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
github: minenwerfer | ||
open_collective: aeria |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
name: Continuos Integration | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Setup pnpm | ||
uses: pnpm/action-setup@v2 | ||
- name: Setup node | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 20 | ||
cache: pnpm | ||
- name: Install dependencies | ||
run: pnpm install | ||
|
||
- name: Build packages | ||
run: | | ||
pnpm --no-bail --filter='./packages/types' build \ | ||
&& pnpm --no-bail --filter='./packages/common' build \ | ||
&& pnpm --no-bail --filter='./packages/entrypoint' build \ | ||
&& pnpm --no-bail --filter='./packages/validation' build \ | ||
&& pnpm --no-bail --filter='./packages/http' build \ | ||
&& pnpm --no-bail --filter='./packages/node-http' build \ | ||
&& pnpm --no-bail --filter='./packages/access-control' build \ | ||
&& pnpm --no-bail --filter='./packages/security' build \ | ||
&& pnpm --no-bail --filter='./packages/api' build \ | ||
&& pnpm --no-bail --filter='./packages/builtins' build \ | ||
&& pnpm --no-bail --filter='./packages/server' build \ | ||
&& pnpm --no-bail --filter='./packages/aeria' build \ | ||
&& pnpm --no-bail --filter='./packages/aeria-build' build:build | ||
- name: Patch node_modules | ||
run: | | ||
find packages -mindepth 1 -maxdepth 1 \ | ||
-exec bash -c 'a={}; cp -r $a/dist node_modules/@aeriajs/${a//packages\//} 2>/dev/null || true' \; | ||
cp -r packages node_modules/@aeriajs | ||
- name: Build playground | ||
run: | | ||
cd playground | ||
pnpm install . | ||
pnpm build | ||
- name: Run tests | ||
run: pnpm -r test | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
node_modules | ||
__pycache__ | ||
.env | ||
production.env | ||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/usr/bin/env sh | ||
. "$(dirname -- "$0")/_/husky.sh" | ||
|
||
pnpm commitlint --edit ${1} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/usr/bin/env sh | ||
. "$(dirname -- "$0")/_/husky.sh" | ||
|
||
for ws in $(git diff --name-only --cached | grep -oE 'packages/([^/]+)' | uniq); do | ||
pnpm --filter="./${ws}" lint:fix | ||
done | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/usr/bin/env sh | ||
. "$(dirname -- "$0")/_/husky.sh" | ||
|
||
pnpm -r lint | ||
|
||
if test -d playground/node_modules; then | ||
rm pnpm-lock.yaml | ||
pnpm i | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Copyright 2023 João Santos ([email protected]) | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
this software and associated documentation files (the “Software”), to deal in | ||
the Software without restriction, including without limitation the rights to | ||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies | ||
of the Software, and to permit persons to whom the Software is furnished to do | ||
so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# Aeria ![https://github.com/aeria-org/aeria/actions/workflows/ci.yaml](https://github.com/aeria-org/aeria/actions/workflows/ci.yaml/badge.svg) | ||
|
||
<img | ||
align="left" | ||
src="/assets/aeria-logo.png" | ||
alt="Aeria Logo" | ||
width="190px" | ||
height="190px" | ||
/> | ||
|
||
|
||
A source of truth and REST framework for the busy developer. | ||
|
||
```typescript | ||
router.GET('/get-pets/(\w+)', (context) => { | ||
return context.collections.pet.functions.getAll({ | ||
filters: { | ||
name: context.request.fragments[0] | ||
} | ||
}) | ||
}) | ||
``` | ||
|
||
<br clear="left" /> | ||
|
||
## Features | ||
|
||
### Minimalistically typed | ||
|
||
A type-driven experience is provided with state-of-the-art TypeScript, no code generation required. Define your collection structure with a runtime JavaScript object then it's type will be made universally available, even to the frontend. | ||
|
||
### A more cohesive fullstack | ||
|
||
Aeria makes your backend metadata fully available to the frontend with [JSON Schema](https://json-schema.org/), allowing third parties to quickly grasp how your data should be rendered. The official counterpart library [Aeria UI]() makes possible to bring up a complete frontend for an Aeria backend within minutes. | ||
|
||
### Better error handling | ||
|
||
Inspired by functional languages, Aeria makes use of the much safer and runtime efficient `Either` approach to error handling. Route callbacks have their exceptions handled by default, so your application won't crash if you miss a try/catch block. | ||
|
||
### Runtime safety | ||
|
||
All input data is optionally validated using the same schemas used during collection definition. Role-based access control and security checks for [common security weaknesses](https://github.com/aeria-org/aeria/tree/master/packages/security) are also shipped to allow even those who are unfamiliar with AppSec to build safely. | ||
|
||
|
||
## Resources | ||
|
||
- [Official Documentation](https://aeria.land/aeria/) | ||
- [Aeria UI](https://aeria.land/aeria-ui/) | ||
- [Aeria SDK](https://aeria.land/aeria-sdk/) | ||
- [Aeria Lang](https://aeria.land/aeria-lang/) | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = [require('eslint-config-aeria')] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"name": "aeria-monorepo", | ||
"private": true, | ||
"packageManager": "[email protected]", | ||
"scripts": { | ||
"postinstall": "husky; rm -rf packages/*/node_modules/@aeriajs", | ||
"esm-transform": "./scripts/transform-import-extensions.ts", | ||
"write-icons": "NODE_PATH=./playground/node_modules ./scripts/compile-builtins-icons.ts" | ||
}, | ||
"devDependencies": { | ||
"@changesets/cli": "^2.26.2", | ||
"@commitlint/cli": "^17.7.1", | ||
"@commitlint/config-conventional": "^17.7.0", | ||
"@swc/cli": "^0.3.9", | ||
"@types/mocha": "^10.0.1", | ||
"@types/node": "^20.10.4", | ||
"eslint": "^8.57.0", | ||
"eslint-config-aeria": "latest", | ||
"glob": "^9.3.0", | ||
"husky": "^9.0.10", | ||
"mocha": "^10.2.0", | ||
"ts-node": "^10.9.1", | ||
"typescript": "^5.1.6" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import type { Collection } from '../src/types' | ||
|
||
declare global { | ||
type Collections = Record<string, ReturnType<Collection>> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# `@aeriajs/access-control` | ||
|
||
## Introduction | ||
|
||
This package implements [Role-based access control](https://en.wikipedia.org/wiki/Role-based_access_control) for collection functions. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
{ | ||
"name": "@aeriajs/access-control", | ||
"version": "0.0.0", | ||
"description": "## Instalation", | ||
"main": "dist/index.js", | ||
"module": "dist/index.mjs", | ||
"types": "dist/index.d.ts", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"scripts": { | ||
"test": "echo skipping", | ||
"lint": "eslint src", | ||
"lint:fix": "eslint src --fix", | ||
"build": "pnpm build:cjs && pnpm build:esm", | ||
"build:cjs": "tsc", | ||
"build:esm": "swc src/* -d dist --strip-leading-paths -C module.type=es6 --out-file-extension=mjs && pnpm build:esm-transform", | ||
"build:esm-transform": "pnpm -w esm-transform $PWD/dist", | ||
"prepublishOnly": "pnpm lint && pnpm build" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"exports": { | ||
".": { | ||
"import": "./dist/index.mjs", | ||
"require": "./dist/index.js", | ||
"types": "./dist/index.d.ts" | ||
} | ||
}, | ||
"files": [ | ||
"dist" | ||
], | ||
"peerDependencies": { | ||
"@aeriajs/common": "^0.0.0", | ||
"@aeriajs/entrypoint": "^0.0.0", | ||
"@aeriajs/types": "^0.0.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import type { AccessControl } from '@aeriajs/types' | ||
|
||
export const DEFAULT_ACCESS_CONTROL = <const>{ | ||
roles: { | ||
root: { | ||
grantEverything: true, | ||
}, | ||
}, | ||
} satisfies AccessControl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
import type { AccessControl, Role, ACProfile } from '@aeriajs/types' | ||
import { getCollection, getCollections } from '@aeriajs/entrypoint' | ||
import { deepMerge } from '@aeriajs/common' | ||
import { DEFAULT_ACCESS_CONTROL } from './constants.js' | ||
|
||
let availableRolesMemo: string[] | undefined | ||
|
||
const applyInheritance = async (accessControl: AccessControl, targetRole: Role) => { | ||
const role = Object.assign({}, targetRole) | ||
|
||
if( role.inherit ) { | ||
for( const roleName of role.inherit ) { | ||
const parentRole = accessControl.roles?.[String(roleName)] | ||
if( !parentRole ) { | ||
throw new Error(`inherit: role ${String(roleName)} doesnt exist`) | ||
} | ||
|
||
Object.assign(role, deepMerge(role, await applyInheritance(accessControl, parentRole))) | ||
} | ||
} | ||
|
||
return role | ||
} | ||
|
||
export const getAccessControl = async <TCollectionName extends string>(collectionName: TCollectionName): Promise<AccessControl | undefined> => { | ||
const collection = await getCollection(collectionName) | ||
if( collection ) { | ||
const accessControl = collection.accessControl || DEFAULT_ACCESS_CONTROL | ||
return accessControl | ||
} | ||
} | ||
|
||
export const getAvailableRoles = async () => { | ||
if( availableRolesMemo ) { | ||
return availableRolesMemo | ||
} | ||
|
||
const collections = await getCollections() | ||
const availableRoles = [] | ||
|
||
for( const collectionName in collections ) { | ||
const ac = await getAccessControl(collectionName) | ||
if( !ac?.roles ) { | ||
continue | ||
} | ||
|
||
availableRoles.push(...Object.keys(ac.roles)) | ||
} | ||
|
||
availableRolesMemo = [...new Set(availableRoles)] | ||
return availableRolesMemo | ||
} | ||
|
||
export const isGranted = async ( | ||
collectionName: keyof Collections, | ||
functionName: string, | ||
acProfile: ACProfile, | ||
) => { | ||
const accessControl = await getAccessControl(collectionName) | ||
if( !accessControl ) { | ||
return false | ||
} | ||
|
||
const userRoles = (acProfile.roles || ['guest']) | ||
|
||
for( const roleName of userRoles ) { | ||
const targetRole = accessControl.roles?.[roleName] | ||
if( !targetRole ) { | ||
continue | ||
} | ||
|
||
const currentRole = await applyInheritance(accessControl, targetRole) | ||
if( currentRole.forbid?.includes(functionName) ) { | ||
return false | ||
} | ||
|
||
const allowedInToken = !acProfile.allowed_functions || ( | ||
acProfile.allowed_functions.includes(`${collectionName}@${functionName}`) | ||
) | ||
|
||
const result = allowedInToken && ( | ||
currentRole.grantEverything | ||
|| currentRole.grant?.includes(functionName) | ||
) | ||
|
||
if( result ) { | ||
return true | ||
} | ||
} | ||
|
||
return false | ||
} | ||
|
||
export const grantedFor = async < | ||
TCollectionName extends string, | ||
TFunctionName extends string, | ||
>( | ||
collectionName: TCollectionName, | ||
functionName: TFunctionName, | ||
) => { | ||
const accessControl = await getAccessControl(collectionName) | ||
if( !accessControl?.roles ) { | ||
return [] | ||
} | ||
|
||
const roles = [] | ||
for( const role in accessControl.roles ) { | ||
const granted = await isGranted(collectionName, functionName, { | ||
roles: [role], | ||
}) | ||
|
||
if( granted ) { | ||
roles.push(role) | ||
} | ||
} | ||
|
||
return roles | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './constants.js' | ||
export * from './granted.js' |
Oops, something went wrong.