Socket
Socket
Sign inDemoInstall

fulton-server

Package Overview
Dependencies
218
Maintainers
1
Versions
62
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.19 to 0.0.20

identity/options/notification-Options.d.ts

6

entities/entity-service.d.ts

@@ -0,7 +1,7 @@

import { ColumnMetadata } from 'typeorm/metadata/ColumnMetadata';
import { IEntityService, OperationManyResult, OperationOneResult, OperationResult, QueryParams, Type } from '../interfaces';
import { MongoRepository, Repository } from 'typeorm';
import { ColumnMetadata } from 'typeorm/metadata/ColumnMetadata';
import { EntityMetadata } from 'typeorm/metadata/EntityMetadata';
import { EntityRunner } from './runner/entity-runner';
import { IFultonApp } from "../fulton-app";
import { MongoRepository, Repository } from 'typeorm';
import { IFultonApp } from '../fulton-app';
import { IUser } from '../identity';

@@ -8,0 +8,0 @@ export declare class EntityService<TEntity> implements IEntityService<TEntity> {

@@ -13,7 +13,8 @@ "use strict";

const lodash = require("lodash");
const keys_1 = require("../keys");
const interfaces_1 = require("../interfaces");
const fulton_error_1 = require("../common/fulton-error");
const fulton_log_1 = require("../fulton-log");
const typeorm_1 = require("typeorm");
const class_validator_1 = require("class-validator");
const fulton_log_1 = require("../fulton-log");
let EntityService = class EntityService {

@@ -31,3 +32,3 @@ constructor(input) {

if (this.mainRepository instanceof typeorm_1.MongoRepository) {
this._runner = this.app.container.get(interfaces_1.DiKeys.MongoEntityRunner);
this._runner = this.app.container.get(keys_1.DiKeys.MongoEntityRunner);
}

@@ -277,3 +278,3 @@ else {

__decorate([
interfaces_1.inject(interfaces_1.DiKeys.FultonApp),
interfaces_1.inject(keys_1.DiKeys.FultonApp),
__metadata("design:type", Object)

@@ -280,0 +281,0 @@ ], EntityService.prototype, "app", void 0);

@@ -5,3 +5,3 @@ /// <reference types="express" />

import * as https from 'https';
import { AppMode, DiContainer, Type, TypeIdentifier } from './interfaces';
import { AppMode, DiContainer, Type, TypeIdentifier, NotificationMessage } from './interfaces';
import { Provider } from "./helpers/type-helpers";

@@ -13,3 +13,3 @@ import { Connection, Repository } from 'typeorm';

import { Express } from "express";
import { FultonAppOptions } from "./fulton-app-options";
import { FultonAppOptions } from "./options/fulton-app-options";
import { Router } from "./routers/router";

@@ -38,2 +38,3 @@ export interface IFultonApp {

getRepository<T>(entity: Type, connectionName?: string): Repository<T>;
sendNotifications(...messages: NotificationMessage[]): Promise<void>;
}

@@ -124,2 +125,3 @@ /**

getRepository<T>(entity: Type, connectionName?: string): Repository<T>;
sendNotifications(...messages: NotificationMessage[]): Promise<void>;
protected initServer(): void | Promise<void>;

@@ -139,2 +141,3 @@ protected initDiContainer(): void | Promise<void>;

protected initCors(): void | Promise<void>;
protected initCompression(): void | Promise<void>;
protected initMiddlewares(): void | Promise<void>;

@@ -146,2 +149,3 @@ protected initFormatter(): void | Promise<void>;

protected registerTypes(providers: Provider[], singleton?: boolean): TypeIdentifier[];
notify(...messages: NotificationMessage[]): void;
/**

@@ -148,0 +152,0 @@ * to init the app. Env values for options will be loaded after onInit.

@@ -13,2 +13,3 @@ "use strict";

const express = require("express");
const compression = require("compression");
const http = require("http");

@@ -20,7 +21,7 @@ const https = require("https");

const winston = require("winston");
const interfaces_1 = require("./interfaces");
const keys_1 = require("./keys");
const typeorm_1 = require("typeorm");
const env_1 = require("./helpers/env");
const events_1 = require("events");
const fulton_app_options_1 = require("./fulton-app-options");
const fulton_app_options_1 = require("./options/fulton-app-options");
const fulton_log_1 = require("./fulton-log");

@@ -43,3 +44,3 @@ const http_logger_1 = require("./middlewares/http-logger");

this.serve = (req, res) => {
if (this.options.settings.zoneEnabled) {
if (this.options.miscellaneous.zoneEnabled) {
Zone.current.fork({

@@ -73,3 +74,3 @@ name: this.appName,

getLocalData(key) {
if (this.options.settings.zoneEnabled) {
if (this.options.miscellaneous.zoneEnabled) {
let res = Zone.current.get("res");

@@ -85,3 +86,3 @@ if (res) {

setLocalData(key, value) {
if (this.options.settings.zoneEnabled) {
if (this.options.miscellaneous.zoneEnabled) {
let res = Zone.current.get("res");

@@ -103,3 +104,3 @@ if (res) {

yield this.onInit(this.options);
this.options.loadEnvOptions();
this.options.init();
yield this.initLogging();

@@ -112,2 +113,3 @@ yield this.initProviders();

yield this.initCors();
yield this.initCompression();
yield this.initFormatter();

@@ -123,3 +125,3 @@ yield this.initIdentity();

this.isInitialized = true;
this.events.emit(interfaces_1.EventKeys.didInit, this);
this.events.emit(keys_1.EventKeys.AppDidInit, this);
debug_1.fultonDebugMaster("app", "Initializing with options: %O\t", this.options);

@@ -141,3 +143,3 @@ }

}
if (this.options.settings.zoneEnabled) {
if (this.options.miscellaneous.zoneEnabled) {
require("zone.js");

@@ -235,2 +237,6 @@ }

}
sendNotifications(...messages) {
var service = this.container.get(keys_1.DiKeys.NotificationService);
return service.send(...messages);
}
initServer() {

@@ -240,3 +246,3 @@ this.express = express();

this.express.disable('x-powered-by');
this.events.emit(interfaces_1.EventKeys.didInitServer, this);
this.events.emit(keys_1.EventKeys.AppDidInitServer, this);
}

@@ -258,7 +264,7 @@ initDiContainer() {

}
this.events.emit(interfaces_1.EventKeys.didInitLogging, this);
this.events.emit(keys_1.EventKeys.AppDidInitLogging, this);
}
initProviders() {
this.registerTypes(this.options.providers || []);
this.events.emit(interfaces_1.EventKeys.didInitProviders, this);
this.events.emit(keys_1.EventKeys.AppDidInitProviders, this);
}

@@ -273,10 +279,3 @@ /**

return __awaiter(this, void 0, void 0, function* () {
let providers = this.options.services || [];
if (this.options.loader.serviceLoaderEnabled) {
let dirs = this.options.loader.serviceDirs.map((dir) => path.join(this.options.loader.appDir, dir));
let loadedProviders = yield this.options.loader.serviceLoader(dirs, true);
providers = loadedProviders.concat(providers);
}
this.registerTypes(providers);
this.events.emit(interfaces_1.EventKeys.didInitServices, this);
return require('./initializers/service-initializer')(this);
});

@@ -289,3 +288,3 @@ }

return promise.then(() => {
this.events.emit(interfaces_1.EventKeys.didInitIdentity, this);
this.events.emit(keys_1.EventKeys.AppDidInitIdentity, this);
});

@@ -311,3 +310,3 @@ }

});
this.events.emit(interfaces_1.EventKeys.didInitRouters, this);
this.events.emit(keys_1.EventKeys.AppDidInitRouters, this);
});

@@ -323,3 +322,3 @@ }

}
this.events.emit(interfaces_1.EventKeys.didInitHttpLogging, this);
this.events.emit(keys_1.EventKeys.AppDidInitHttpLogging, this);
}

@@ -349,3 +348,3 @@ }

}
this.events.emit(interfaces_1.EventKeys.didInitStaticFile, this);
this.events.emit(keys_1.EventKeys.AppDidInitStaticFile, this);
}

@@ -361,9 +360,20 @@ }

}
this.events.emit(interfaces_1.EventKeys.didInitCors, this);
this.events.emit(keys_1.EventKeys.AppDidInitCors, this);
}
}
initCompression() {
if (this.options.compression.enabled) {
if (lodash.some(this.options.compression.middlewares)) {
this.express.use(...this.options.compression.middlewares);
}
else {
this.express.use(compression(this.options.compression.options));
}
this.events.emit(keys_1.EventKeys.AppDidInitCompression, this);
}
}
initMiddlewares() {
if (lodash.some(this.options.middlewares)) {
this.express.use(...this.options.middlewares);
this.events.emit(interfaces_1.EventKeys.didInitMiddlewares, this);
this.events.emit(keys_1.EventKeys.AppDidInitMiddlewares, this);
}

@@ -391,3 +401,3 @@ }

}
this.events.emit(interfaces_1.EventKeys.didInitIndex, this);
this.events.emit(keys_1.EventKeys.AppDidInitIndex, this);
}

@@ -402,3 +412,3 @@ initErrorHandler() {

}
this.events.emit(interfaces_1.EventKeys.didInitErrorHandler, this);
this.events.emit(keys_1.EventKeys.AppDidInitErrorHandler, this);
}

@@ -456,3 +466,5 @@ }

}
notify(...messages) {
}
}
exports.FultonApp = FultonApp;

@@ -17,3 +17,3 @@ /// <reference types="express" />

/**
* check the request is authenticated.
* check the currect request is authorized.
* @param options

@@ -29,3 +29,3 @@ */

/**
* authorize the current user has of the roles
* authorize the current user has one of the roles
* @param roles

@@ -32,0 +32,0 @@ * @param options

@@ -5,3 +5,3 @@ "use strict";

/**
* check the request is authenticated.
* check the currect request is authorized.
* @param options

@@ -41,3 +41,3 @@ */

/**
* authorize the current user has of the roles
* authorize the current user has one of the roles
* @param roles

@@ -44,0 +44,0 @@ * @param options

@@ -1,4 +0,4 @@

import { AccessToken, IProfile, IUserRegister, IUserService } from "../interfaces";
import { AccessToken, IProfile, IUserRegister, IUserService } from '../interfaces';
import { FultonUser } from './fulton-user';
import { IFultonApp } from "../../fulton-app";
import { IFultonApp } from '../../fulton-app';
export declare class FultonUserService implements IUserService<FultonUser> {

@@ -19,2 +19,3 @@ protected app: IFultonApp;

private readonly cipherPassword;
private sendWelcomeNotification(user);
}

@@ -28,6 +28,7 @@ "use strict";

const validator = require("validator");
const interfaces_1 = require("../../interfaces");
const keys_1 = require("../../keys");
const typeorm_1 = require("typeorm");
const fulton_user_1 = require("./fulton-user");
const common_1 = require("../../common");
const interfaces_1 = require("../../interfaces");
const bson_1 = require("bson");

@@ -111,3 +112,3 @@ class MongoRunner {

get currentUser() {
if (this.app.options.settings.zoneEnabled) {
if (this.app.options.miscellaneous.zoneEnabled) {
let res = Zone.current.get("res");

@@ -188,2 +189,4 @@ if (res) {

}
this.sendWelcomeNotification(user);
this.app.events.emit(keys_1.EventKeys.UserDidRegister, user);
return user;

@@ -341,8 +344,22 @@ });

}
sendWelcomeNotification(user) {
var opts = this.options.register.notiication;
if (opts.email.enabled) {
var message = {
email: {
to: user.email,
subjectTemplate: opts.email.subjectTemplate,
bodyTemplate: opts.email.bodyTemplate,
variables: user
}
};
this.app.sendNotifications(message);
}
}
};
FultonUserService = __decorate([
interfaces_1.injectable(),
__param(0, interfaces_1.inject(interfaces_1.DiKeys.FultonApp)),
__param(0, interfaces_1.inject(keys_1.DiKeys.FultonApp)),
__metadata("design:paramtypes", [Object])
], FultonUserService);
exports.FultonUserService = FultonUserService;

@@ -11,7 +11,7 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
const lodash = require("lodash");
const passport = require("passport");
const lodash = require("lodash");
const google_strategy_1 = require("./strategies/google-strategy");
const passport_local_1 = require("passport-local");
const passport_http_bearer_1 = require("passport-http-bearer");
const google_strategy_1 = require("./strategies/google-strategy");
module.exports = function identityInitializer(app) {

@@ -18,0 +18,0 @@ return __awaiter(this, void 0, void 0, function* () {

/// <reference types="node" />
/// <reference types="passport" />
import { AppMode, HttpMethod, Middleware, PathIdentifier, Type } from "../interfaces";
import { AppMode, HttpMethod, Middleware, PathIdentifier, Type } from '../interfaces';
import { AuthenticateOptions } from 'passport';
import { CustomStrategySettings, FacebookStrategyOptions, GoogleStrategyOptions, IUser, IUserService, LocalStrategyVerifier, OAuthStrategyOptions, StrategyOptions, TokenStrategyVerifier } from './interfaces';
import { AuthenticateOptions } from "passport";
import { Strategy } from "passport";
import { RegisterOptions } from './options/register-options';
import { Strategy } from 'passport';
export declare class IdentityOptions {
private appName;
private appModel;
private appMode;
/**

@@ -170,74 +171,3 @@ * the default value is false

*/
register: {
/**
* the default value is true
*/
enabled?: boolean;
/**
* the default value is /auth/login
*/
path?: PathIdentifier;
/**
* the default value is `post`
*/
httpMethod?: HttpMethod;
/**
* the default value email
*/
emailField?: string;
/**
* the default value username
*/
usernameField?: string;
/**
* the default value password
*/
passwordField?: string;
/**
* the options for hash password
*/
passwordHashOptions?: {
/**
* the default value is sha256
*/
algorithm?: string;
/**
* the default value is 8
*/
saltLength?: number;
/**
* the default value is 1
*/
iterations?: number;
};
session?: boolean;
/**
* accept other fields, like nickname or phone-number
* the default value is empty
*/
otherFields?: string[];
/**
* verify password is valid or not
* the default value is /^[a-zA-Z0-9_-]{4,64}$/
*/
usernameVerifier?: RegExp | ((username: string) => boolean);
/**
* verify password is valid or not
* the default value is /^\S{6,64}$/, any 4 to 64 non-whitespace characters
*/
passwordVerifier?: RegExp | ((pw: string) => boolean);
/**
* the handler for register
* the default value is fultonDefaultRegisterHandler
*/
handler?: Middleware;
/**
* either use successCallback or responseOptions for response
* the default value is sendAccessToken
*/
successCallback?: Middleware;
/**
*/
responseOptions?: AuthenticateOptions;
};
readonly register: RegisterOptions;
/**

@@ -352,4 +282,4 @@ * the local strategy for login, fulton doesn't have html for login,

*
* clientId can be overridden by process.env["{appName}.options.identity.google.clientId"]
* clientSecret can be overridden by process.env["{appName}.options.identity.google.clientSecret"]
* clientId can be overridden by env["{appName}.options.identity.google.clientId"]
* clientSecret can be overridden by env["{appName}.options.identity.google.clientSecret"]
*/

@@ -366,4 +296,4 @@ google: GoogleStrategyOptions;

*
* clientId can be overridden by process.env["{appName}.options.identity.github.clientId"]
* clientSecret can be overridden by process.env["{appName}.options.identity.github.clientSecret"]
* clientId can be overridden by env["{appName}.options.identity.github.clientId"]
* clientSecret can be overridden by env["{appName}.options.identity.github.clientSecret"]
*/

@@ -381,4 +311,4 @@ github: OAuthStrategyOptions;

*
* clientId can be overridden by process.env["{appName}.options.identity.facebook.clientId"]
* clientSecret can be overridden by process.env["{appName}.options.identity.facebook.clientSecret"]
* clientId can be overridden by env["{appName}.options.identity.facebook.clientId"]
* clientSecret can be overridden by env["{appName}.options.identity.facebook.clientSecret"]
*/

@@ -392,8 +322,8 @@ facebook: FacebookStrategyOptions;

readonly defaultAuthSupportStrategies: string[];
constructor(appName: string, appModel: AppMode);
constructor(appName: string, appMode: AppMode);
/**
* load options from environment to override the current options
*/
loadEnvOptions(): void;
init(): void;
addStrategy(options: StrategyOptions | OAuthStrategyOptions, strategy: Strategy | Type<Strategy>): void;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const lodash = require("lodash");
const env_1 = require("../helpers/env");
const fulton_user_1 = require("./fulton-impl/fulton-user");
const fulton_impl_1 = require("./fulton-impl/fulton-impl");
const fulton_user_1 = require("./fulton-impl/fulton-user");
const fulton_user_service_1 = require("./fulton-impl/fulton-user-service");
const register_options_1 = require("./options/register-options");
class IdentityOptions {
constructor(appName, appModel) {
constructor(appName, appMode) {
this.appName = appName;
this.appModel = appModel;
this.appMode = appMode;
/**
* the default value is false
* It can be overridden by process.env["{appName}.options.identity.enabled"]
*/
this.enabled = false;
/**
* the types of entities for registion,
* the default value is [FultonUser, FultonAccessToken, FultonOauthToken]
*/
this.entities = [fulton_user_1.FultonUser, fulton_user_1.FultonAccessToken, fulton_user_1.FultonOauthToken];
/**
* the instance or type of UserService
* the default value is FultonUserService
* it can be used like
* `req.userService`
*
* if your user schema is like FultonUser and auth strategies is
* username-password and bearer token, then you don't need to change this value,
* otherwise you have to custom your user service;
*/
this.userService = fulton_user_service_1.FultonUserService;
/**
* the setting for register, fulton doesn't have html for register,
*
* for render html, you have to add a router
*
* ## example for web view
* ```
* @router("/auth")
* export class AuthRouter extends Router {
* @httpGet("/register")
* registerView(req: Request, res: Response) {
* res.render("register");
* }
*
* // if you want to put all logics altogether
* // you can set options.identity.register.enabled = false
* // and add this action.
* @httpPost("/register"))
* register(req: Request, res: Response) {
* req.userService
* .register(req.body)
* .then(async(user)=> {
* res.redirect("/");
* .catch(()=>{
* res.sendStatus(400);
* });
* }
* }
* ```
*/
this.register = new register_options_1.RegisterOptions();
/** other passport strategies */

@@ -18,5 +70,2 @@ this.strategies = [];

this.defaultAuthSupportStrategies = [];
this.enabled = false;
this.userService = fulton_user_service_1.FultonUserService;
this.entities = [fulton_user_1.FultonUser, fulton_user_1.FultonAccessToken, fulton_user_1.FultonOauthToken];
this.defaultAuthorizes = [];

@@ -31,19 +80,2 @@ this.accessToken = {

this.defaultAuthenticateErrorIfFailure = false;
this.register = {
enabled: true,
path: "/auth/register",
httpMethod: "post",
usernameField: "username",
passwordField: "password",
emailField: "email",
usernameVerifier: /^[a-zA-Z0-9_-]{4,64}$/,
passwordVerifier: /\S{6,64}/,
passwordHashOptions: {
algorithm: "sha256"
},
session: false,
otherFields: [],
handler: fulton_impl_1.FultonImpl.registerHandler,
successCallback: fulton_impl_1.FultonImpl.issueAccessToken
};
this.login = {

@@ -90,6 +122,6 @@ enabled: true,

};
if (this.appModel == "api") {
if (this.appMode == "api") {
this.bearer.enabled = true;
}
else if (this.appModel == "web-view") {
else if (this.appMode == "web-view") {
this.bearer.enabled = false;

@@ -117,44 +149,17 @@ this.register.responseOptions = {

*/
loadEnvOptions() {
init() {
let prefix = `${this.appName}.options.identity`;
let envValues = {
enabled: env_1.Env.getBoolean(`${prefix}.enabled`),
register: {
enabled: env_1.Env.getBoolean(`${prefix}.register.enabled`)
},
login: {
enabled: env_1.Env.getBoolean(`${prefix}.login.enabled`)
},
bearer: {
enabled: env_1.Env.getBoolean(`${prefix}.login.enabled`)
},
google: {
enabled: env_1.Env.getBoolean(`${prefix}.google.enabled`),
clientId: env_1.Env.get(`${prefix}.google.clientId`),
clientSecret: env_1.Env.get(`${prefix}.google.clientSecret`)
},
github: {
enabled: env_1.Env.getBoolean(`${prefix}.github.enabled`),
clientId: env_1.Env.get(`${prefix}.github.clientId`),
clientSecret: env_1.Env.get(`${prefix}.github.clientSecret`)
},
facebook: {
enabled: env_1.Env.getBoolean(`${prefix}.facebook.enabled`),
clientId: env_1.Env.get(`${prefix}.facebook.clientId`),
clientSecret: env_1.Env.get(`${prefix}.facebook.clientSecret`)
}
};
let customer = (a, b) => {
if (a == null && b == null) {
// lodash don't understand null
return undefined;
}
if (typeof a == "object") {
return lodash.assignWith(a, b, customer);
}
else {
return b == null ? a : b;
}
};
lodash.assignWith(this, envValues, customer);
this.enabled = env_1.Env.getBoolean(`${prefix}.enabled`, this.enabled);
this.login.enabled = env_1.Env.getBoolean(`${prefix}.login.enabled`, this.login.enabled);
this.bearer.enabled = env_1.Env.getBoolean(`${prefix}.bearer.enabled`, this.bearer.enabled);
this.google.enabled = env_1.Env.getBoolean(`${prefix}.google.enabled`, this.google.enabled);
this.google.clientId = env_1.Env.get(`${prefix}.google.clientId`, this.google.clientId);
this.google.clientSecret = env_1.Env.get(`${prefix}.google.clientSecret`, this.google.clientSecret);
this.github.enabled = env_1.Env.getBoolean(`${prefix}.github.enabled`, this.github.enabled);
this.github.clientId = env_1.Env.get(`${prefix}.github.clientId`, this.github.clientId);
this.github.clientSecret = env_1.Env.get(`${prefix}.github.clientSecret`, this.github.clientSecret);
this.facebook.enabled = env_1.Env.getBoolean(`${prefix}.facebook.enabled`, this.facebook.enabled);
this.facebook.clientId = env_1.Env.get(`${prefix}.facebook.clientId`, this.facebook.clientId);
this.facebook.clientSecret = env_1.Env.get(`${prefix}.facebook.clientSecret`, this.facebook.clientSecret);
this.register.init();
}

@@ -161,0 +166,0 @@ addStrategy(options, strategy) {

@@ -13,3 +13,3 @@ "use strict";

const typeorm_1 = require("typeorm");
const interfaces_1 = require("../interfaces");
const keys_1 = require("../keys");
const fulton_log_1 = require("../fulton-log");

@@ -28,3 +28,3 @@ const entity_decorators_helpers_1 = require("../entities/entity-decorators-helpers");

let connOptions = [];
app.options.databases.forEach((conn, name) => {
app.options.databases.forEach((name, conn) => {
lodash.set(conn, "name", name);

@@ -56,4 +56,4 @@ // extends entities

}
app.events.emit(interfaces_1.EventKeys.didInitDatabases, app);
app.events.emit(keys_1.EventKeys.AppDidInitDatabases, app);
});
};
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const inversify_1 = require("inversify");
const interfaces_1 = require("../interfaces");
const keys_1 = require("../keys");
const entities_1 = require("../entities");

@@ -9,7 +9,7 @@ module.exports = function (app) {

// for FultonApp
app.container.bind(interfaces_1.DiKeys.FultonApp).toConstantValue(app);
app.container.bind(keys_1.DiKeys.FultonApp).toConstantValue(app);
// for EntityService
app.container.bind(interfaces_1.DiKeys.EntityServiceFactory).toFactory(entityServiceFactory);
app.container.bind(keys_1.DiKeys.EntityServiceFactory).toFactory(entityServiceFactory);
// for EntityRunner
app.container.bind(interfaces_1.DiKeys.MongoEntityRunner).toDynamicValue((ctx) => {
app.container.bind(keys_1.DiKeys.MongoEntityRunner).toDynamicValue((ctx) => {
// lazy require

@@ -19,3 +19,3 @@ let runner = require("../entities/runner/mongo-entity-runner").MongoEntityRunner;

}).inSingletonScope();
app.events.emit(interfaces_1.EventKeys.didInitDiContainer, app);
app.events.emit(keys_1.EventKeys.AppDidInitDiContainer, app);
};

@@ -28,5 +28,5 @@ /**

let service = new entities_1.EntityService(entity);
service["app"] = ctx.container.get(interfaces_1.DiKeys.FultonApp);
service["app"] = ctx.container.get(keys_1.DiKeys.FultonApp);
return service;
};
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const fs = require("fs");
const interfaces_1 = require("../interfaces");
const entity_router_1 = require("../routers/entity-router");
const keys_1 = require("../keys");
const helper_1 = require("../helpers/helper");

@@ -17,3 +17,3 @@ const constants_1 = require("../constants");

}
app.events.emit(interfaces_1.EventKeys.didInitDocs, app);
app.events.emit(keys_1.EventKeys.AppDidInitDocs, app);
let docsMiddlewares = [];

@@ -20,0 +20,0 @@ let jsonMiddlewares = [];

@@ -5,4 +5,4 @@ "use strict";

const lodash = require("lodash");
const keys_1 = require("../keys");
const constants_1 = require("../constants");
const interfaces_1 = require("../interfaces");
const query_params_parser_1 = require("../middlewares/query-params-parser");

@@ -29,3 +29,3 @@ module.exports = function (app) {

}
app.events.emit(interfaces_1.EventKeys.didInitFormatter, app);
app.events.emit(keys_1.EventKeys.AppDidInitFormatter, app);
};

@@ -5,29 +5,2 @@ import "reflect-metadata";

export * from "./re-export";
export declare enum DiKeys {
EntityServiceFactory = "__EntityServiceFactory__",
FultonApp = "__FultonApp__",
MongoEntityRunner = "__MongoEntityRunner__",
}
export declare enum EventKeys {
didInit = "didInit",
didInitCors = "didInitCors",
didInitDatabases = "didInitDatabases",
didInitDiContainer = "didInitDiContainer",
didInitDocs = "didInitDocs",
didInitErrorHandler = "didInitErrorHandler",
didInitFormatter = "didInitFormatter",
didInitHttpLogging = "didInitHttpLogging",
didInitIdentity = "didInitIdentity",
didInitIndex = "didInitIndex",
didInitJsonApi = "didInitJsonApi",
didInitLogging = "didInitLogging",
didInitMiddlewares = "didInitMiddlewares",
didInitProviders = "didInitProviders",
didInitRepositories = "didInitRepositories",
didInitRouters = "didInitRouters",
didInitServer = "didInitServer",
didInitServices = "didInitServices",
didInitStaticFile = "didInitStaticFile",
onInitJsonApi = "onInitJsonApi",
}
export interface AbstractType<T = any> extends Function {

@@ -172,3 +145,55 @@ }

}
export interface ITemplateService {
geneate(contentOrFilePath: string, variables: any): string;
}
export interface INotificationService {
send(...messages: NotificationMessage[]): Promise<void>;
}
export interface NotificationMessage {
email?: EmailMessage;
sms?: any;
}
export interface IEmailService {
send(message: EmailMessage): Promise<void>;
}
export interface EmailMessage {
/**
* the sender, if null, use the default sender.
*/
from?: string;
/**
* the cc. if null, use the default cc.
*/
cc?: string;
/**
* the bcc. if null, use the default bcc.
*/
bcc?: string;
/**
* the to
*/
to: string | string[];
/**
* if subjectTemplate is not null, app will generate subject by template
*/
subject?: string;
/**
* the subject template, it can be text or file path
*/
subjectTemplate?: string;
/**
* if bodyTemplate is not null, app will generate body by template
*/
body?: string;
/**
* the body template, it can be text or file path
*/
bodyTemplate?: string;
/**
* the variables for template
*/
variables?: any;
attachments?: any[];
}
export declare type HttpMethod = "all" | "get" | "post" | "patch" | "delete" | "head" | "put";
export declare type AppMode = "api" | "web-view" | "mixed";

@@ -9,30 +9,1 @@ "use strict";

__export(require("./re-export"));
var DiKeys;
(function (DiKeys) {
DiKeys["EntityServiceFactory"] = "__EntityServiceFactory__";
DiKeys["FultonApp"] = "__FultonApp__";
DiKeys["MongoEntityRunner"] = "__MongoEntityRunner__";
})(DiKeys = exports.DiKeys || (exports.DiKeys = {}));
var EventKeys;
(function (EventKeys) {
EventKeys["didInit"] = "didInit";
EventKeys["didInitCors"] = "didInitCors";
EventKeys["didInitDatabases"] = "didInitDatabases";
EventKeys["didInitDiContainer"] = "didInitDiContainer";
EventKeys["didInitDocs"] = "didInitDocs";
EventKeys["didInitErrorHandler"] = "didInitErrorHandler";
EventKeys["didInitFormatter"] = "didInitFormatter";
EventKeys["didInitHttpLogging"] = "didInitHttpLogging";
EventKeys["didInitIdentity"] = "didInitIdentity";
EventKeys["didInitIndex"] = "didInitIndex";
EventKeys["didInitJsonApi"] = "didInitJsonApi";
EventKeys["didInitLogging"] = "didInitLogging";
EventKeys["didInitMiddlewares"] = "didInitMiddlewares";
EventKeys["didInitProviders"] = "didInitProviders";
EventKeys["didInitRepositories"] = "didInitRepositories";
EventKeys["didInitRouters"] = "didInitRouters";
EventKeys["didInitServer"] = "didInitServer";
EventKeys["didInitServices"] = "didInitServices";
EventKeys["didInitStaticFile"] = "didInitStaticFile";
EventKeys["onInitJsonApi"] = "onInitJsonApi";
})(EventKeys = exports.EventKeys || (exports.EventKeys = {}));
export * from "./interfaces";
export * from "./keys";
export * from "./fulton-app";
export * from "./fulton-app-options";
export * from "./fulton-log";
export * from "./app-launcher";
export * from "./options/fulton-app-options";
export * from "./helpers/index";

@@ -12,2 +13,1 @@ export * from "./common/index";

export * from "./routers/index";
export * from "./middlewares/output-cache";

@@ -7,6 +7,7 @@ "use strict";

__export(require("./interfaces"));
__export(require("./keys"));
__export(require("./fulton-app"));
__export(require("./fulton-app-options"));
__export(require("./fulton-log"));
__export(require("./app-launcher"));
__export(require("./options/fulton-app-options"));
__export(require("./helpers/index"));

@@ -18,3 +19,2 @@ __export(require("./common/index"));

__export(require("./routers/index"));
__export(require("./middlewares/output-cache"));
// don't import this file, like "./main" which cause circular module imports

@@ -5,7 +5,7 @@ "use strict";

const url = require("url");
const entity_router_1 = require("../routers/entity-router");
const keys_1 = require("../keys");
const helper_1 = require("../helpers/helper");
const jsonapi_converter_1 = require("../helpers/jsonapi-converter");
const interfaces_1 = require("../interfaces");
const entity_router_1 = require("../routers/entity-router");
const constants_1 = require("../constants");
const helper_1 = require("../helpers/helper");
module.exports = function (app) {

@@ -15,3 +15,3 @@ let converter;

// so add a hook.
app.events.once("didInitRouters", (app) => {
app.events.once(keys_1.EventKeys.AppDidInitRouters, (app) => {
converter = initConverter(app);

@@ -33,3 +33,2 @@ });

apply: (send, thisArg, args) => {
let useOrigin = true;
if (args && args.length == 1 && typeof args[0] == "object") {

@@ -65,3 +64,2 @@ if (args[0].data) {

args[0] = JSON.stringify(result);
useOrigin = false;
}

@@ -73,13 +71,5 @@ }

args[0] = JSON.stringify({ errors: [args[0].error] });
useOrigin = false;
}
}
if (useOrigin) {
// use original send
send.apply(thisArg, args);
}
else {
// go through the send flow again
res.send(...args);
}
send.apply(thisArg, args);
},

@@ -93,3 +83,3 @@ });

let converter = new jsonapi_converter_1.JsonApiConverter();
app.events.emit(interfaces_1.EventKeys.onInitJsonApi, app, converter);
app.events.emit(keys_1.EventKeys.OnInitJsonApi, app, converter);
app.entityMetadatas.forEach((metadata, type) => {

@@ -144,3 +134,3 @@ let relatedToMetadata = metadata.relatedToMetadata;

});
app.events.emit(interfaces_1.EventKeys.didInitJsonApi, app, converter);
app.events.emit(keys_1.EventKeys.AppDidInitJsonApi, app, converter);
return converter;

@@ -147,0 +137,0 @@ }

{
"name": "fulton-server",
"version": "0.0.19",
"version": "0.0.20",
"description": "Fulton is the best practical way to build web apis or websites we have done in our company. Basically, Fulton is integrated many popular libraries or frameworks seamlessly. By use Fulton, developers can build a completed web api or a websites quickly.",

@@ -15,4 +15,4 @@ "main": "./main.js",

"test:all": "npm run test && npm run test:it",
"test:debug": "ts-node --inspect-brk=9229 --typeCheck=true ./spec/test.ts",
"test:debug:it": "ts-node --inspect-brk=9229 --typeCheck=true ./spec/test.ts --it",
"test:debug": "node --inspect-brk=9229 -r ts-node/register ./spec/test.ts",
"test:debug:it": "node --inspect-brk=9229 -r ts-node/register ./spec/test.ts --it",
"coverage": "nyc npm test"

@@ -37,2 +37,3 @@ },

"@types/chalk": "^2.2.0",
"@types/compression": "0.0.36",
"@types/cors": "^2.8.3",

@@ -47,2 +48,3 @@ "@types/debug": "0.0.30",

"@types/mongodb": "^2.2.20",
"@types/nodemailer": "^4.6.0",
"@types/passport-http-bearer": "^1.0.31",

@@ -55,3 +57,5 @@ "@types/passport-local": "^1.0.32",

"@types/winston": "^2.3.7",
"angular-template": "^2.4.0",
"debug": "^3.1.0",
"dotenv": "^5.0.1",
"google-auth-library": "^1.1.0",

@@ -61,2 +65,3 @@ "jasmine": "^2.9.0",

"mongodb": "^2.2.35",
"nodemailer": "^4.6.4",
"nyc": "^11.4.1",

@@ -69,4 +74,4 @@ "passport-facebook": "^2.1.1",

"swagger-ui-express": "^2.0.15",
"ts-node": "^3.3.0",
"typescript": "^2.7.2"
"ts-node": "^6.0.0",
"typescript": "^2.8.3"
},

@@ -78,5 +83,7 @@ "dependencies": {

"class-validator": "^0.8.1",
"compression": "^1.7.2",
"cors": "^2.8.4",
"escape-string-regexp": "^1.0.5",
"express": "^4.16.2",
"hoek": "^4.2.1",
"inversify": "^4.9.0",

@@ -83,0 +90,0 @@ "jws": "^3.1.4",

@@ -1,4 +0,4 @@

import { FullEntityRouterMetadata } from "./route-decorators-helpers";
import { IEntityService, NextFunction, OperationOneResult, OperationManyResult, OperationResult, Request, Response } from "../interfaces";
import { Router } from "./router";
import { IEntityService, NextFunction, OperationManyResult, OperationOneResult, OperationResult, Request, Response } from '../interfaces';
import { FullEntityRouterMetadata } from './route-decorators-helpers';
import { Router } from './router';
export declare abstract class EntityRouter<TEntity> extends Router {

@@ -5,0 +5,0 @@ protected entityService: IEntityService<TEntity>;

@@ -12,5 +12,6 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
const keys_1 = require("../keys");
const interfaces_1 = require("../interfaces");
const route_decorators_helpers_1 = require("./route-decorators-helpers");
const route_decorators_1 = require("./route-decorators");
const interfaces_1 = require("../interfaces");
const router_1 = require("./router");

@@ -28,3 +29,3 @@ let EntityRouter = class EntityRouter extends router_1.Router {

// use default implementation
let factory = this.app.container.get(interfaces_1.DiKeys.EntityServiceFactory);
let factory = this.app.container.get(keys_1.DiKeys.EntityServiceFactory);
if (factory instanceof Function) {

@@ -47,3 +48,3 @@ // factory

if (req.queryParams.pagination.size == null)
req.queryParams.pagination.size = this.app.options.settings.paginationSize;
req.queryParams.pagination.size = this.app.options.miscellaneous.paginationSize;
}

@@ -53,3 +54,3 @@ else {

index: 0,
size: this.app.options.settings.paginationSize
size: this.app.options.miscellaneous.paginationSize
};

@@ -56,0 +57,0 @@ }

@@ -14,5 +14,5 @@ "use strict";

const lodash = require("lodash");
const keys_1 = require("../keys");
const route_decorators_helpers_1 = require("./route-decorators-helpers");
const interfaces_1 = require("../interfaces");
const route_decorators_helpers_1 = require("./route-decorators-helpers");
const interfaces_2 = require("../interfaces");
const express_1 = require("express");

@@ -77,7 +77,7 @@ /**

__decorate([
interfaces_2.inject(interfaces_1.DiKeys.FultonApp),
interfaces_1.inject(keys_1.DiKeys.FultonApp),
__metadata("design:type", Object)
], Router.prototype, "app", void 0);
Router = Router_1 = __decorate([
interfaces_2.injectable(),
interfaces_1.injectable(),
__metadata("design:paramtypes", [])

@@ -84,0 +84,0 @@ ], Router);

@@ -1,2 +0,2 @@

import { IFultonApp } from "../fulton-app";
import { IFultonApp } from '../fulton-app';
/**

@@ -3,0 +3,0 @@ * Fulton Service

@@ -13,2 +13,3 @@ "use strict";

const interfaces_1 = require("../interfaces");
const keys_1 = require("../keys");
/**

@@ -20,3 +21,3 @@ * Fulton Service

__decorate([
interfaces_1.inject(interfaces_1.DiKeys.FultonApp),
interfaces_1.inject(keys_1.DiKeys.FultonApp),
__metadata("design:type", Object)

@@ -23,0 +24,0 @@ ], Service.prototype, "app", void 0);

@@ -9,4 +9,4 @@ "use strict";

this.app = app;
fulton_log_1.FultonLog.level = "warn";
this.app.options.settings.zoneEnabled = false;
fulton_log_1.FultonLog.level = "error";
this.app.options.miscellaneous.zoneEnabled = false;
this.app.options.server.httpPort = 5000;

@@ -13,0 +13,0 @@ this.app.options.logging.httpLoggerEnabled = false;

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc