Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ yalc.lock
.early.coverage

tsconfig.tsbuildinfo
.qodo
583 changes: 292 additions & 291 deletions .yarn/releases/yarn-4.6.0.cjs → .yarn/releases/yarn-4.7.0.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ nodeLinker: node-modules

npmAuthToken: "${NODE_AUTH_TOKEN:-default}"

yarnPath: .yarn/releases/yarn-4.6.0.cjs
yarnPath: .yarn/releases/yarn-4.7.0.cjs
16 changes: 8 additions & 8 deletions __tests__/integration/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ describe("Integration", () => {
properties: {
email: "[email protected]",
picture:
"https://www.topaz.sh/assets/templates/citadel/img/Rick%20Sanchez.jpg",
"https://www.topaz.sh/assets/templates/v32/citadel/img/Rick%20Sanchez.jpg",
roles: ["admin", "evil_genius"],
status: "USER_STATUS_ACTIVE",
},
Expand Down Expand Up @@ -375,7 +375,7 @@ describe("Integration", () => {
properties: {
email: "[email protected]",
picture:
"https://www.topaz.sh/assets/templates/citadel/img/Rick%20Sanchez.jpg",
"https://www.topaz.sh/assets/templates/v32/citadel/img/Rick%20Sanchez.jpg",
roles: ["admin", "evil_genius"],
status: "USER_STATUS_ACTIVE",
},
Expand Down Expand Up @@ -494,7 +494,7 @@ describe("Integration", () => {
properties: {
email: "[email protected]",
picture:
"https://www.topaz.sh/assets/templates/citadel/img/Rick%20Sanchez.jpg",
"https://www.topaz.sh/assets/templates/v32/citadel/img/Rick%20Sanchez.jpg",
roles: ["admin", "evil_genius"],
status: "USER_STATUS_ACTIVE",
},
Expand Down Expand Up @@ -885,7 +885,7 @@ describe("Integration", () => {
properties: {
email: "[email protected]",
picture:
"https://www.topaz.sh/assets/templates/citadel/img/Beth%20Smith.jpg",
"https://www.topaz.sh/assets/templates/v32/citadel/img/Beth%20Smith.jpg",
roles: ["viewer"],
status: "USER_STATUS_ACTIVE",
},
Expand Down Expand Up @@ -913,7 +913,7 @@ describe("Integration", () => {
properties: {
email: "[email protected]",
picture:
"https://www.topaz.sh/assets/templates/citadel/img/Jerry%20Smith.jpg",
"https://www.topaz.sh/assets/templates/v32/citadel/img/Jerry%20Smith.jpg",
roles: ["viewer"],
status: "USER_STATUS_ACTIVE",
},
Expand All @@ -930,7 +930,7 @@ describe("Integration", () => {
properties: {
email: "[email protected]",
picture:
"https://www.topaz.sh/assets/templates/citadel/img/Morty%20Smith.jpg",
"https://www.topaz.sh/assets/templates/v32/citadel/img/Morty%20Smith.jpg",
roles: ["editor"],
status: "USER_STATUS_ACTIVE",
},
Expand All @@ -948,7 +948,7 @@ describe("Integration", () => {
status: "USER_STATUS_ACTIVE",
email: "[email protected]",
picture:
"https://www.topaz.sh/assets/templates/citadel/img/Rick%20Sanchez.jpg",
"https://www.topaz.sh/assets/templates/v32/citadel/img/Rick%20Sanchez.jpg",
roles: ["admin", "evil_genius"],
},
createdAt: expect.anything(),
Expand All @@ -964,7 +964,7 @@ describe("Integration", () => {
properties: {
email: "[email protected]",
picture:
"https://www.topaz.sh/assets/templates/citadel/img/Summer%20Smith.jpg",
"https://www.topaz.sh/assets/templates/v32/citadel/img/Summer%20Smith.jpg",
roles: ["editor"],
status: "USER_STATUS_ACTIVE",
},
Expand Down
100 changes: 54 additions & 46 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import simpleImportSort from "eslint-plugin-simple-import-sort";
import typescriptSortKeys from "eslint-plugin-typescript-sort-keys";
import perfectionist from "eslint-plugin-perfectionist";
import path from "node:path";
import { fileURLToPath } from "node:url";

import { fixupConfigRules } from "@eslint/compat";
import { FlatCompat } from "@eslint/eslintrc";
import js from "@eslint/js";
Expand All @@ -10,9 +10,9 @@ import tsParser from "@typescript-eslint/parser";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const compat = new FlatCompat({
allConfig: js.configs.all,
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all,
});

export default [
Expand All @@ -27,93 +27,101 @@ export default [
"plugin:prettier/recommended",
),
),
perfectionist.configs["recommended-natural"],
{
plugins: {
"simple-import-sort": simpleImportSort,
"typescript-sort-keys": typescriptSortKeys,
},

languageOptions: {
parser: tsParser,
ecmaVersion: 2018,
parser: tsParser,
sourceType: "module",
},

rules: {
curly: "error",
eqeqeq: ["error", "always"],
"no-console": "warn",
"no-debugger": "warn",
"no-duplicate-case": "error",
"no-use-before-define": "off",
plugins: {},

rules: {
"@typescript-eslint/consistent-type-assertions": [
"error",
{
assertionStyle: "as",
objectLiteralTypeAssertions: "allow-as-parameter",
},
],

"@typescript-eslint/explicit-module-boundary-types": "off",

"@typescript-eslint/naming-convention": [
1,
{
selector: "interface",
format: ["PascalCase"],
selector: "interface",
},
],

"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/no-inferrable-types": "off",
"@typescript-eslint/no-non-null-asserted-nullish-coalescing": "error",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-var-requires": "off",
"prettier/prettier": ["error"],

"simple-import-sort/imports": [
"warn",
{
groups: [["^\\u0000"], ["^\\w", "^@"], ["^"], ["^\\."]],
},
],

"typescript-sort-keys/string-enum": [
"@typescript-eslint/no-empty-interface": "off",
"@typescript-eslint/no-explicit-any": [
"error",
"asc",
{
caseSensitive: false,
natural: true,
fixToUnknown: true,
},
],

"@typescript-eslint/no-inferrable-types": "off",

"@typescript-eslint/no-non-null-asserted-nullish-coalescing": "error",

"@typescript-eslint/no-non-null-assertion": "off",

"@typescript-eslint/no-unused-expressions": [
"error",
{
allowShortCircuit: true,
allowTernary: true,
},
],

"@typescript-eslint/no-empty-interface": "off",

"@typescript-eslint/no-explicit-any": [
"error",
"@typescript-eslint/no-unused-vars": [
"warn",
{
fixToUnknown: true,
argsIgnorePattern: "^_",
varsIgnorePattern: "^_",
},
],
"@typescript-eslint/no-var-requires": "off",
curly: "error",
eqeqeq: ["error", "always"],
"no-console": "warn",

"no-debugger": "warn",

"no-duplicate-case": "error",

"no-unused-vars": "off",

"@typescript-eslint/no-unused-vars": [
"no-use-before-define": "off",
"perfectionist/sort-enums": [
"warn",
{
argsIgnorePattern: "^_",
varsIgnorePattern: "^_",
partitionByComment: true,
partitionByNewLine: true,
},
],
"perfectionist/sort-imports": [
"warn",
{
internalPattern: ["^@"],
specialCharacters: "keep",
},
],
"perfectionist/sort-maps": [
"warn",
{
partitionByComment: true,
partitionByNewLine: true,
},
],
"perfectionist/sort-objects": "off",
"perfectionist/sort-object-types": "off",
"perfectionist/sort-interfaces": "off",
"perfectionist/sort-classes": "off",
"perfectionist/sort-enums": "off",

"prettier/prettier": ["error"],
},
},
];
1 change: 1 addition & 0 deletions lib/authorizer/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { readFileSync } from "fs";

import {
Authorizer as AuthorizerClient,
DecisionTreeRequestSchema,
Expand Down
1 change: 1 addition & 0 deletions lib/authorizer/mapper/identity/jwt.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Request } from "express";
import { jwtDecode } from "jwt-decode";

import { IdentityContext } from "@aserto/node-authorizer/src/gen/cjs/aserto/authorizer/v2/api/identity_context_pb";

import { IdentityMapper } from "../../middleware";
Expand Down
1 change: 1 addition & 0 deletions lib/authorizer/mapper/identity/sub.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Request } from "express";
import { jwtDecode, JwtPayload } from "jwt-decode";

import { IdentityContext } from "@aserto/node-authorizer/src/gen/cjs/aserto/authorizer/v2/api/identity_context_pb";

import { IdentityMapper } from "../../middleware";
Expand Down
27 changes: 14 additions & 13 deletions lib/authorizer/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { NextFunction, Request, Response } from "express";

import { IdentityContext } from "@aserto/node-authorizer/src/gen/cjs/aserto/authorizer/v2/api/identity_context_pb";
import { PolicyContext } from "@aserto/node-authorizer/src/gen/cjs/aserto/authorizer/v2/api/policy_context_pb";
import { PolicyInstance } from "@aserto/node-authorizer/src/gen/cjs/aserto/authorizer/v2/api/policy_instance_pb";
import { CallOptions } from "@connectrpc/connect";

import { errorHandler } from "../errorHandler";
import { Authorizer } from ".";
import { errorHandler } from "../errorHandler";
import JWTIdentityMapper from "./mapper/identity/jwt";
import PolicyPathMapper from "./mapper/policy/path";
import checkResourceMapper from "./mapper/resource/check";
Expand All @@ -14,14 +15,6 @@ import policyContext from "./model/policyContext";
import policyInstance from "./model/policyInstance";
import { ResourceContext } from "./model/resourceContext";

type Policy = {
root: string;
name?: string;
instanceLabel?: string;
decision?: string;
path?: string;
};

export type CheckOptions = {
object?: ObjectMapper;
objectId?: string | StringMapper;
Expand All @@ -30,16 +23,24 @@ export type CheckOptions = {
subjectType?: string;
};

export type ResourceMapper =
| ResourceContext
| ((req?: Request) => Promise<ResourceContext>);

export type IdentityMapper = (req: Request) => Promise<IdentityContext>;

export type PolicyMapper = (req?: Request) => Promise<PolicyContext>;

export type ResourceMapper =
| ((req?: Request) => Promise<ResourceContext>)
| ResourceContext;
type ObjectMapper = (
req?: Request,
) => Promise<{ objectId: string; objectType: string }>;

type Policy = {
root: string;
name?: string;
instanceLabel?: string;
decision?: string;
path?: string;
};
type StringMapper = (req?: Request) => Promise<string>;

export class Middleware {
Expand Down
4 changes: 2 additions & 2 deletions lib/authorizer/model/resourceContext.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { JsonObject } from "@bufbuild/protobuf";

export type ResourceContext = JsonObject;

export type CheckResourceContext = {
relation: string;
object_type: string;
object_id: string;
subject_type: string;
};

export type ResourceContext = JsonObject;
Loading