Skip to content

Commit

Permalink
feat(session): add actions, entities, reducers and services for sessi…
Browse files Browse the repository at this point in the history
…on module
  • Loading branch information
tenretC committed Apr 13, 2018
1 parent 38c48fe commit 2dad18c
Show file tree
Hide file tree
Showing 33 changed files with 1,752 additions and 178 deletions.
3 changes: 3 additions & 0 deletions packages/stark-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
"npm": ">=5.3.0"
},
"dependencies": {
"@ng-idle/core": "2.0.0-beta.15",
"@ng-idle/keepalive": "2.0.0-beta.15",
"@ngx-translate/core": "9.1.1",
"@ngrx/store": "5.2.0",
"@types/core-js": "0.9.46",
"@types/jasmine": "2.8.6",
Expand Down
4 changes: 4 additions & 0 deletions packages/stark-core/src/common/routes/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

// TODO only exports the public api stuffs
export * from "./routes";

93 changes: 93 additions & 0 deletions packages/stark-core/src/common/routes/routes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
"use strict";

import { Location } from "@angular/common";
import { StarkRoutingService, starkRoutingServiceName, StarkStateConfigWithParams } from "../../routing/services/index";
import { StatesModule } from "@uirouter/angular";

export const starkAppInitStateName: string = "starkAppInit";
export const starkAppExitStateName: string = "starkAppExit";

export const starkLoginStateName: string = "starkAppInit.starkLogin";
export const starkLoginStateUrl: string = "/starkLogin";

export const starkPreloadingStateName: string = "starkAppInit.starkPreloading";
export const starkPreloadingStateUrl: string = "/starkPreloading";

export const starkSessionExpiredStateName: string = "starkAppExit.starkSessionExpired";
export const starkSessionExpiredStateUrl: string = "/starkSessionExpired";

export const starkSessionLogoutStateName: string = "starkAppExit.starkSessionLogout";
export const starkSessionLogoutStateUrl: string = "/starkSessionLogout";

// FIXME Fix states declaration
export const starkCoreRouteConfig: StatesModule = <any>{
states: [
{
name: starkAppInitStateName, // parent state for any initialization state (used to show/hide the main app component)
abstract: true,
resolve: {
targetRoute: ["$location", starkRoutingServiceName, ($location: Location, routingService: StarkRoutingService) => {
// get the path of the current URL in the browser's navigation bar
const targetUrlPath: string = $location.path();
const targetRoute: StarkStateConfigWithParams | undefined = routingService.getStateConfigByUrlPath(targetUrlPath);

// skip any init/exit state
const initOrExitStateRegex: RegExp = new RegExp("(" + starkAppInitStateName + "|" + starkAppExitStateName + ")");

if (targetRoute) {
if ((<Function>targetRoute.state.$$state)().parent) {
if (!(<Function>targetRoute.state.$$state)().parent.name.match(initOrExitStateRegex)) {
return targetRoute;
} else {
return undefined;
}
} else {
return targetRoute;
}
} else {
return undefined;
}
}],
targetState: ["targetRoute", (targetRoute: StarkStateConfigWithParams) => {
return (typeof targetRoute !== "undefined") ? targetRoute.state.name : undefined;
}],
targetStateParams: ["targetRoute", (targetRoute: StarkStateConfigWithParams) => {
return (typeof targetRoute !== "undefined") ? targetRoute.paramValues : undefined;
}]
}
},
{
name: starkAppExitStateName, // parent state for any exit state (used to show/hide the main app component)
abstract: true
},
{
name: starkLoginStateName, // the parent is defined in the state's name (contains a dot)
url: starkLoginStateUrl,
views: {
// TODO: how to use a constant instead of a hard-coded string? (without loading the component file to avoid circular dependencies!)
"initOrExit@": "starkLoginPage"
}
},
{
name: starkPreloadingStateName, // the parent is defined in the state's name (contains a dot)
url: starkPreloadingStateUrl,
views: {
"initOrExit@": "starkPreloadingPage"
}
},
{
name: starkSessionExpiredStateName, // the parent is defined in the state's name (contains a dot)
url: starkSessionExpiredStateUrl,
views: {
"initOrExit@": "starkSessionExpiredPage"
}
},
{
name: starkSessionLogoutStateName, // the parent is defined in the state's name (contains a dot)
url: starkSessionLogoutStateUrl,
views: {
"initOrExit@": "starkSessionLogoutPage"
}
}
]
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
* Interface defining the shape of the application state of Stark Core (i.e., what's stored in Redux by Stark)
*/
import { StarkLogging } from "../../logging/entities/index";
// import {StarkSession} from "../../session/entities";
import { StarkSession } from "../../session/entities";
// import {StarkSettings} from "../../settings/entities";

export interface StarkCoreApplicationState
extends StarkLoggingApplicationState /*, StarkSessionApplicationState, StarkSettingsApplicationState*/ {
extends StarkLoggingApplicationState , StarkSessionApplicationState/*, StarkSettingsApplicationState*/ {
// starkApplicationMetadata: StarkApplicationMetadata;
// starkLogging: StarkLogging;
// starkSession: StarkSession;
Expand All @@ -17,9 +17,9 @@ export interface StarkLoggingApplicationState {
starkLogging: StarkLogging;
}

// export interface StarkSessionApplicationState {
// starkSession: StarkSession;
// }
export interface StarkSessionApplicationState {
starkSession: StarkSession;
}
// export interface StarkSettingsApplicationState {
// starkSettings: StarkSettings;
// }
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,23 @@ export interface StarkApplicationConfig {
*/
loggingFlushResourceName?: string;

/**
* Option to disable the logging flush if it not needed for the application.
* Default: false
*/
loggingFlushDisabled?: boolean;

/**
* Enable router logging
*/
routerLoggingEnabled: boolean;

/**
* Enable router visualizer. Only in DEV (the router visualizer is not available in PROD)
* Default: false
*/
routerVisualizerEnabled: boolean;

/**
* Timeout period before the session is ended if no user interaction occurs
*/
Expand All @@ -86,6 +98,12 @@ export interface StarkApplicationConfig {
*/
keepAliveUrl?: string;

/**
* Option to disable the keepAlive if it not needed for the application.
* Default: false
*/
keepAliveDisabled?: boolean;

/**
* Url to be navigated to logout the user
*/
Expand All @@ -108,18 +126,6 @@ export interface StarkApplicationConfig {
*/
publicApp: boolean;

/**
* Option to disable the logging flush if it not needed for the application.
* default: false
*/
loggingFlushDisabled?: boolean;

/**
* Option to disable the keepAlive if it not needed for the application.
* default: false
*/
keepAliveDisabled?: boolean;

/**
* Backends that the application will interact to.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
"use strict";

import { IsBoolean, IsDefined, IsNotEmpty, IsNumber, IsString, IsUrl, Matches, Min, ValidateIf, validateSync } from "class-validator";
import { IsBoolean, IsDefined, IsNotEmpty, IsPositive, IsString, IsUrl, Matches, Min, ValidateIf, validateSync } from "class-validator";
import { autoserialize, autoserializeAs } from "cerialize";
import { StarkApplicationConfig } from "./app-config.entity.intf";
import { StarkBackend, StarkBackendImpl } from "../../../http/entities/backend/index";
import { stringMap } from "../../../serialization/index";
import { StarkValidationErrorsUtil } from "../../../util/index";
import { StarkValidationMethodsUtil } from "../../../util/validation-methods.util";
// FIXME Implement the following decorators as before
// import {StarkMapIsValid, StarkMapNotEmpty} from "../../../validation/decorators";

export class StarkApplicationConfigImpl implements StarkApplicationConfig {
Expand Down Expand Up @@ -41,8 +42,8 @@ export class StarkApplicationConfigImpl implements StarkApplicationConfig {
public debugLoggingEnabled: boolean;

@ValidateIf(StarkApplicationConfigImpl.validateIfLoggingFlushEnabled)
@IsNumber()
@Min(1)
@IsPositive()
@Min(2)
@autoserialize
public loggingFlushPersistSize?: number;

Expand All @@ -58,28 +59,37 @@ export class StarkApplicationConfigImpl implements StarkApplicationConfig {
@autoserialize
public loggingFlushResourceName?: string;

@ValidateIf(StarkValidationMethodsUtil.validateIfDefined)
@IsBoolean()
@autoserialize
public loggingFlushDisabled?: boolean;

@IsDefined()
@IsBoolean()
@autoserialize
public routerLoggingEnabled: boolean;

@IsBoolean()
@autoserialize
public routerVisualizerEnabled: boolean;

@IsNotEmpty()
@IsString()
@Matches(/^[a-z]{2}$/)
@autoserialize
public defaultLanguage: string;

@IsDefined()
@IsNumber()
@IsPositive()
@autoserialize
public sessionTimeout: number;

@IsNumber()
@IsPositive()
@autoserialize
public sessionTimeoutWarningPeriod: number;

@ValidateIf(StarkApplicationConfigImpl.validateIfKeepAliveEnabled)
@IsNumber()
@IsPositive()
@autoserialize
public keepAliveInterval?: number;

Expand All @@ -88,6 +98,11 @@ export class StarkApplicationConfigImpl implements StarkApplicationConfig {
@autoserialize
public keepAliveUrl?: string;

@ValidateIf(StarkValidationMethodsUtil.validateIfDefined)
@IsBoolean()
@autoserialize
public keepAliveDisabled?: boolean;

@IsDefined()
@IsUrl()
@autoserialize
Expand All @@ -103,15 +118,6 @@ export class StarkApplicationConfigImpl implements StarkApplicationConfig {
@autoserialize
public publicApp: boolean;

@ValidateIf(StarkValidationMethodsUtil.validateIfDefined)
@IsBoolean()
@autoserialize
public loggingFlushDisabled?: boolean;

@ValidateIf(StarkValidationMethodsUtil.validateIfDefined)
@IsBoolean()
@autoserialize
public keepAliveDisabled?: boolean;
//FIXME Import StarkMapIsValid & StarkMapNotEmpty from validation/decorators
// @StarkMapNotEmpty()
// @StarkMapIsValid()
Expand All @@ -127,9 +133,13 @@ export class StarkApplicationConfigImpl implements StarkApplicationConfig {
this.loggingFlushPersistSize = 15;
// }

this.loggingFlushDisabled = false;
this.loggingFlushResourceName = "logging";
this.sessionTimeout = 900; // default timeout of the F5
this.sessionTimeoutWarningPeriod = 15;
this.keepAliveDisabled = false;
this.keepAliveInterval = 15;
this.routerVisualizerEnabled = false;
}

public addBackend(backend: StarkBackend): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
StarkSingleItemResponseWrapper
} from "../entities/index";
import { StarkHttpService } from "../services/http.service.intf";
import { StarkLoggingService } from "../../logging";
import { StarkLoggingService, MockStarkLoggingService } from "../../logging/index";
import { UnitTestingUtils } from "../../test/unit-testing/index";
import { StarkHttpRequestBuilderImpl } from "../builder/index";
import { StarkHttpSerializer, StarkHttpSerializerImpl } from "../serializer/index";
Expand All @@ -32,7 +32,7 @@ describe("Repository: AbstractStarkHttpRepository", () => {

beforeEach(() => {
mockStarkHttpService = UnitTestingUtils.getMockedHttpService();
mockLogger = UnitTestingUtils.getMockedLoggingService();
mockLogger = new MockStarkLoggingService();
mockBackend = createSpyObj("backend", ["url"]);
mockResourcePath = "mock";
mockResource = new MockResource(resourceUuid);
Expand Down
4 changes: 2 additions & 2 deletions packages/stark-core/src/http/services/http.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import {

import { StarkHttpHeaders, StarkSortOrder } from "../constants/index";
import { StarkHttpStatusCodes } from "../enumerators/index";
import { StarkLoggingService } from "../../logging/index";
import { StarkLoggingService, MockStarkLoggingService } from "../../logging/index";
import { UnitTestingUtils } from "../../test/unit-testing/index";
import { StarkHttpSerializer, StarkHttpSerializerImpl } from "../serializer/index";
import { StarkSessionService } from "../../session/index";
Expand Down Expand Up @@ -150,7 +150,7 @@ describe("Service: StarkHttpService", () => {
metadata: mockResourceMetadata
};
// Make sure that a correlation identifier is defined correctly on the logger
loggerMock = UnitTestingUtils.getMockedLoggingService(mockCorrelationId);
loggerMock = new MockStarkLoggingService(mockCorrelationId);
mockSessionService = UnitTestingUtils.getMockedSessionService();
httpMock = createSpyObj("HttpClient", ["get", "put", "post", "delete"]);

Expand Down
3 changes: 2 additions & 1 deletion packages/stark-core/src/logging/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export * from "./actions/index";
export * from "./entities/index";
export * from "./reducers/index";
export * from "./services/index";
export * from "./logging.module";
export * from "./testing/index";
export * from "./logging.module";
1 change: 1 addition & 0 deletions packages/stark-core/src/logging/testing/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./logging.mock";
3 changes: 3 additions & 0 deletions packages/stark-core/src/session/actions/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"use strict";

export * from "./session.actions";
Loading

0 comments on commit 2dad18c

Please sign in to comment.