Skip to content

Commit

Permalink
added authorization provider functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
imolorhe committed Mar 30, 2024
1 parent f9f713e commit c11f8ab
Show file tree
Hide file tree
Showing 56 changed files with 1,110 additions and 175 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
root: true,
// root: true,
extends: ['altair'],
};
15 changes: 14 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1 +1,14 @@
"prettier-config-altair"
{
"semi": true,
"trailingComma": "es5",
"singleQuote": true,
"printWidth": 80,
"overrides": [
{
"files": "tsconfig.json",
"options": {
"trailingComma": "none"
}
}
]
}
18 changes: 17 additions & 1 deletion libs/eslint-config-altair/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,23 @@ module.exports = {
],
plugins: ['@typescript-eslint', 'import', 'prettier', 'no-unsanitized'],
rules: {
'prettier/prettier': 'warn',
'prettier/prettier': [
'warn',
{
semi: true,
trailingComma: 'es5',
singleQuote: true,
printWidth: 85,
overrides: [
{
files: 'tsconfig.json',
options: {
trailingComma: 'none',
},
},
],
},
],
'@typescript-eslint/no-unused-vars': 'warn',
'import/no-unresolved': 0,
'require-jsdoc': 'off',
Expand Down
1 change: 0 additions & 1 deletion libs/eslint-config-altair/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"eslint-plugin-no-unsanitized": "^4.0.2",
"eslint-plugin-prettier": "^4.2.1",
"prettier": "^2.8.1",
"prettier-config-altair": "^6.3.1",
"typescript": "5.2.2"
},
"license": "MIT",
Expand Down
14 changes: 0 additions & 14 deletions libs/prettier-config/index.js

This file was deleted.

7 changes: 0 additions & 7 deletions libs/prettier-config/package.json

This file was deleted.

1 change: 0 additions & 1 deletion packages/altair-api/.prettierrc

This file was deleted.

1 change: 0 additions & 1 deletion packages/altair-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
"passport-custom": "^1.1.1",
"pino-pretty": "^9.2.0",
"prettier": "^2.3.2",
"prettier-config-altair": "^6.3.1",
"prisma": "^4.9.0",
"source-map-support": "^0.5.20",
"supertest": "^6.1.3",
Expand Down
1 change: 0 additions & 1 deletion packages/altair-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@
"ncp": "2.0.0",
"ng-mocks": "^14.12.1",
"ngrx-store-freeze": "0.2.4",
"prettier-config-altair": "^6.3.1",
"protractor": "7.0.0",
"react": "17.0.1",
"rxjs-tslint-rules": "4.32.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<form nz-form nzLayout="vertical" [formGroup]="apiKeyForm">
<nz-form-item>
<nz-form-label nzRequired nzFor="key">Key</nz-form-label>
<nz-form-control [nzSm]="14" [nzXs]="24" nzErrorTip="The input is not a valid key!">
<input nz-input formControlName="key" id="key" class="app-input" />
</nz-form-control>
</nz-form-item>
<nz-form-item>
<nz-form-label nzRequired nzFor="value">Value</nz-form-label>
<nz-form-control [nzSm]="14" [nzXs]="24" nzErrorTip="The input is not a valid value!">
<input nz-input formControlName="value" id="value" class="app-input" />
</nz-form-control>
</nz-form-item>
</form>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { AuthorizationApikeyComponent } from './authorization-apikey.component';

describe('AuthorizationApikeyComponent', () => {
let component: AuthorizationApikeyComponent;
let fixture: ComponentFixture<AuthorizationApikeyComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [AuthorizationApikeyComponent]
})
.compileComponents();

fixture = TestBed.createComponent(AuthorizationApikeyComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Component, Input, OnInit, Output } from '@angular/core';
import { NonNullableFormBuilder } from '@angular/forms';
import { SharedModule } from 'app/modules/altair/modules/shared/shared.module';

