@seidor-cloud-produtos/orbit-backend-lib 0.0.12 → 0.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/clean-arch/infra/authorizations/authorizer.js +1 -0
- package/package.json +2 -3
- package/lib/clean-arch/application/queue/handler.ts +0 -3
- package/lib/clean-arch/application/queue/messages-in-memory.ts +0 -7
- package/lib/clean-arch/application/queue/queue-connection.ts +0 -7
- package/lib/clean-arch/application/queue/queue.ts +0 -11
- package/lib/clean-arch/domain/entities/aggregate-root.ts +0 -22
- package/lib/clean-arch/domain/entities/common-dto.ts +0 -16
- package/lib/clean-arch/domain/entities/entity.ts +0 -31
- package/lib/clean-arch/domain/entities/unique-entity-id.ts +0 -21
- package/lib/clean-arch/domain/entities/value-object.ts +0 -7
- package/lib/clean-arch/domain/entities/watched-list.spec.ts +0 -65
- package/lib/clean-arch/domain/entities/watched-list.ts +0 -130
- package/lib/clean-arch/domain/errors/application-error.ts +0 -8
- package/lib/clean-arch/domain/errors/domain-error.ts +0 -8
- package/lib/clean-arch/domain/errors/validation-error.ts +0 -17
- package/lib/clean-arch/domain/events/domain-event.ts +0 -4
- package/lib/clean-arch/domain/types/optional.ts +0 -1
- package/lib/clean-arch/infra/adapters/express-adapter.ts +0 -49
- package/lib/clean-arch/infra/adapters/fastify-adapter.ts +0 -66
- package/lib/clean-arch/infra/authorizations/authorization.ts +0 -47
- package/lib/clean-arch/infra/authorizations/authorizer.spec.ts +0 -156
- package/lib/clean-arch/infra/authorizations/authorizer.ts +0 -22
- package/lib/clean-arch/infra/authorizations/not-allowed.ts +0 -8
- package/lib/clean-arch/infra/errors/infra-error.ts +0 -8
- package/lib/clean-arch/infra/http/controller.ts +0 -93
- package/lib/clean-arch/infra/http/handle-bool-filter.ts +0 -7
- package/lib/clean-arch/infra/http/handle-is-active-query.ts +0 -7
- package/lib/clean-arch/infra/http/handle-sort-param-query.ts +0 -12
- package/lib/clean-arch/infra/http/handle-user-headers.ts +0 -13
- package/lib/clean-arch/infra/http/health-connections.ts +0 -21
- package/lib/clean-arch/infra/http/http.ts +0 -7
- package/lib/clean-arch/shared/pagination/dto-response.ts +0 -5
- package/lib/clean-arch/shared/pagination/get-take-and-skip.ts +0 -6
- package/lib/clean-arch/shared/pagination/pagination.ts +0 -8
- package/lib/frameworks/express/authorizations/authorization-express.spec.ts +0 -107
- package/lib/frameworks/express/authorizations/authorization-express.ts +0 -54
- package/lib/frameworks/express/authorizations/midleware-express.ts +0 -16
- package/lib/frameworks/nest/authorizations/guard-nest.ts +0 -24
- package/lib/index.ts +0 -1
- package/lib/infra/authorizations/auth-matcher.spec.ts +0 -130
- package/lib/infra/authorizations/auth-matcher.ts +0 -76
- package/lib/infra/authorizations/validator/api/api-validator.ts +0 -37
- package/lib/infra/authorizations/validator/api/factories/unauthorized-response-factory.spec.ts +0 -126
- package/lib/infra/authorizations/validator/api/factories/unauthorized-response-factory.ts +0 -51
- package/lib/infra/authorizations/validator/auth-validator.spec.ts +0 -82
- package/lib/infra/authorizations/validator/auth-validator.ts +0 -35
- package/lib/infra/http/errors/api-common-error.ts +0 -25
- package/lib/infra/http/errors/api-error.ts +0 -13
- package/lib/infra/http/errors/unauthorized-response.ts +0 -7
- package/lib/node_modules/.vitest/results.json +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@seidor-cloud-produtos/orbit-backend-lib",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.14",
|
|
4
4
|
"description": "Internal lib for backend components",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -22,8 +22,7 @@
|
|
|
22
22
|
]
|
|
23
23
|
},
|
|
24
24
|
"files": [
|
|
25
|
-
"dist"
|
|
26
|
-
"lib"
|
|
25
|
+
"dist"
|
|
27
26
|
],
|
|
28
27
|
"repository": {
|
|
29
28
|
"type": "git",
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import DomainEvent from '../../domain/events/domain-event';
|
|
2
|
-
import Handler from './handler';
|
|
3
|
-
|
|
4
|
-
export default interface Queue {
|
|
5
|
-
on(queueName: string, callback: Handler): Promise<void>;
|
|
6
|
-
publish(
|
|
7
|
-
exchangeName: string,
|
|
8
|
-
domainEvent: DomainEvent,
|
|
9
|
-
configs?: Record<string, any>,
|
|
10
|
-
): Promise<void>;
|
|
11
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { CommonDTO } from './common-dto';
|
|
2
|
-
import { Entity } from './entity';
|
|
3
|
-
|
|
4
|
-
export abstract class AggregateRoot<
|
|
5
|
-
Props extends CommonDTO,
|
|
6
|
-
> extends Entity<Props> {
|
|
7
|
-
get createdAt() {
|
|
8
|
-
return this.props.createdAt;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
set createdAt(date: Date) {
|
|
12
|
-
this.props.createdAt = date;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
get updatedAt(): Date | undefined {
|
|
16
|
-
return this.props.updatedAt;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
public touch() {
|
|
20
|
-
this.props.updatedAt = new Date();
|
|
21
|
-
}
|
|
22
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export type CommonDTO = {
|
|
2
|
-
createdAt: Date;
|
|
3
|
-
updatedAt?: Date;
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
export type CreateCommonDTO = {
|
|
7
|
-
createdAt?: Date;
|
|
8
|
-
updatedAt?: Date;
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export type UserRequestDTO = {
|
|
12
|
-
createdByName: string;
|
|
13
|
-
createdByEmail: string;
|
|
14
|
-
updatedByName: string;
|
|
15
|
-
updatedByEmail: string;
|
|
16
|
-
};
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { UniqueEntityId } from './unique-entity-id';
|
|
2
|
-
|
|
3
|
-
export abstract class Entity<Props> {
|
|
4
|
-
private _id: UniqueEntityId;
|
|
5
|
-
protected props: Props;
|
|
6
|
-
|
|
7
|
-
get id() {
|
|
8
|
-
return this._id;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
set id(id: UniqueEntityId) {
|
|
12
|
-
this._id = id;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
protected constructor(props: Props, id?: UniqueEntityId) {
|
|
16
|
-
this._id = id ?? new UniqueEntityId(id);
|
|
17
|
-
this.props = props;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
public equals(entity: Entity<any>) {
|
|
21
|
-
if (entity === this) {
|
|
22
|
-
return true;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
if (entity.id === this._id) {
|
|
26
|
-
return true;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return false;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { randomUUID } from 'node:crypto';
|
|
2
|
-
|
|
3
|
-
export class UniqueEntityId {
|
|
4
|
-
private value: string;
|
|
5
|
-
|
|
6
|
-
constructor(value?: string) {
|
|
7
|
-
this.value = value ?? randomUUID();
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
toString() {
|
|
11
|
-
return this.value;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
toValue() {
|
|
15
|
-
return this.value;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
public equals(id: UniqueEntityId) {
|
|
19
|
-
return id.toValue() === this.toValue();
|
|
20
|
-
}
|
|
21
|
-
}
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { WatchedList } from './watched-list';
|
|
2
|
-
|
|
3
|
-
class NumberWatchedList extends WatchedList<number> {
|
|
4
|
-
compareItems(a: number, b: number): boolean {
|
|
5
|
-
return a === b;
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
describe('Watched List', () => {
|
|
10
|
-
it('should be able to create a watched list with initial items', () => {
|
|
11
|
-
const list = new NumberWatchedList([1, 2, 3]);
|
|
12
|
-
|
|
13
|
-
expect(list.currentItems).toHaveLength(3);
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
it('should be able to add new items to the list', () => {
|
|
17
|
-
const list = new NumberWatchedList([1, 2, 3]);
|
|
18
|
-
|
|
19
|
-
list.add(4);
|
|
20
|
-
|
|
21
|
-
expect(list.currentItems).toHaveLength(4);
|
|
22
|
-
expect(list.getNewItems()).toEqual([4]);
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
it('should be able to add remove items from the list', () => {
|
|
26
|
-
const list = new NumberWatchedList([1, 2, 3]);
|
|
27
|
-
|
|
28
|
-
list.remove(2);
|
|
29
|
-
|
|
30
|
-
expect(list.currentItems).toHaveLength(2);
|
|
31
|
-
expect(list.getRemovedItems()).toEqual([2]);
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it('should be able to add an item even if it was removed before', () => {
|
|
35
|
-
const list = new NumberWatchedList([1, 2, 3]);
|
|
36
|
-
|
|
37
|
-
list.remove(2);
|
|
38
|
-
list.add(2);
|
|
39
|
-
|
|
40
|
-
expect(list.currentItems).toHaveLength(3);
|
|
41
|
-
expect(list.getRemovedItems()).toEqual([]);
|
|
42
|
-
expect(list.getNewItems()).toEqual([]);
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it('should be able to remove an item even if it was added before', () => {
|
|
46
|
-
const list = new NumberWatchedList([1, 2, 3]);
|
|
47
|
-
|
|
48
|
-
list.add(4);
|
|
49
|
-
list.remove(4);
|
|
50
|
-
|
|
51
|
-
expect(list.currentItems).toHaveLength(3);
|
|
52
|
-
expect(list.getRemovedItems()).toEqual([]);
|
|
53
|
-
expect(list.getNewItems()).toEqual([]);
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it('should be able to update watched list items', () => {
|
|
57
|
-
const list = new NumberWatchedList([1, 2, 3]);
|
|
58
|
-
|
|
59
|
-
list.update([1, 3, 5]);
|
|
60
|
-
|
|
61
|
-
expect(list.getRemovedItems()).toEqual([2]);
|
|
62
|
-
expect(list.getNewItems()).toEqual([5]);
|
|
63
|
-
expect(list.getUpdatedItems()).toEqual([1, 3]);
|
|
64
|
-
});
|
|
65
|
-
});
|
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
export abstract class WatchedList<T> {
|
|
2
|
-
public currentItems: T[];
|
|
3
|
-
private initial: T[];
|
|
4
|
-
private new: T[];
|
|
5
|
-
private removed: T[];
|
|
6
|
-
private updated: T[];
|
|
7
|
-
|
|
8
|
-
constructor(initialItems?: T[]) {
|
|
9
|
-
this.currentItems = initialItems || [];
|
|
10
|
-
this.initial = initialItems || [];
|
|
11
|
-
this.new = [];
|
|
12
|
-
this.removed = [];
|
|
13
|
-
this.updated = [];
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
abstract compareItems(a: T, b: T): boolean;
|
|
17
|
-
|
|
18
|
-
public getItems(): T[] {
|
|
19
|
-
return this.currentItems;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
public getNewItems(): T[] {
|
|
23
|
-
return this.new;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
public getRemovedItems(): T[] {
|
|
27
|
-
return this.removed;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
public getUpdatedItems(): T[] {
|
|
31
|
-
return this.updated;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
public addUpdatedItem(item: T) {
|
|
35
|
-
return this.updated.push(item);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
private isCurrentItem(item: T): boolean {
|
|
39
|
-
return (
|
|
40
|
-
this.currentItems.filter((v: T) => this.compareItems(item, v)).length !==
|
|
41
|
-
0
|
|
42
|
-
);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
private isNewItem(item: T): boolean {
|
|
46
|
-
return this.new.filter((v: T) => this.compareItems(item, v)).length !== 0;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
private isRemovedItem(item: T): boolean {
|
|
50
|
-
return (
|
|
51
|
-
this.removed.filter((v: T) => this.compareItems(item, v)).length !== 0
|
|
52
|
-
);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
private removeFromNew(item: T): void {
|
|
56
|
-
this.new = this.new.filter(v => !this.compareItems(v, item));
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
private removeFromCurrent(item: T): void {
|
|
60
|
-
this.currentItems = this.currentItems.filter(
|
|
61
|
-
v => !this.compareItems(item, v),
|
|
62
|
-
);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
private removeFromRemoved(item: T): void {
|
|
66
|
-
this.removed = this.removed.filter(v => !this.compareItems(item, v));
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
private wasAddedInitially(item: T): boolean {
|
|
70
|
-
return (
|
|
71
|
-
this.initial.filter((v: T) => this.compareItems(item, v)).length !== 0
|
|
72
|
-
);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
public exists(item: T): boolean {
|
|
76
|
-
return this.isCurrentItem(item);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
public add(item: T): void {
|
|
80
|
-
if (this.isRemovedItem(item)) {
|
|
81
|
-
this.removeFromRemoved(item);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
if (!this.isNewItem(item) && !this.wasAddedInitially(item)) {
|
|
85
|
-
this.new.push(item);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
if (!this.isCurrentItem(item)) {
|
|
89
|
-
this.currentItems.push(item);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
public remove(item: T): void {
|
|
94
|
-
this.removeFromCurrent(item);
|
|
95
|
-
|
|
96
|
-
if (this.isNewItem(item)) {
|
|
97
|
-
this.removeFromNew(item);
|
|
98
|
-
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
if (!this.isRemovedItem(item)) {
|
|
103
|
-
this.removed.push(item);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
public update(items: T[]): void {
|
|
108
|
-
const newItems = items.filter(a => {
|
|
109
|
-
return !this.getItems().some(b => this.compareItems(a, b));
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
const removedItems = this.getItems().filter(a => {
|
|
113
|
-
return !items.some(b => this.compareItems(a, b));
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
const updatedItems = items.filter(
|
|
117
|
-
item =>
|
|
118
|
-
!newItems.some(
|
|
119
|
-
a =>
|
|
120
|
-
this.compareItems(item, a) &&
|
|
121
|
-
!removedItems.some(b => this.compareItems(item, b)),
|
|
122
|
-
),
|
|
123
|
-
);
|
|
124
|
-
|
|
125
|
-
this.currentItems = items;
|
|
126
|
-
this.new = newItems;
|
|
127
|
-
this.removed = removedItems;
|
|
128
|
-
this.updated = updatedItems;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
type Errors = {
|
|
2
|
-
property: string;
|
|
3
|
-
message: string;
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
export default class ValidationError extends Error {
|
|
7
|
-
code: number;
|
|
8
|
-
|
|
9
|
-
errors: Errors[];
|
|
10
|
-
|
|
11
|
-
constructor(errors: Errors[]) {
|
|
12
|
-
super('Validation Error');
|
|
13
|
-
this.code = 400;
|
|
14
|
-
this.name = 'Validation Error';
|
|
15
|
-
this.errors = errors;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import cors from 'cors';
|
|
2
|
-
import express, { Request, Response, Express } from 'express';
|
|
3
|
-
|
|
4
|
-
import Controller from '../http/controller';
|
|
5
|
-
import Http, { MethodType } from '../http/http';
|
|
6
|
-
|
|
7
|
-
export default class ExpressAdapter implements Http {
|
|
8
|
-
readonly instance: Express;
|
|
9
|
-
private server: any;
|
|
10
|
-
|
|
11
|
-
constructor(readonly envs: Record<string, unknown>) {
|
|
12
|
-
this.instance = express();
|
|
13
|
-
this.instance.use(cors());
|
|
14
|
-
this.instance.use(express.json({ limit: '10mb' }));
|
|
15
|
-
this.instance.use(express.urlencoded({ limit: '10mb', extended: false }));
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
on(method: MethodType, url: string, callback: Controller): void {
|
|
19
|
-
this.instance[method](url, async (request: Request, response: Response) => {
|
|
20
|
-
try {
|
|
21
|
-
const requestData = {
|
|
22
|
-
body: request.body,
|
|
23
|
-
params: request.params,
|
|
24
|
-
headers: request.headers,
|
|
25
|
-
query: request.query,
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
const output = await callback.handle(requestData);
|
|
29
|
-
|
|
30
|
-
return response.status(output.code || 200).json(output.data || {});
|
|
31
|
-
} catch (err: any) {
|
|
32
|
-
const error = callback.throw(err);
|
|
33
|
-
return response.status(error.code).json(error.data || {});
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
async listen(port: number): Promise<void> {
|
|
39
|
-
this.server = this.instance.listen(port, () => {
|
|
40
|
-
if (this.envs.NODE_ENV !== 'test') {
|
|
41
|
-
console.log(`🚀 Server is running on PORT ${port}`);
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
async close() {
|
|
47
|
-
await this.server.close();
|
|
48
|
-
}
|
|
49
|
-
}
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import cors from '@fastify/cors';
|
|
2
|
-
import fastify, {
|
|
3
|
-
FastifyInstance,
|
|
4
|
-
FastifyRequest,
|
|
5
|
-
FastifyReply,
|
|
6
|
-
} from 'fastify';
|
|
7
|
-
import qs from 'qs';
|
|
8
|
-
|
|
9
|
-
import Controller, { Request } from '../http/controller';
|
|
10
|
-
import Http, { MethodType } from '../http/http';
|
|
11
|
-
|
|
12
|
-
export default class FastifyAdapter implements Http {
|
|
13
|
-
readonly instance: FastifyInstance;
|
|
14
|
-
|
|
15
|
-
constructor(readonly envs: Record<string, unknown>) {
|
|
16
|
-
this.instance = fastify({
|
|
17
|
-
bodyLimit: 10 * 1024 * 1024,
|
|
18
|
-
querystringParser: str => qs.parse(str),
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
this.instance.register(cors);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
on(method: MethodType, url: string, callback: Controller): void {
|
|
25
|
-
this.instance[method](
|
|
26
|
-
url,
|
|
27
|
-
async (request: FastifyRequest, reply: FastifyReply) => {
|
|
28
|
-
try {
|
|
29
|
-
const requestData = {
|
|
30
|
-
body: request.body,
|
|
31
|
-
params: request.params,
|
|
32
|
-
headers: request.headers,
|
|
33
|
-
query: request.query,
|
|
34
|
-
} as Request;
|
|
35
|
-
|
|
36
|
-
const output = await callback.handle(requestData);
|
|
37
|
-
|
|
38
|
-
return reply.status(output.code || 200).send(output.data || {});
|
|
39
|
-
} catch (err: any) {
|
|
40
|
-
const error = callback.throw(err);
|
|
41
|
-
return reply.status(error.code || 200).send(error.data || {});
|
|
42
|
-
}
|
|
43
|
-
},
|
|
44
|
-
);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
async listen(port: number): Promise<void> {
|
|
48
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
49
|
-
this.instance.listen({ port }, async (err, _) => {
|
|
50
|
-
if (err) {
|
|
51
|
-
console.error(err);
|
|
52
|
-
process.exit();
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
await this.instance?.ready();
|
|
56
|
-
|
|
57
|
-
if (this.envs.NODE_ENV !== 'test') {
|
|
58
|
-
console.log(`🚀 Server is running on PORT ${port}`);
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
async close() {
|
|
64
|
-
await this.instance.close();
|
|
65
|
-
}
|
|
66
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { AuthParams } from '../../../infra/authorizations/auth-matcher';
|
|
2
|
-
import { APIAuthValidator } from '../../../infra/authorizations/validator/api/api-validator';
|
|
3
|
-
import AuthValidator from '../../../infra/authorizations/validator/auth-validator';
|
|
4
|
-
import { UnauthorizedResponse } from '../../../infra/http/errors/unauthorized-response';
|
|
5
|
-
import { Request, Response } from '../http/controller';
|
|
6
|
-
import NotAllowedError from './not-allowed';
|
|
7
|
-
|
|
8
|
-
type AuthorizationMetaData = {
|
|
9
|
-
handle(input: Request): Promise<Response>;
|
|
10
|
-
request: Request;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export default class Authorization extends APIAuthValidator {
|
|
14
|
-
declare controller: AuthorizationMetaData;
|
|
15
|
-
|
|
16
|
-
public static async create(
|
|
17
|
-
query: AuthParams,
|
|
18
|
-
controllerMetaData: AuthorizationMetaData,
|
|
19
|
-
): Promise<AuthValidator> {
|
|
20
|
-
const instance = new Authorization(query, controllerMetaData);
|
|
21
|
-
|
|
22
|
-
return await instance.setup();
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
protected unauthorize(response: UnauthorizedResponse) {
|
|
26
|
-
throw new NotAllowedError(response);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
protected getRequestId(): string {
|
|
30
|
-
return this.controller.request.headers['X-Amzn-Requestid'] as string;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
protected async getAuthorizations(): Promise<string[]> {
|
|
34
|
-
const authorizations = this.controller.request.headers
|
|
35
|
-
.authorizations as string;
|
|
36
|
-
|
|
37
|
-
if (typeof authorizations === 'string') {
|
|
38
|
-
return JSON.parse(authorizations);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return authorizations;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
protected handleAuthorized() {
|
|
45
|
-
return this.controller.handle(this.controller.request);
|
|
46
|
-
}
|
|
47
|
-
}
|