Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import {Deprecated, ProxyMap, Type} from "@tsed/core";
import {Provider, Service, ProviderType, InjectorService} from "@tsed/di";
import {UnknowFilterError} from "../errors/UnknowFilterError";
import {IFilter} from "../interfaces";
import {FilterRegistry} from "../registries/FilterRegistry";
/**
* @deprecated This service will be removed in a future release. Use injectorService directly.
*/
@Service()
export class FilterService extends ProxyMap | any, Provider> {
constructor(private injectorService: InjectorService) {
super(injectorService, {filter: {type: ProviderType.FILTER}});
}
/**
*
* @param target
* @returns {ControllerProvider}
*/
@Deprecated("static FilterService.get(). Removed feature.")
/* istanbul ignore next */
static get(target: Type): Provider | undefined {
return FilterRegistry.get(target);
}
import {Deprecated, ProxyMap, Type} from "@tsed/core";
import {Provider, Service, ProviderType, ProviderRegistry, InjectorService} from "@tsed/di";
import {UnknowMiddlewareError} from "../errors/UnknowMiddlewareError";
import {IMiddleware} from "../interfaces";
/**
* @deprecated This service will be removed in a future release. Use injectorService directly.
*/
@Service()
export class MiddlewareService extends ProxyMap | any, Provider> {
constructor(private injectorService: InjectorService) {
super(injectorService, {filter: {type: ProviderType.MIDDLEWARE}});
}
/**
*
* @param target
* @returns {Provider}
* @deprecated
*/
@Deprecated("static MiddlewareService.get(). Removed feature.")
/* istanbul ignore next */
static get(target: Type): Provider | undefined {
return ProviderRegistry.get(target);
}
import {Service} from "@tsed/di";
import * as Express from "express";
import {IServerMountDirectories} from "../../config";
import {ExpressApplication} from "../decorators/expressApplication";
@Service()
export class ServeStaticService {
constructor(@ExpressApplication private expressApp: Express.Application) {}
statics(statics: IServerMountDirectories) {
/* istanbul ignore else */
Object.keys(statics).forEach(path => {
[].concat(statics[path] as any).forEach((directory: string) => this.mount(path, directory));
});
}
mount(path: string, directory: string) {
const middleware = Express.static(directory);
this.expressApp.use(path, (request: any, response: any, next: any) => {
if (!response.headersSent) {
middleware(request, response, next);
} else {
import {Service} from "@tsed/di";
import {ITokenPayload} from "passport-azure-ad";
import {$log} from "@tsed/common";
import {TenantIdError} from "./errors/TenantIdError";
import {ClientIdError} from "./errors/ClientIdError";
import {InsufficientScopePermissions} from "./errors/InsufficientScopePermissions";
require("dotenv").config();
/**
* Customise this as required. Remember that Azure handles most user authentication/authorization so what
* happens here is only to provide functional benefits to the application. The Azure auth happens in the
* protocols / BearerStrategy class for passport-azure-ad.
*/
@Service()
export class AuthService {
owner = null;
scopes = process.env.Scopes ? process.env.Scopes.split(",") : [];
static getClientId(): string {
return process.env.clientId;
}
static getTenantId(): string {
return process.env.tenantId;
}
add(token: ITokenPayload) {
this.owner = token.oid;
}
import {Service} from "@tsed/di";
@Service()
export class ValidationService {
public validate(obj: any, targetType: any, baseType?: any): boolean {
return true;
}
}
import {JSONSchema6} from "json-schema";
import {ProxyRegistry, Type} from "@tsed/core";
import {Service} from "@tsed/di";
import {JsonSchema} from "../class/JsonSchema";
import {JsonSchemesRegistry} from "../registries/JsonSchemesRegistry";
@Service()
export class JsonSchemesService extends ProxyRegistry {
private cache: Map, JSONSchema6> = new Map();
constructor() {
super(JsonSchemesRegistry);
}
/**
*
* @param {Type} target
* @returns {JSONSchema4}
*/
getSchemaDefinition(target: Type): JSONSchema6 | undefined {
if (!this.cache.has(target)) {
this.cache.set(target, JsonSchemesRegistry.getSchemaDefinition(target));
}
import {Constant, InjectorService, Service} from "@tsed/di";
import {$log} from "ts-log-debug";
import {colorize} from "ts-log-debug/lib/layouts/utils/colorizeUtils";
import {AfterRoutesInit} from "../../server/interfaces/AfterRoutesInit";
import {ControllerProvider} from "../class/ControllerProvider";
import {EndpointMetadata} from "../class/EndpointMetadata";
import {IControllerRoute} from "../interfaces";
/**
* `RouteService` is used to provide all routes collected by annotation `@Controller`.
*/
@Service()
export class RouteService implements AfterRoutesInit {
/**
*
*/
@Constant("logger.disableRoutesSummary", false)
disableRoutesSummary: boolean;
private readonly _routes: {route: string; provider: any}[] = [];
constructor(private injector: InjectorService) {}
/**
*
* @returns {{route: string; provider: any}[]}
*/
get routes(): {route: string; provider: any}[] {
import {getValue, isEmpty} from "@tsed/core";
import {Service} from "@tsed/di";
/**
*
*/
@Service()
export class ParseService {
constructor() {}
/**
* Clone an object.
* @param src
*/
static clone = (src: any): any => JSON.parse(JSON.stringify(src));
/**
* Eval an expression with a scope context and return value.
* @param expression
* @param scope
* @param clone
* @returns {any}
*/
import {InjectorService, Service, TokenProvider} from "@tsed/di";
import {ExpressApplication} from "../../server/decorators/expressApplication";
import {IControllerRoute} from "../interfaces";
import {ControllerProvider} from "../models/ControllerProvider";
import {EndpointMetadata} from "../models/EndpointMetadata";
export interface IRouteProvider {
route: string;
provider: ControllerProvider;
}
/**
* `RouteService` is used to provide all routes collected by annotation `@Controller`.
*/
@Service()
export class RouteService {
private readonly _routes: IRouteProvider[] = [];
constructor(private injector: InjectorService, @ExpressApplication private expressApplication: ExpressApplication) {}
get routes(): IRouteProvider[] {
return this._routes || [];
}
/**
* Add a new route in the route registry
* @param endpoint
* @param token
*/
public addRoute(endpoint: string, token: TokenProvider) {
if (this.injector.hasProvider(token)) {