Socket
Socket
Sign inDemoInstall

fulton-server

Package Overview
Dependencies
346
Maintainers
1
Versions
62
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.24 to 0.0.25-0

97

fulton-app.d.ts

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

import * as https from 'https';
import { AppMode, DiContainer, Type, TypeIdentifier, NotificationMessage } from './interfaces';
import { Provider } from "./helpers/type-helpers";
import { AppMode, DiContainer, NotificationMessage, Type, TypeIdentifier } from './interfaces';
import { Provider } from './helpers/type-helpers';
import { Connection, Repository } from 'typeorm';
import { IUser, IUserService } from "./identity/interfaces";
import { EntityMetadata } from 'typeorm/metadata/EntityMetadata';
import { EventEmitter } from 'events';
import { Express } from "express";
import { FultonAppOptions } from "./options/fulton-app-options";
import { Router } from "./routers/router";
import { Express } from 'express';
import { FultonAppOptions } from './options/fulton-app-options';
import { IUser, IUserService } from './identity/interfaces';
import { Router } from './routers/router';
export interface IFultonApp {
readonly isInitialized: boolean;
readonly appName: string;
express: Express;
container: DiContainer;
options: FultonAppOptions;
events: EventEmitter;
userService: IUserService<IUser>;
httpServer: http.Server;
httpsServer: https.Server;
connections: Connection[];
entityMetadatas: Map<Type, EntityMetadata>;
routers: Router[];
getLocalData(key: string): any;
setLocalData(key: string, value: any): void;
init(): Promise<void>;
start(): Promise<any>;
stop(): Promise<any>;
/**
* A shortcut to get typeorm repository
*/
getRepository<T>(entity: Type, connectionName?: string): Repository<T>;
sendNotifications(...messages: NotificationMessage[]): Promise<void>;
}
/**
* The app of Fulton Server, it is the main class of Fulton Server
*
* `onInit` is the required function when extends from FultonApp
*/
export declare abstract class FultonApp implements IFultonApp {
readonly mode: AppMode;
private assetFolder;
/**
* app name, use in output, parser. default is class name.
*/
appName: string;
readonly appName: string;
/**

@@ -64,7 +34,7 @@ * the instance of Express, created during init().

/**
* the EventEmitter, every init{name} will emit didInit{name} event
* the EventEmitter, see EventKeys for all the events
*
* ## example
* ```
* app.events.on("didInitRouters", (app:FultonApp)=>{});
* app.events.on(EventKeys.AppDidInit, (app:FultonApp)=>{});
* ```

@@ -88,3 +58,3 @@ */

*/
connections: Connection[];
dbConnections: Connection[];
/**

@@ -98,7 +68,6 @@ * the metadatas of the entities, which added after initDatabases

routers: Router[];
isInitialized: boolean;
/**
* @param mode There are some different default values for api and web-view.
* the base url, it is generated by every request,
*/
constructor(mode?: AppMode);
baseUrl: string;
/**

@@ -122,7 +91,47 @@ * get data from res.locals[key], and use Zone to manage context

/**
* stop http server or https server
* stop http server or https server and dbConnections
*/
stop(): Promise<any>;
/**
* A shortcut to get typeorm repository
*/
getRepository<T>(entity: Type, connectionName?: string): Repository<T>;
/**
* call NotificationService to send messages, message can be email, sms or push-notification
* @param messages
*/
sendNotifications(...messages: NotificationMessage[]): Promise<void>;
}
/**
* The app of Fulton Server, it is the main class of Fulton Server
*
* `onInit` is the required function when extends from FultonApp
*/
export declare abstract class FultonApp implements IFultonApp {
readonly mode: AppMode;
private assetFolder;
appName: string;
express: Express;
container: DiContainer;
options: FultonAppOptions;
events: EventEmitter;
userService: IUserService<IUser>;
httpServer: http.Server;
httpsServer: https.Server;
dbConnections: Connection[];
entityMetadatas: Map<Type, EntityMetadata>;
routers: Router[];
baseUrl: string;
isInitialized: boolean;
/**
* @param mode There are some different default values for api and web-view.
*/
constructor(mode?: AppMode);
getLocalData(key: string): any;
setLocalData(key: string, value: any): void;
init(): Promise<void>;
start(): Promise<any>;
stop(): Promise<any>;
getRepository<T>(entity: Type, connectionName?: string): Repository<T>;
sendNotifications(...messages: NotificationMessage[]): Promise<void>;
protected initServer(): void | Promise<void>;

@@ -129,0 +138,0 @@ protected initDiContainer(): void | Promise<void>;

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

Object.defineProperty(exports, "__esModule", { value: true });
const compression = require("compression");
const cors = require("cors");
const express = require("express");
const compression = require("compression");
const fs = require("fs");
const http = require("http");

@@ -19,12 +20,12 @@ const https = require("https");

const path = require("path");
const fs = require("fs");
const winston = require("winston");
const typeorm_1 = require("typeorm");
const http_logger_1 = require("./middlewares/http-logger");
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("./options/fulton-app-options");
const debug_1 = require("./helpers/debug");
const fulton_log_1 = require("./fulton-log");
const http_logger_1 = require("./middlewares/http-logger");
const debug_1 = require("./helpers/debug");
const helper_1 = require("./helpers/helper");
/**

@@ -44,2 +45,3 @@ * The app of Fulton Server, it is the main class of Fulton Server

this.serve = (req, res) => {
this.baseUrl = helper_1.Helper.baseUrlRaw(req);
if (this.options.miscellaneous.zoneEnabled) {

@@ -67,8 +69,5 @@ Zone.current.fork({

this.entityMetadatas = new Map();
this.connections = [];
this.dbConnections = [];
this.routers = [];
}
/**
* get data from res.locals[key], and use Zone to manage context
*/
getLocalData(key) {

@@ -82,5 +81,2 @@ if (this.options.miscellaneous.zoneEnabled) {

}
/**
* set data from res.locals[key], and use Zone to manage context
*/
setLocalData(key, value) {

@@ -94,6 +90,2 @@ if (this.options.miscellaneous.zoneEnabled) {

}
/**
* initialize FultonApp. It will be called on start(), if the app isn't initialized;
* it can be run many times, every times call this will reset all the related objects
*/
init() {

@@ -134,5 +126,2 @@ return __awaiter(this, void 0, void 0, function* () {

}
/**
* start http server or https server. if it isn't initialized, it will call init(), too.
*/
start() {

@@ -206,9 +195,6 @@ if (this.httpServer || this.httpsServer) {

}
/**
* stop http server or https server
*/
stop() {
var tasks = [];
if (this.connections) {
tasks.push(...this.connections.map((conn) => conn.close()));
if (this.dbConnections) {
tasks.push(...this.dbConnections.map((conn) => conn.close()));
}

@@ -215,0 +201,0 @@ if (this.httpServer) {

@@ -0,1 +1,3 @@

/// <reference types="node" />
import * as http from 'http';
import { Request } from '../interfaces';

@@ -10,4 +12,6 @@ export declare let Helper: {

escapedRegexp(input: string, flags?: string): RegExp;
baseUrl(req: Request): string;
baseUrlRaw(req: http.IncomingMessage): string;
urlResolve(req: Request, ...pathes: string[]): string;
urlJoin: (...args: string[]) => string;
};
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const escapeStringRegexp = require("escape-string-regexp");
const tls = require("tls");
let urlJoin = require('url-join');

@@ -54,11 +55,22 @@ const booleanReg = /^((true)|(false))$/i;

},
urlResolve(req, ...pathes) {
baseUrl(req) {
// x-forwarded-proto is from proxy like AWS load balancer
let protocol = req.header("x-forwarded-proto") || req.protocol;
let domain = `${protocol}://${req.get("host")}`;
return `${protocol}://${req.get("host")}`;
},
baseUrlRaw(req) {
// x-forwarded-proto is from proxy like AWS load balancer
let protocol = req.headers["x-forwarded-proto"];
if (!protocol) {
protocol = (req.connection instanceof tls.TLSSocket) ? "https" : "http";
}
return `${protocol}://${req.headers["host"]}`;
},
urlResolve(req, ...pathes) {
let baseUrl = req.fultonApp.baseUrl;
if (pathes == null || pathes.length == 0) {
return domain;
return baseUrl;
}
else {
return urlJoin(domain, ...pathes);
return urlJoin(baseUrl, ...pathes);
}

@@ -65,0 +77,0 @@ },

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

req.userService
.forgotPassword(username || email, helper_1.Helper.urlResolve(req, options.path))
.forgotPassword(username || email)
.then((result) => {

@@ -242,0 +242,0 @@ res.send({

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

import { AccessToken, IFultonUser, IOauthProfile, IUserService, RegisterModel, ForgotPasswordModel } from '../interfaces';
import { AccessToken, ForgotPasswordModel, IFultonUser, IOauthProfile, IUserService, RegisterModel } from '../interfaces';
import { FultonUser } from './fulton-user';

@@ -15,3 +15,3 @@ import { IFultonApp } from '../../fulton-app';

issueAccessToken(user: IFultonUser): Promise<AccessToken>;
forgotPassword(usernameOrEmail: string, baseUrl: string): Promise<ForgotPasswordModel>;
forgotPassword(usernameOrEmail: string): Promise<ForgotPasswordModel>;
resetPassword(token: string, code: string, password: string): Promise<void>;

@@ -18,0 +18,0 @@ verifyResetPassword(token: string, code: string): Promise<void>;

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

const typeorm_1 = require("typeorm");
const helper_1 = require("../../helpers/helper");
const interfaces_1 = require("../../interfaces");

@@ -351,3 +352,3 @@ const bson_1 = require("bson");

}
forgotPassword(usernameOrEmail, baseUrl) {
forgotPassword(usernameOrEmail) {
return __awaiter(this, void 0, void 0, function* () {

@@ -362,6 +363,8 @@ let identity = yield this.runner.findIdentityByLocal(usernameOrEmail);

this.app.events.emit(keys_1.EventKeys.UserForgotPassword, identity);
var url = helper_1.Helper.urlJoin(this.app.baseUrl, this.options.forgotPassword.path);
this.sendForgotPasswordNotification({
username: user.username,
email: identity.email,
url: `${baseUrl}?token=${token}&code=${code}`,
url: `${url}?token=${token}&code=${code}`,
token: token,
code: code

@@ -368,0 +371,0 @@ });

@@ -43,3 +43,3 @@ /// <reference types="passport" />

issueAccessToken(user: T): Promise<AccessToken>;
forgotPassword(usernameOrEmail: string, baseUrl: string): Promise<ForgotPasswordModel>;
forgotPassword(usernameOrEmail: string): Promise<ForgotPasswordModel>;
resetPassword(token: string, code: string, password: string): Promise<void>;

@@ -90,11 +90,12 @@ verifyResetPassword(token: string, code: string): Promise<void>;

}
export interface WelcomeNotificationModel {
export interface NotificationModel {
username: string;
email: string;
}
export interface ForgotPasswordNotificationModel {
username: string;
email: string;
export interface WelcomeNotificationModel extends NotificationModel {
}
export interface ForgotPasswordNotificationModel extends NotificationModel {
url: string;
token: string;
code: string;
}

@@ -12,3 +12,3 @@ import { BaseOptions } from '../../options/options';

* 2.
* ALL /auth/forgot-password?token=token&code=code, for just verfiy the token is valid or not
* ALL /auth/forgot-password?token=token&code=code, for just verify the token is valid or not
*

@@ -15,0 +15,0 @@ * 3.

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

* 2.
* ALL /auth/forgot-password?token=token&code=code, for just verfiy the token is valid or not
* ALL /auth/forgot-password?token=token&code=code, for just verify the token is valid or not
*

@@ -18,0 +18,0 @@ * 3.

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

});
app.connections = yield typeorm_1.createConnections(connOptions).catch((error) => {
app.dbConnections = yield typeorm_1.createConnections(connOptions).catch((error) => {
fulton_log_1.FultonLog.error("initDatabases fails", error);
throw error;
});
for (const conn of app.connections) {
for (const conn of app.dbConnections) {
for (const metadata of conn.entityMetadatas) {

@@ -48,0 +48,0 @@ let type = metadata.target;

{
"name": "fulton-server",
"version": "0.0.24",
"version": "0.0.25-0",
"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.",

@@ -5,0 +5,0 @@ "main": "./main.js",

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