@Component({
selector: 'app-authorization-apikey',
standalone: true,
imports: [SharedModule],
templateUrl: './authorization-apikey.component.html',
styles: ``,
})
export class AuthorizationApikeyComponent implements OnInit {
apiKeyForm = this.formBuilder.group({
key: '',
value: '',
});
@Input() authData?: unknown;
@Output() authDataChange = this.apiKeyForm.valueChanges;

constructor(private readonly formBuilder: NonNullableFormBuilder) {}

ngOnInit(): void {
if (this.authData) {
this.apiKeyForm.patchValue(this.authData);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<form nz-form nzLayout="vertical" [formGroup]="basicForm">
<nz-form-item>
<nz-form-label nzRequired nzFor="username">Username</nz-form-label>
<nz-form-control [nzSm]="14" [nzXs]="24" nzErrorTip="The input is not a valid username!">
<input nz-input formControlName="username" id="username" class="app-input" />
</nz-form-control>
</nz-form-item>
<nz-form-item>
<nz-form-label nzRequired nzFor="password">Password</nz-form-label>
<nz-form-control [nzSm]="14" [nzXs]="24" nzErrorTip="The input is not a valid password!">
<input nz-input formControlName="password" id="password" class="app-input" type="password" />
</nz-form-control>
</nz-form-item>
</form>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { AuthorizationBasicComponent } from './authorization-basic.component';

describe('AuthorizationBasicComponent', () => {
let component: AuthorizationBasicComponent;
let fixture: ComponentFixture<AuthorizationBasicComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [AuthorizationBasicComponent]
})
.compileComponents();

fixture = TestBed.createComponent(AuthorizationBasicComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Component, Input, OnInit, Output } from '@angular/core';
import { NonNullableFormBuilder } from '@angular/forms';
import { SharedModule } from 'app/modules/altair/modules/shared/shared.module';

@Component({
selector: 'app-authorization-basic',
standalone: true,
imports: [SharedModule],
templateUrl: './authorization-basic.component.html',
styles: ``,
})
export class AuthorizationBasicComponent implements OnInit {
basicForm = this.formBuilder.group({
username: '',
password: '',
});
@Input() authData?: unknown;
@Output() authDataChange = this.basicForm.valueChanges;

constructor(private readonly formBuilder: NonNullableFormBuilder) {}

ngOnInit(): void {
if (this.authData) {
this.basicForm.patchValue(this.authData);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<form nz-form nzLayout="vertical" [formGroup]="bearerForm">
<nz-form-item>
<nz-form-label nzRequired nzFor="token">Bearer token</nz-form-label>
<nz-form-control [nzSm]="14" [nzXs]="24" nzErrorTip="The input is not a valid bearer token!">
<input nz-input formControlName="token" id="token" class="app-input" />
</nz-form-control>
</nz-form-item>
</form>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { AuthorizationBearerComponent } from './authorization-bearer.component';

describe('AuthorizationBearerComponent', () => {
let component: AuthorizationBearerComponent;
let fixture: ComponentFixture<AuthorizationBearerComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [AuthorizationBearerComponent]
})
.compileComponents();

fixture = TestBed.createComponent(AuthorizationBearerComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Component, Input, OnInit, Output } from '@angular/core';
import { NonNullableFormBuilder } from '@angular/forms';
import { SharedModule } from 'app/modules/altair/modules/shared/shared.module';

@Component({
selector: 'app-authorization-bearer',
standalone: true,
imports: [SharedModule],
templateUrl: './authorization-bearer.component.html',
styles: ``,
})
export class AuthorizationBearerComponent implements OnInit {
bearerForm = this.formBuilder.group({
token: '',
});
@Input() authData?: unknown;
@Output() authDataChange = this.bearerForm.valueChanges;

constructor(private readonly formBuilder: NonNullableFormBuilder) {}

ngOnInit(): void {
if (this.authData) {
this.bearerForm.patchValue(this.authData);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<form nz-form nzLayout="vertical" [formGroup]="typeForm">
<nz-form-item>
<nz-form-label>{{ 'AUTHORIZATION_TYPE_TEXT' | translate }}</nz-form-label>
<nz-form-control [nzSm]="6" nzErrorTip="The input is not a valid type!">
<nz-select formControlName="type">
@for (item of AUTH_TYPES; track $index) {
<nz-option [nzValue]="item" [nzLabel]="AUTH_MAPPING[item].copy | translate"></nz-option>
}
</nz-select>
</nz-form-control>
</nz-form-item>
</form>
@switch (typeForm.controls.type.value) {
@case ('api-key') {
<app-authorization-apikey
[authData]="authorizationState?.data"
(authDataChange)="authDataChange.emit($event)"
/>
}
@case ('basic') {
<app-authorization-basic
[authData]="authorizationState?.data"
(authDataChange)="authDataChange.emit($event)"
/>
}
@case ('bearer') {
<app-authorization-bearer
[authData]="authorizationState?.data"
(authDataChange)="authDataChange.emit($event)"
/>
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { AuthorizationEditorComponent } from './authorization-editor.component';

describe('AuthorizationEditorComponent', () => {
let component: AuthorizationEditorComponent;
let fixture: ComponentFixture<AuthorizationEditorComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [AuthorizationEditorComponent]
})
.compileComponents();

fixture = TestBed.createComponent(AuthorizationEditorComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { NonNullableFormBuilder } from '@angular/forms';
import {
AUTHORIZATION_TYPES,
AUTHORIZATION_TYPE_LIST,
AuthorizationState,
AuthorizationTypes,
DEFAULT_AUTHORIZATION_TYPE,
} from 'altair-graphql-core/build/types/state/authorization.interface';
import { distinctUntilChanged, map } from 'rxjs/operators';
import { AUTHORIZATION_MAPPING } from '../authorizations';

@Component({
selector: 'app-authorization-editor',
templateUrl: './authorization-editor.component.html',
styles: ``,
})
export class AuthorizationEditorComponent implements OnInit {
typeForm = this.formBuilder.group<{
type: AuthorizationTypes;
}>({
type: DEFAULT_AUTHORIZATION_TYPE,
});

@Input() authorizationState?: AuthorizationState;
@Output() authTypeChange = this.typeForm.valueChanges.pipe(
map(({ type }) => type ?? DEFAULT_AUTHORIZATION_TYPE),
distinctUntilChanged()
);
@Output() authDataChange = new EventEmitter();
AUTH_MAPPING = AUTHORIZATION_MAPPING;
AUTH_TYPES = AUTHORIZATION_TYPE_LIST;

constructor(private readonly formBuilder: NonNullableFormBuilder) {}

ngOnInit(): void {
if (this.authorizationState) {
this.typeForm.patchValue({
type: this.authorizationState.type,
});
}
}
}
Loading

0 comments on commit c11f8ab

Please sign in to comment.